int rotation;
int lastMousePos;
int mouseMovement;
boolean forward = true;
void setup()
{
size(900, 400); // def. window size
}
void draw()
{
mouseMovement = mouseX-lastMousePos;
// println(mouseX-lastMousePos);
background(255);
//wheel(width/2, height/2);
car(mouseX, height/2);
lastMousePos = mouseX;
}
void car(int x, int y) {
rotation+= abs(mouseMovement);
pushMatrix();
translate(x, y);
if (mouseMovement<0) {
forward = false;
}
if (mouseMovement>0) {
forward = true;
}
if(forward == false) {
scale(-1,1);
}
println(forward);
fill(100, 0, 0);
noStroke();
beginShape();
vertex(0, 0);
vertex(5, -50);
vertex(50, -50);
vertex(70, -80);
vertex(150, -80);
vertex(190, -50);
vertex(265, -45);
vertex(270, 0);
vertex(0, 0);
endShape();
wheel(60, 0);
wheel(210, 0);
popMatrix();
}
void wheel(int x, int y) {
pushMatrix();
translate(x, y);
rotate(radians(rotation));
int radius = 25;
fill(0, 100, 0);
stroke(0);
strokeWeight(7);
ellipse(0, 0, radius*2, radius*2);
strokeWeight(4);
line(0-radius, 0, 0+radius, 0);
line (0, 0-radius, 0, 0+radius);
noStroke();
popMatrix();
}
|