float R,r,d; float theta,dtheta; float x,y,xo,yo; float dr; float sc; // scale PFont fontA; void setup() { size(400,400); framerate(60); background(127); strokeWeight(7); fontA = loadFont("CourierNewPSMT-9.vlw"); textFont(fontA, 12); smooth(); theta = 0.0; dtheta = 0.2; R = 110; // radius of outer fixed circle r = 64; // radius of inner rolling circle d = 90; // distance from center of rolling circle dr = 0.4; sc = 1; update_xy(); } void update_xy() { x = (R-r)*cos(theta) + d*cos( ((R-r)/r)*theta ); y = (R-r)*sin(theta) - d*sin( ((R-r)/r)*theta ); //x = r * cos(theta); //y = r * sin(theta); theta += dtheta; // r += dr; // + random(-0.2,0.2); // if( r> 200 ) dr = random(-0.6,-0.5); // if( r < 0 ) dr = random(0.6,0.8); } void draw() { fill(127); stroke(127); rect(0,0,width,16); fill(0); text("R:"+(int)R+" r:"+(int)r+" d:"+(int)d+" theta:"+(int)theta,8,8); text("space randoms, return clears, +/- scales, [],<> alters", 8,16); pushMatrix(); smooth(); translate(width/2,height/2); scale(sc); xo = x; yo = y; update_xy(); float dx = (x-xo); float dy = (y-yo); float rth = atan2(dy,dx); float rx = (dx/cos(rth))/dtheta; float ry = (dy/sin(rth))/dtheta; // println("dx:"+dx+" dy:"+dy+" rth:"+rth+" rx:"+rx+" ry:"+ry+ // " r:"+(int)r+" x:"+(int)x+" y:"+(int)y); stroke( 0,0, 100-100*cos(theta/100) ); // this is clever i thought strokeWeight(5); line( x,y, xo,yo); // stroke(1); noFill(); strokeWeight(1); // ellipse(0,0, R,R); // ellipse( (R-r)*sin(theta), (R-r)*cos(theta), r,r); popMatrix(); } void keyPressed() { if( key == CODED ) { if( keyCode == UP ) d += 1; else if( keyCode == DOWN ) d -= 1; else if( keyCode == LEFT ) r += 1; else if( keyCode == RIGHT ) r -= 1; } else if( keyCode == RETURN || keyCode == ENTER ) background(127); else { if( key == ',' || key == '<' ) R -= 5; else if( key == '.' || key == '>' ) R += 5; else if( key == ']' ) dtheta += 0.01; else if( key == '[' ) dtheta -= 0.01; else if( key == '-' || key == '_' ) sc -= 0.1; else if( key == '=' || key == '+' ) sc += 0.1; else if( key == ' ' ) { d = random( 10,100); R = random( 100,140); d = random( 10,100); theta = 0; update_xy(); xo = x; yo = y; background(127); } } }