Modify a text file: $/2914a-colors.java
$/2914a-colors.java
//// Exercise in class -- color-changing square. float x,y, w,h; // Position and size of square. int r,g,b; // Color of fill. int kr=255,kg=255,kb=255; // Color of fill. int birdX=50, birdY=50, birdDX=10, birdDY=10, birdW=30; void setup() { size( 800, 600 ); //// Initialize the position, color, etc. x= width/2; y= height/2; w= width/4; h= height/4; rectMode(CENTER); ellipseMode(CENTER); //// Initialize colors. fillColor(); bgColor(); } void draw() { background( kr, kg, kb ); fill( (128+kr)%256, (128+kg)%256, (128+kb)%256 ); text( "Click within rectangle, to change color!", 10, 10 ); text( "Press 'k' to change background color!", 10, 25 ); //// Chase mouse & squeeze the creature. chase(); squeeze(); creature(); //// Birds bird(); //// Debugging: Display some values on screen. fill( 0 ); text( "w= "+w, width-100, height-20 ); text( "h= "+h, width-100, height-10 ); } void creature() { //// Draw creature at x,y //// FIll with latest color. fill( r,g,b ); rect( x,y, w,h ); //// Complimentary color for head. float d= (h+w) / 6; // Diameter of head. fill( (128+r)%256, (128+g)%256, (128+b)%256 ); ellipse( x, y-h/2-d/2, d, d ); } void bird() { //// Draw bird. birdDX= (birdX>0 && birdX
0 && birdY