We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a football being kicked by a robot going through the goal posts. How do I make the football rotate while flying through the air? Here is my code. Thanks
int x = 80;
int y = 600;
int bodyHeight=110;
int neckHeight=140;
int radius = 45;
int ny = y-bodyHeight-neckHeight-radius;
int m=740;
int b=558;
int t=15;
int h=30;
void setup(){
size (1520,780);
}
void draw(){
smooth();
strokeWeight(2);
background(204);
fill(#36A6FF); //sky color
rect(0,0,2000,600); //sky
fill(#F6FF00);//suncolor
ellipse(30,30,100,100); //sun
ellipseMode(RADIUS);
//neck
stroke(102); //set dtroke 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-75); //tall
line(x+12,ny,x+78,ny+15); //Medium
//Body
noStroke(); //disable stroke
fill(102);//set fill to gray
ellipse(x,y-33,33,33); //antigravity orb
fill(#FF6600);//set fill to block
rect(x-45,y-bodyHeight,90,bodyHeight-33); //main body
fill(102); //set fill to gray
rect(x-45,y-bodyHeight+17,90,6); //gray stripe
//head
fill(#FF6600); //set fill to block
ellipse(x+12,ny,radius,radius); //head
fill(255); //set fill to white
ellipse(x+24,ny-6,17,17); //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,400); //left upright
fill(234,100,30); //color football
ellipse(m,b,t,h); //football
fill (234,234,2);
rect(1400,200,10,400); //right upright
rect(1200,400,210,10); //crossbar
fill(#26D34D); //grass color
rect(0,600,2000,2000); //grass
fill(#FF0000); //flag color
rect(1210,200,25,10); //left flag
rect(1410,200,25,10); //right flag
fill(#FF6600); //pad color
rect(1185,500, 40, 100); //left pad
rect(1385,500,40,100); //right pad
fill(0);//tee color
rect(725,588,30,12);//tee
//bigger eye, smaller big antenna, sky, sun, laces on the ball, upright flags, orange body color, and post pads.
}
//kick the football
void mousePressed(){
x+=30;
if (x>700){
m+=50;b+=-25;x=700;
rotate(90);
ellipse(m,b,t,h);
}
}
Answers
Compute the argument passed to rotate() based on the x position of the ball.
or:
See also: https://forum.processing.org/two/discussion/23956/how-to-make-an-ellipse-rotate
The matrix is reset at start of draw automatically
This means you have to pass a value to rotate that makes the ball rotate even though the previous rotation is not there anymore