What I learned:
1.Map can do many things, not only changing the range of the sensor value from Arduino but also can change the range of the value in processing. It is really useful if I want all my images don’t go out the canvas.
2.I learn how to create many balls using the add function.
ballList.add(new Ball(random(-10,10), random(-10,10),color(random (255))));
also the Ball temp = ballList.get(i); temp.display(); temp.move(); to make the ball spread out and move.
3. The class is a great thing. I can change on another file no need to worry about affecting other function in the original file.
The code for processing:
My interaction is when pressing the Key UP, the ball will appear and spread out.
Ball cloverBall; Ball cindyBall; float x; ArrayList<Ball> ballList = new ArrayList<Ball>(); void setup(){ size(1600,900); ballList = new ArrayList<Ball>(); for(int i=0; i<100; i++){ ballList.add(new Ball(random(-10,10), random(-10,10),color(random (255)))); x=map(x,0,1023,0,width); } //cloverBall = new Ball(random(-10,10), random(-10,10),color(random (255))); //cindyBall = new Ball(5,0,color(0,0,200)); } void draw(){ background(255,255,150); if (key == CODED) { if (keyCode == UP) { for(int i=0; i<ballList.size(); i++){ Ball temp = ballList.get(i); temp.display(); temp.move(); } } } }
class Ball{ float x,y; color c; float spdX, spdY; float r; Ball(float newSpdX, float newSpdY, color newColor){ r=50; spdX= newSpdX; spdY= newSpdY; c=newColor; x=width/2; y=height/2; } void move(){ x= x + spdX; y= y + spdY; } void display(){ fill(c); ellipse(x,y,r,r); } } The video recitation10