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.
Page Index Toggle Pages: 1
hypotrochoid (Read 460 times)
hypotrochoid
Aug 5th, 2006, 7:29am
 
Hello everyone!  I am new to Processing and coding in general. I am trying to learn how to take a concept and continue towards a complete code.  Currently, I am trying to reproduce a spirograph-type image using a hypotochoid equation [http://mathworld.wolfram.com/Hypotrochoid.html]

I'm getting better but I have a lot to learn.  I can't take the figure out the next step.  Because I'm close to clueless, I am graciously asking for help.
This is what I have so far:

int r = 5;
int R = 30;
int d = 70;
float theta;
float rot;
int dif = R - r;

void setup () {
 size (500,500);
 background (0);
 stroke (255);
}

void draw () {
 
 theta = radians(rot);
 rot=rot+1;
 translate (width/2,height/2);
 point (dif * cos(theta) + d * cos((dif/r)*theta), dif * sin(theta) + d * sin((dif/r)*theta));
}

These are the questions I have about my code:
1) How do I create a single clean line quickly rather than a dotted line?

2) is there a way to create a spirograph shape without using the draw() function? In other words, I would like to know how to be able to animate this function as well as just creating a still picture.

Thanks in advance! I'm looking forward to seeing a solution.
Re: hypotrochoid
Reply #1 - Aug 5th, 2006, 2:30pm
 
Hi there! I've been using processing for a few days now. I'm not really that mathematically skilled to understand the spirograph-type math you're using, but it looks neat though.

You could try to use the line() function and calculate the starting & ending locations (points) for every line.

Quote:

int r = 5;
int R = 30;
int d = 70;
float theta = 0;
float rot;
int dif = R - r;
float x1, y1, x2, y2;

void setup () {  
 size (500,500);
 background (0);
 stroke (255);
}

void draw () {
 x1 = dif * cos(theta) + d * cos((dif/r)*theta);
 y1 = dif * sin(theta) + d * sin((dif/r)*theta);
 rot++;
 theta = radians(rot);
 x2 = dif * cos(theta) + d * cos((dif/r)*theta);
 y2 = dif * sin(theta) + d * sin((dif/r)*theta);  
 translate(width/2,height/2);  
 line(x1,y1,x2,y2);
}
Page Index Toggle Pages: 1