We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › My first piece - hypnotic spokes!
Page Index Toggle Pages: 1
My first piece - hypnotic spokes! (Read 780 times)
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;
 }

}
Re: My first piece - hypnotic spokes!
Reply #1 - Mar 7th, 2009, 9:28pm
 
There is a spanner in the spokes


"cannot find anything named bgcolourDirection"
Re: My first piece - hypnotic spokes!
Reply #2 - Mar 8th, 2009, 7:02pm
 
there' s a line missing: this block should read:

//switcher variables used in oscillation.

int colourDirection = 1;
//this is the line to add although I'm not sure if should be 1 or -1?

int bgcolourDirection = 1;
 
float sizeDirection = 0.5;  
int colour = 0;
int bgcolour = 255;
float endlines = 6.2;
Re: My first piece - hypnotic spokes!
Reply #3 - Mar 8th, 2009, 7:15pm
 
bgcolourDirection = -1 makes the background fade thru black and white.

also halved the output size which sped it up on my old G3 iBook!
Re: My first piece - hypnotic spokes!
Reply #4 - Mar 8th, 2009, 8:50pm
 
I'm so annoyed at myself! I think I pasted the wrong version of the code or something. I think I must have deleted something whilst adding some quick comments to the code before copy/pasting it.. :/

Here is the correct version -


-----------

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 bgcolourDirection = -1;
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;
 }

}



-------------

Here is what was missing;

int bgcolourDirection = -1;
Re: My first piece - hypnotic spokes!
Reply #5 - Mar 9th, 2009, 8:25pm
 
WHOA, DUDE
Page Index Toggle Pages: 1