Simple Ping Pong (led mapping) +PixelPusher

>

This is a simple example using pixelpusher’s library, processing and APA102 strips.

float lineX = 0;
float speed = 1;
float noiseC = random(10000);
float noiseCC = 0.01;
float addNoise = 0;
boolean juego = false;
float parti1 = 0;

import com.heroicrobot.dropbit.registry.*;
import com.heroicrobot.dropbit.devices.pixelpusher.Pixel;
import com.heroicrobot.dropbit.devices.pixelpusher.Strip;
import com.heroicrobot.dropbit.devices.pixelpusher.PixelPusher;
import com.heroicrobot.dropbit.devices.pixelpusher.PusherCommand;

import java.util.*;
DeviceRegistry registry;

void spamCommand(PixelPusher p, PusherCommand pc) {
for (int i=0; i<3; i++) {
p.sendCommand(pc);
}
}

class TestObserver implements Observer {
public boolean hasStrips = false;
public void update(Observable registry, Object updatedDevice) {
println(“Registry changed!”);
if (updatedDevice != null) {
println(“Device change: ” + updatedDevice);
}
this.hasStrips = true;
}
}

TestObserver testObserver;
int c = 0;

void setup() {
size(10, 150);
registry = new DeviceRegistry();
testObserver = new TestObserver();
registry.addObserver(testObserver);
colorMode(HSB, 100);
frameRate(30);
start();
prepareExitHandler();
}

void mousePressed() {
List pushers = registry.getPushers();
println(mouseY);
for (PixelPusher p : pushers) {
PusherCommand pc = new PusherCommand(PusherCommand.GLOBALBRIGHTNESS_SET, (short)((65536.0 * mouseY) / height));
spamCommand(p, pc);
}
}

void draw() {
int x=5;
int y=0;

if (testObserver.hasStrips) {

registry.startPushing();
registry.setExtraDelay(0);
registry.setAutoThrottle(true);
registry.setAntiLog(true);
List strips = registry.getStrips();

int numStrips = strips.size();
//println(“Strips total = “+numStrips);
if (numStrips == 0)
return;

if (juego == false) {
circles();
}
fill(12, 1, 1, 10);
rect(0, 0, width, height);
fill((noise(noiseC + addNoise)*100), 100, 100, 255);
noStroke();
rect(0, lineX, 10, 4);
addNoise += noiseCC;
///linea limite
fill(33, 80, 80, 10);
noStroke();
rect(0, height – 22, 12, 10);
if (juego) {
lineX+=speed;
if (lineX <= -2) { speed = speed*-1; } } if (lineX > height) {
juego = false;
lineX = 0;
noiseCC= 0.01;
speed = 1;
parti1 = 0;
}

for (Strip strip : strips) {
int yscale = 1;
for (int stripy = 0; stripy < 150; stripy++) { y = stripy*yscale; color c = get(x, y); strip.setPixel(c, y); } } } }   void keyPressed() { juego = true; if (key == ‘a’ || key == ‘A’) { if (lineX >= height – 25 && lineX < height -10) {
speed += 0.5;
speed = speed*-1;
noiseCC += 0.02;
}
fill(33, 97, 99, 255);
noStroke();
rect(0, height – 22, 12, 10);
}
}

void start() {
lineX = 0;
}

void circles() {
ellipseMode(CENTER);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.2, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/0.9, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.3, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.4, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.5, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.6, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.26, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.7, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.33, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.11, 20, 20);
fill(random(100), 100, 100, 200);
ellipse(0, height + 10 – parti1/1.56, 20, 20);
parti1 += 7;
}

private void prepareExitHandler () {

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

public void run () {

System.out.println(“Shutdown hook running”);
{
List strips = registry.getStrips();
for (Strip strip : strips) {
for (int i=0; i strip.setPixel(#000000, i);
}
}
for (int i=0; i<100000; i++)
Thread.yield();
}
}
));
}

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s