Modify a text file: $/trees_5_not_trees_3_it_s_trees_5_not_trees_3.pde
$/trees_5_not_trees_3_it_s_trees_5_not_trees_3.pde
//// Trees 5 float horizon; color sky= color( 110, 110, 250 ); color grass= color( 160, 255, 160 ); int many=5; Tree t1, t2, t3, t4, t5; void setup() { size( 800, 600 ); horizon = height/3; reset(); } void reset() { int m=1; t1 = new Tree(m++); t2 = new Tree(m++); t3 = new Tree(m++); t4 = new Tree(m++); t5 = new Tree(m++); } void draw() { background(sky); fill(grass); rect( 0,horizon, width,height-horizon ); t1.show(); t2.show(); t3.show(); t4.show(); t5.show(); } void keyPressed() { if(key == '1') { t1.jump(); } if(key == '2') { t2.jump(); } if(key == '3') { t3.jump(); } if(key == '4') { t4.jump(); } if(key == '5') { t5.jump(); } if(key == 'r') { reset(); } } //// OBJECTS //// class Tree { float x=100,y=100, w=100,h=150; color leaves= color( 150, 200, 150 ); color bark= color( 120, 90, 90 ); int number; Tree( int m ) { number=m; jump(); w=random(20,350); h=random(30,450); leaves=color( random(100,200), random( 150,255), random(100,200)); bark=color( random(100,200), random( 30,130), random(30,130)); } void mousePressed() { background(0); println(mouseX, mouseY); if(t1.hit(mouseX, mouseY)) { t1.jump(); } } void show() { fill(bark); rect( x-20,y, 40,h ); fill(leaves); ellipse(x,y, w,w); fill(0); text(number, x, y); } void jump() { x= random(100, width-100); y= random(horizon-120, height-200); } boolean hit( float x1, float y1) { println( dist(x1,y1, x,y) ); if ( dist(x1,y1, x,y) < w/2 ) { return true; } return false; } } // End of class Tree. //