正在处理-向后翻筋斗

问题描述 投票:0回答:1

我必须编写一个程序,显示汽车以正确的弹丸运动在空中飞行并向后翻腾,着陆在车轮上。

到目前为止,我所拥有的代码使我可以使汽车空飞。我需要做的就是使汽车向后旋转并正确着陆。

我目前拥有的代码:

float x,y;
float s = 20;
float theta = 0.64;
float g = 9.8;
float t =0.0;
PImage img;
void setup(){
  size(750,600);
  img = loadImage("myimage.gif");

  noStroke();
  smooth();
}

void draw(){
   fill(0, 22);
   rect(0, 0, width, height);
   t = t+0.01;
   x = s*cos(theta)*t;
   y = (s*t*sin(theta))-(0.5*g*t*t);
   fill(255);
   image(img,x*15,550-y*5);
}

我正在为汽车使用的图像:

enter image description here

processing
1个回答
0
投票

使用rotate()使汽车绕其相对位置旋转,并使用rotate()将汽车移至其位置。

translate()

旋转角(translate())必须随时间增加(r = f(t)):

translate(x*15,550-y*5);
rotate(r);
image(img, 0, 0);

请参见示例:

r

float r = alpha * t;
© www.soinside.com 2019 - 2024. All rights reserved.