final int appwidth = 600;
final int appheight = 600;
final float stepsize = 10;
targetedobject myobject;
class targetedobject { // This is the object to move
int mcurrentx, mcurrenty; // This will store the current location of the object
int mtargetx, mtargety; // This will store the target location of the object
float mrotation; // This is the current orientation of this object
boolean demostep;
targetedobject( int x, int y, int r ) { // Initialize with coordinate and orientation
mcurrentx = x;
mtargetx = x;
mcurrenty = y;
mtargety = y;
mrotation = r;
demostep = false;
}
void updatedraw() { //Draws the shape
pushMatrix();
translate( mcurrentx, mcurrenty );
rotate( mrotation );
noStroke();
fill( 255, 0, 0 );
ellipse(0, 0, 40, 40);
noFill();
stroke(255);
strokeWeight(5);
line( -10, 0, 10, 0 );
line( 10, 0, 5, -5 );
line( 10, 0, 5, 5 );
popMatrix();
}
void drawhelper(){
}
void startstep(int x, int y){
this.demostep = true;
this.mtargetx = x;
this.mtargety = y;
}
void endstep(){
this.demostep = false;
}
}
void setup() {
size(appwidth, appheight);
background(0);
myobject = new targetedobject( width / 2, height / 2, 0 );
}
void draw() {
background(0);
myobject.updatedraw();
}
void mousePressed() {
if (mouseButton == LEFT) {
myobject.startstep(mouseX, mouseY);
}
}
void mouseReleased() {
if( myobject.demostep ){
myobject.endstep();
}
}