In our final project, we plan to create a moving object which will be controlled by the movement of the balance board. Therefore, we choose the object workshop to better know how to create an object in processing. We managed to control where objects appear and when to remove them by using “mousePressed” and “keyPressed”. Based on this, we will try to control the object with the sensor and a specific tool we make.
//float x; //Emoji e; //Emoji f; ArrayList<Emoji> emojiList; void setup() { size(1600, 900); emojiList=new ArrayList<Emoji>(); //for (int i=0; i<10; i++) { // emojiList.add(new Emoji(random(width/2), random(height/2), color(random(255), random(255), random(255)))); //} //e= new Emoji(width/2,height/2,color(random(255),random(255),random(255))); //f=new Emoji(width/3,height/3,color(random(255),random(255),random(255))); } void draw() { background(255); fill(200); for (int i=0; i< emojiList.size(); i++) { Emoji e = emojiList.get(i); e.display();// same as emojiList[i] e.move(); } //e.display(); // f.display(); } void mousePressed() { float x= map(mouseX, 0, width, width/8, width/2); float y= map(mouseX, 0, width, width/8, width/2); emojiList.add(new Emoji(x, y, color(random(255), random(255), random(255)))); } void keyPressed() { emojiList.remove(emojiList.size()-1); }
class Emoji { float x, y; float size; color clr; String type; float spdX; float spdY; //type="simley-face"; // if(type == "")//never give things value at the top. Emoji(float startingX, float startingY, color startingColor) { x=startingX; y=startingY; size=random(50, 100); clr=startingColor; spdX= random(-5,5); spdY= random(-5,5); } void display() { fill(clr); ellipse(x, y, size, size); fill(255); //size=random(50,100); ellipse(x-size/4, y-size/6, size/4, size/2); ellipse(x+size/4, y-size/6, size/4, size/2); } void move(){ x= x+spdX; y= y+spdY; } }