Änderungen

Aus Hackerspace Ffm
Wechseln zu: Navigation, Suche

Rundbunt Mini Emulator

3.389 Byte hinzugefügt, 20:23, 6. Okt. 2015
Die Seite wurde neu angelegt: „== Emulator Programm == [[Datei:Rundbunt mini Emulator screenshot 1.PNG|thumb]] * Programm für Processing 2.x (getestet unter Windows) * Das eindimensionale Arra…“
== Emulator Programm ==
[[Datei:Rundbunt mini Emulator screenshot 1.PNG|thumb]]
* Programm für Processing 2.x (getestet unter Windows)
* Das eindimensionale Array ''hsvbuf1[]'' wird durch die Funktion ''render_lamp()'' auf dem Bildschirm gerendert.
* die Potis für ''para[1]'' und '''para[2]'' können am unteren Bildschirm-Rand mit der Maus gesteuert werden.



== Limits ==
Processing unterscheidet sich in einigen Punkten von der FastLED Bibliothek in der Arduino IDE:

* Der Hue Wert für Farben bleibt bei Werten > 255 "stehen", geht also nicht zirkulär wieder bei 0 los.
* Einige Datentypen sind unbekannt, wie z.B. ''uint8_t''.


== Quellcode mit Beispiel-Muster ==
<pre>
CHSV[] hsvbuf1 = new CHSV[64];

int[] para = new int[3];


class CHSV {
float h, s, v;

CHSV(float ih, float is, float iv) {
h = ih;
s = is;
v = iv;
}

void set_HSV(float ih, float is, float iv) {
h = ih;
s = is;
v = iv;
}
}

void setup() {
size(500, 500);
background(32);

colorMode(HSB, 255);


for (int i = 0; i < 64; i ++) {
hsvbuf1[i] = new CHSV(i * 4, 255, 255);
}

for (int i = 0; i < 3; i ++) {
para[i] = 512;
}
}

void draw() {
{
// ==============================
// ==== rotating color dots =====
// ==============================

float mx, my;

mx = 3.5 + 3.5 * sin(millis() / 1200.0);
my = 3.5 + 3.5 * sin(millis() / 1321.0);

float s,v,cx,cy,t,t2;
int para1 = 0, para2 = 0;

float round = (4 * atan(1) * 2) / 8; // 2 * PI / 8

if(abs(para1 - para[1]) > 4) para1 = para[1];
if(abs(para2 - para[2]) > 4) para2 = para[2];

int pos;

float dx, dy;

for(int y=0; y<8; y++) {
float tr = 3.1 + 6.3 * sin(millis() / (20.0 * para1)) * sin((millis() / 1000.0) + y * 100.0);
float ts;
dy = my - y;

for(int x=0; x<8; x++) {
dx = mx - x;

ts = sqrt(sq(dx) + sq(dy));
ts = exp(-ts * .5);
pos = x * 8 + y;
hsvbuf1[pos].h = para1 / 4 * ts; // y * 32.0 + 255 * sin(millis() / 10000.0);
hsvbuf1[pos].s = 255 * ts;
hsvbuf1[pos].v = ts * 255;
}
}
}
render_lamp();
}

void mouseDragged() {
int mx = mouseX;
int my = height - mouseY;

if (my < 80) {
if (my < 40) {
para[2] = round(map(mx, 0, width, 0, 1023));
fill(0);
rect(0, height - 40, width, 40);
fill(#4682B4);
rect(0, height - 40, mx, 40);
fill(255);
text("para[2] = " + para[2], 10, height - 15);
} else {
para[1] = round(map(mx, 0, width, 0, 1023));
fill(0);
rect(0, height - 80, width, 40);
fill(#3E484F);
rect(0, height - 80, mx, 40);
fill(255);
text("para[1] = " + para[1], 10, height - 55);
}
}
}


void render_lamp() {
noStroke();
for (int x = 0; x < 8; x ++) {
for (int y2 = 0; y2 < 8; y2 ++) {
int y;
if ((x % 2) == 0) {
y = y2;
} else {
y = 7 - y2;
}

int pos = x * 8 + y;

int x0 = 40 + 40 * x;
int y0 = (8 * 40) - 40 * y;

//fill(led[pos]);
fill(color(hsvbuf1[pos].h, hsvbuf1[pos].s, hsvbuf1[pos].v));
rect (x0, y0, 38, 38);
}
}
}
</pre>
1.383
Bearbeitungen