Seeker s;//http://kirkjerk.com/java/artseroids/js/ void reset(){ background(100); s = new Seeker(); } void keyPressed(){ if(key == ' ') reset(); } void setup() { size(500, 500); noStroke(); reset(); frameRate(10); noStroke(); pushMatrix(); translate(width/2,height/2); fill(128,0,0); rect(-5,-5,10,15); rotate(-PI/2); drawPart(); popMatrix(); } void draw() { s.seek(mouseX, mouseY); s.move(); s.draw(); } class Seeker { float x, y, a, s; float MAXTURN = .3; Seeker() { x = width/2; y = height/2; a = -PI/2; s = 8; } void move() { x += s * cos(a); y += s * sin(a); while (x < 0) x += width; while (x > width) x -= width; while (y < 0) y += height; while (y > height) y -= height; } void draw() { pushMatrix(); translate(x, y); rotate(a); drawPart(); if(random(1) < .4){ randomOrnamentColor(); ellipse(random(-8,8),4,5,5); } noStroke(); fill(255,255,0); // ellipse(20,0,5,5); drawStar(20,0,5,0); popMatrix(); } void seek(float rtx, float rty) { float dx = (rtx - x); float dy = ( rty - y); //this trick seems to work to deal with the overlap.. //they consider the shortest path even if other side of screen if (abs(dx) > width/2) { dx *= -1.0; } if (abs(dy) > height/2) { dy *= -1.0; } float wantangle = atan2(dy, dx); float anglediff = (a - wantangle); anglediff /= PI; //this next bit catches the "runaround" if (anglediff > 1) { anglediff -= 2; } if (anglediff < -1) { anglediff += 2; } // if (abs(anglediff) > .1) { if (anglediff > 0) { a -= smaller(abs(anglediff*PI),MAXTURN); } else { a += smaller(abs(anglediff*PI),MAXTURN);; } // } } } float smaller(float a, float b){ if(a < b) return a; return b; } void randomOrnamentColor(){ float r = random(1); if(r < .33) { fill(255,0,0); stroke(128,0,0); return; } if(r < .66) { fill(0,0,255); stroke(0,0,128); return; } fill(255,255,0); stroke(128,128,0); return; } void drawStar(float x, float y, float size,float angle) { fill(255, 255, 0); noStroke(); pushMatrix(); translate(x, y); beginShape(); vertex(cos(angle) * size, sin(angle)*size); vertex(cos(angle + TWO_PI*.4) * size, sin(angle+ TWO_PI*.4)*size); vertex(cos(angle + TWO_PI*.8) * size, sin(angle+ TWO_PI*.8)*size); vertex(cos(angle + TWO_PI*.2) * size, sin(angle+ TWO_PI*.2)*size); vertex(cos(angle + TWO_PI*.6) * size, sin(angle+ TWO_PI*.6)*size); endShape(CLOSE); popMatrix(); } void drawPart(){ // if(true)return; noStroke(); fill(100,200,100); float s = random(10,20); triangle(23, 0, 0, -s, 0, +s); strokeWeight(2); stroke(76,150,75); line(20,0,0,-s); line(20,0,0,s); line(10,0,0,-s); line(10,0,0,s); }