Sonntag, 8. November 2009

test drive speed by photocell





//-----drive speed by photocell -----//

import cc.arduino.*;
import processing.serial.*;

Arduino myArduino;

float value;
int count=0;
float multi;
float x=(random (0,600));
float y=(random (0,600));
float xspeed=1;
float yspeed=1;
float vx = 0;
float vy = 0;
float swx,swy;

void setup() {
colorMode(HSB,100);
size(600,600);
myArduino = new Arduino(this, Arduino.list()[1], 57600);
background(0);
smooth();
count=0;
}

void draw(){
move();
border();
fill(0,0,0,0);
noStroke();
rect(0,0,width,height);
value=5*(myArduino.analogRead(0));
stroke(value,100,100,50);
strokeWeight(10/5);
noFill();
ellipse(x,y,value*2,value*2);

if ( (count% 100 >= 5) && (count% 100 <= 50) ) {
myArduino.digitalWrite(13, myArduino.HIGH);
}
else{
myArduino.digitalWrite(13, myArduino.LOW);
}
if (count==100) xspeed= (random(-1,1));
if (count==100) yspeed= (random(-1,1));
if (count==100) count=0;
count++;
saveFrame("anim/circles-####.png");
}

void move() {
vx = xspeed;
vy = yspeed;
multi=(5-(value*0.03));
x += vx*multi;
y += vy*multi;

}

void border() {
float radius= (value*2)*0.0;
if (x < -radius) x = width+radius;
if (y < -radius) y = height+radius;
if (x > width+radius) x = -radius;
if (y > height+radius) y = -radius;
}

Keine Kommentare:

Kommentar veröffentlichen