Modify a text file: $/ashley.java
$/ashley.java
class Fish { // Fishes swim float x=200,y=200, dx=5, dy=.30, w=80,h=30; int r= 100,g=8,b=90; // Color String name=""; int glitter=0; // METHODS // void show() { // Draw the fishes. fill(r+random(glitter), g+random(glitter), b+random(glitter)); ellipse( x,y,w,h ); float front=x-15+w/2, back=x+15-w/2; if (dx<0) { front=x+15-w/2; back=x-15+w/2; } triangle( back,y, back-20,y-10, back-20,y+10 ); // Tail fill(155); // eye strokeWeight(1); ellipse( front, y-10, 10, 10 ); // textSize(20); fill( 255-r, 255-g, 255-b ); text( name, x-25, y ); } void move() { //move the fishes x += dx; y += dy + random( -3, +3 ); if (x>right-w) { dx= -dx; } if (x
bottom-25+h) dy= -dy; } boolean hit( float x, float y ) { // boolean/if/return true statement if (x < x-w/2 || x > x+w/2) return false; if (y < y-h/2 || y > y+h/2) return false; return true; // Hit detected. } //// CONSTRUCTORS // Fish( ) { // Create default constructor, with no args. randomstart(); randomcolor(); } Fish( String s ) { // One-arg constructor, with name name= s; randomstart(); randomcolor(); } Fish( String s, int r, int g, int b ) { // 3-arg constructor, with name & color name= s; this.r= r; this.g= g; this.b= b; randomstart(); randomcolor(); } void randomstart() { x= random( left+150, right-150 ); y= random( top+150, bottom-150 ); dx= random( 1, 5 ); dy= random( 1, 3 ); } void randomcolor() { r= int( random(255) ); g= int( random(255) ); b= int( random(255) ); } Fish( float x, float y, String s, int r, int g, int b ) { // 6-arg constructor, with xy, dx,dy, name & color this.x= r; this.y= r; name= s; this.r= r; this.g= g; this.b= b; } Fish( float x, float y, float dx, float dy, String s, int r, int g, int b ) { // 8-arg constructor, with xy, dx,dy, name & color this.x= r; this.y= r; this.dx= dx; this.dy= dy; name= s; this.r= r; this.g= g; this.b= b; } }//END class Fish // "Button" class class Button { // Button } // GLOBALS: String title="Fish project"; String news="r to reset; e to exit"; float left, top, right, bottom; // float left=50, top=50, right=550, bottom=350; Button b1; // Fish charlie, sarah; // Declare the object // int many=3, toomany=20; Fish[] school= new Fish[toomany]; // void setup() { // Setup screen; instantiate object(s). size( 600, 400 ); left= 50; right= width-50; top=50; bottom= height-50; reset(); } void reset() { // Reset everything. // // Instatiate the fishes. charlie= new Fish( "Charlie", 255, 150, 100 ); sarah= new Fish( charlie.x, charlie.y+100, "Sarah", 200, 150, 200 ); many=3; school[0]= charlie; school[1]= sarah; // school[2]= new Fish( "Rainbow", 50, 100, 50 ); school[2].glitter= 125; // many=12; for (int i=3; i