Modify a text file: $/39/p4b.java
$/39/p4b.java
//// Creatures, using Objects. ///// Project 3-1c String title="Project 3-1c \n (methods with args)", author="BAM"; boolean debug=false; float bugX,bugY; color skyColor=color(200,220,255); color seaColor=color(50,200,100); color grassColor=color(0,150,50); float sealevel=100, waveSize=20, waveSpacing=20; float buttonX, buttonY; // Creatures // Creature octo, squid, lobster; void setup() { //// Init. size(640,480); buttonX=width-200; buttonY=height-100; // Create the creatures // octo= new Creature(); squid= new Creature(60, 40, 0, 10); squid.r=255; lobster= new Creature(30, 50, 4, 0 ); lobster.g=255; } void draw() { //// Next frame scene(); action(); } void scene() { //// sky +_ ocean background( 200, 200, 255 ); fill( 100,200,100 ); // Sea rectMode( CORNER ); rect( 0,100, width, height -100 ); } void action() { //// Move creatures. octo.dx= (mouseX -octo.x ) / 20; octo.dy= (mouseY - octo.y) / 20; octo.move(); squid.dx= (octo.x - squid.x) / 60; squid.dy= (octo.y - squid.y) / 60; squid.move(); lobster.dx= (squid.x - lobster.x) / 60; lobster.dy= (squid.y - lobster.y) / 60; lobster.move(); //// Draw creatures. octo.show(); squid.show(); lobster.show(); text (octo.x, 10,10 ); } class Creature { //// Define creature with arms and legs float x=200, y=200, dx=3, dy=2; float w=80, h=120; int arms=0, legs=8; int r=255, g=0, b=0; //// CONSTRUCTORS //// Creature( ) { //// Default constructor x= random( width/4 ); y= random( 100, height/4 ); } Creature( float w, float h, int arms, int legs ) { //// 4-arg Constructor x= random( width/4 ); y= random( 100, height/4 ); dx= 3-random( 6 ); dy= 2-random( 4 ); this.w= w; this.h= h; this.arms= arms; this.legs= legs; r= int( random( 0, 150 ) ); g= int( random( 100, 250 ) ); b= int( random( 0, 150 ) ); } //// METHODS //// void move() { //// x += dx; y += dy; } void show() { //// fill( r,g,b ); rectMode( CENTER ); rect( x,y, w,h ); //// Legs strokeWeight(3); float legX, legY; legX= x - w/2; legY= y + h/2; for ( int j=0; j