theta
YaBB Newbies
Offline
Posts: 3
My first piece - hypnotic spokes!
Mar 7th , 2009, 7:10pm
EDIT: SEE BELOW FOR RECTIFIED CODE, I SCREWED UP AND POSTED BROKEN CODE, SORRY!! Hypnotic Spokes - http://pastebin.com/f6ff4dc23 (btw, is there a pastebin that highlights processing code?) This is not only my first processing project, but also my first attempt at programming. It took me around a week. Hopefully I'll be getting faster at this! Any suggestions on how else I might have achieved this, how to optimize the code and make it run smoother, or ideas on how I could evolve it. What I would like to do next is have the individual 'spokes' oscillate in size by a small random amount (so it wouldn't be a perfect circle but a more organic microbial shape!). Feel free to toy around with it. ----------------------------------------- void setup() { size(screen.width,screen.height); background(255); noSmooth(); } //initialization variables float r = screen.height/4; float r2 = 0; float r2x = 0; float r2y = 0; float x2 = 0; float y2 = 100; float theta = 0; float theta2 = 0; //switcher variables used in oscillation. int colourDirection = 1; float sizeDirection = 0.5; int colour = 0; int bgcolour = 255; float endlines = 6.2; void drawLines() { while (theta <= endlines) { stroke(colour); strokeWeight(1); float x = r * cos(theta); float y = r * sin(theta); line(x2, y2, x+width/2,y+height/2); theta += 0.1; drawCircles(x, y); } } //draws the blobs on the ends of the lines. void drawCircles(float xx, float yy) { noStroke(); fill(colour - colourDirection); ellipse(xx+width/2,yy+height/2,10,10); } void draw() { background(bgcolour); stroke(colour); bgcolour = bgcolour + bgcolourDirection; theta = 0; colour = colour + colourDirection; r = r + sizeDirection; x2 = r2 * cos(theta2) + width/2; y2 = r2 * sin(theta2) + height/2; drawLines(); //fine tuned incrementers to give the smoothest possible animation. r2 += 0.055; r += 0.1; theta2 += 0.036; //ossilation. if (colour >= 255) { colourDirection *= -1; sizeDirection *= -1; bgcolourDirection *= -1; } if (colour <= 0) { colourDirection *= -1; sizeDirection *= -1; bgcolourDirection *= -1; } }