Modify a text file: $/project4a.java
$/project4a.java
//// Bouncing ball within a box. String title="Bouncing ball within a box."; String news=""; String author="B.A.Martin, CST112, Project 4a"; int counter=0; float boxX=50, boxY=50, boxW=500, boxH=300; float ballX=10, ballY=10, ballDX=5, ballDY=9; float ballR, ballG, ballB; void setup() { //// Set up frame size, etc. size( 640, 480 ); reset(); } void reset() { ballDX= random(10); ballDY= random(4); ballR= random(255); ballG= random(255); ballB= random(255); counter=0; // Zero out the frame count. } void draw() { // Draw the next frame. scene(); // new scene (bg + text ) //// Dynamic sketches -- change with every frame! //// action(); ball(); }// draw() // void scene() { background( 255, 220, 220 ); // RED, GREEN, BLUE text( news, width/4, 40 ); fill(0); text( title, width/4, 20 ); text( author, 20, height-30 ); }// scene() // void action() { //// 0.7: Action! //// fill( 255,127,0); line(0,310, width,310); if ( (counter/30) % 2 == 0 ) { textSize(20); text( "Move the mouse!", 150, 350 ); // Flashing message. textSize(12); } counter++; rectMode(CENTER); noStroke(); rect( mouseX, mouseY, 50, 90 ); fill( 255,255,255 ); ellipse( mouseX-12, mouseY-30, 10,10 ); ellipse( mouseX+12, mouseY-30, 10,10 ); fill( 0,0,255 ); ellipse( mouseX-12, mouseY-30, 5,5 ); ellipse( mouseX+12, mouseY-30, 5,5 ); fill(255,0,0); text( "Mickey", mouseX-20, mouseY+30 ); } void ball() { //// 0.8: Action! //// fill(0); text( "Click inside box,\n for a new ball. ", width-100, 20 ); text( "Frame number "+counter, width/2, height-20 ); fill( 220,230,255 ); stroke(0); strokeWeight(4); rectMode(CORNER); rect( boxX, boxY, boxW, boxH ); ballX += ballDX; ballY += ballDY; if (ballX < 0 || ballX > boxW) ballDX= -ballDX; if (ballY < 0 || ballY > boxH) ballDY= -ballDY; fill( ballR, ballG, ballB ); noStroke(); ellipseMode(CENTER); ellipse( boxX+10+ballX, boxY+ballY, 15,15 ); } boolean within( float x, float y, float left, float right, float top, float bottom ) { //// True if x,y within boundaries //// return x>left && x
top && y