//// _29cst112/x0d //// bam:2022/6/7 String title = "My first sketch - animated"; String subtitle = "animation: bounce off walls; sun arcs thru sky"; String help = "Click repositions; r to reset; q to quit"; String author = "Your Name"; float bamX, bamY, bamDX, bamDY; float sunX, sunY, sunDX=1; float horizon; //////// SETUP //////// void setup() { size( 600, 400 ); horizon = height/4; reset(); } void reset() { bamX=100; bamY=100; bamDX=3; bamDY=2; sunX = 20; sunY = height/8; } //////// DRAW NEXT FRAME //////// void draw() { scene(); credits(); cast(); action(); } void scene() { background(200,255,255); // sky fill(255,255,0); ellipse( sunX, sunY, 40, 40 ); // sun fill(200,255,200); rect( 0,horizon, width,height*3/4 ); // grass } void credits() { fill(0); textSize(20); text( title, 20, 15 ); textSize(12); text( subtitle, 20, 25 ); text( help, 20, 35 ); text( author, 10, height-10 ); fill(0,0,255); text( help, width/2, 15 ); } void cast() { fill( 255,200,200 ); ellipse( bamX,bamY, 20,30 ); // head fill(255,0,255); triangle( bamX-15,bamY-10, bamX+15,bamY-10, bamX,bamY-25); // hat fill( 0,255,255 ); rect( bamX-20, bamY+15, 40, 60); // body fill(0,0,255); text( "bam", bamX-15, bamY+32 ); } void action() { if (sunX > width-20) sunX = 20; sunX = sunX + sunDX; sunY = horizon * ( 1 - sin(PI * sunX/width) ); // bamX = bamX + bamDX; bamY = bamY + bamDY; } void mousePressed() { bamX = mouseX; bamY = mouseY; } void keyPressed() { if (key == 'q') exit(); if (key == 'r') reset(); }