We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working to have a robot run up and kick a football (ellipse) through uprights using the mousePressed option. After the ball is kicked, I am trying to get the ball to rotate about its center 90 degrees every time the mouse is clicked, just like a normal football would rotate when kicked. The problem that I have is that the ellipse returns to its original shape after every click, instead of staying in the new, rotated shape. Attached is my code that I have so far, hopefully someone is able to point out what I have wrong or need to change. I appreciate the assistance.
int x = 80; int y = 600; int bodyHeight = 110; int neckHeight = 140; int radius = 45; int ny = y-bodyHeight-neckHeight-radius; int m = 600; int b = 573; int j = 17; int k = 26;
void setup(){ size (1520,780); } void draw(){ smooth(); strokeWeight(2); background(#0671C6); ellipseMode(RADIUS); //neck stroke(102); //set stroke to gray line(x+2,y-bodyHeight,x+2,ny); //left line(x+12,y-bodyHeight,x+12,ny); // Middle line(x+22,y-bodyHeight,x+22,ny); //Right //antennae line(x+12,ny,x-18,ny-43); //small line(x+12,ny,x+42,ny-99); //tall line(x+12,ny,x+78,ny+15); //Medium //Body noStroke(); //disable stroke fill(0); //set fill to black ellipse(x,y-33,33,33); //antigravity orb fill(#E50C1E); //set fill to red rect(x-45,y-bodyHeight,90,bodyHeight-33); //main body fill(0); //set fill to black rect(x-45,y-bodyHeight+17,90,6); //gray stripe //head fill(#797576); //set fill to gray ellipse(x+12,ny,radius,radius); //head fill(255); //set fill to white ellipse(x+24,ny-6,14,14); //large eye fill(0); //set fill to black ellipse(x+24,ny-6,3,3); //pupil fill(155); //set fill to light gray ellipse(x,ny-8,5,5); //small eye 1 ellipse(x+30,ny-26,4,4); //small eye 2 ellipse(x+41,ny+6,3,3); //small eye 3 //goal post fill(234,234,2); rect(1200,200,10,200); //left upright rect(1200,400,210,10); //crossbar rect(1300,400,10,200); //base pole //football fill(#40190A); //set fill to brown ellipse(m,b,j,k); //football fill(234,234,2); rect(1400,200,10,200); // right upright //grass fill(#0A3E04); //set fill to green rect(0,600,1900,500); //fill in glass //flag 1 fill(#E54405); triangle(1200,200,1200,180,1250,190); //left flag triangle(1400,200,1400,180,1450,190); //right flag //Yardlines fill(#FCF7F5); rect(600,600,10,500); //10 yerd line rect(200,600,10,500); //20 yard line rect(400,600,10,500); //15 yard line rect(800,600,10,500); //5 yard line rect(1000,600,10,500); //front of end zone rect(1300,600,10,500); //back of end zone //endzone fill(#E8071A); rect(1010,600,290,500); //endzone fill //Sun fill(#F7BF05); ellipse(100,100,90,90); }
//kick the football void mousePressed(){ x+=30; if (x>550){ m+=100;b+=-45;x=550;
pushMatrix(); translate (width/2,height/2); rotate(PI/4); translate(100,-45); ellipse(m,b,j,k); popMatrix(); } }
Answers
Edit post, highlight code, press ctrl-o to format
See also: https://forum.processing.org/two/discussion/23955/rotate-an-ellipse-during-mousepressed