mardi 22 mars 2011

First Lissajou coding examples

To get a taste of the Lissajou fun, we do a few simple coding examples.
First start with the circle, from two old friends from maths, the sine and the cosine:


float t = 0;

void setup() {
  size(400, 400);
 stroke(125);
}

void draw() {
 
  while (t<7000){

  int x = int(200 + 150 * sin ( t/100 ) );
  int y = int(200 + 150 * cos ( t/100 ) );

  ellipse(x,y, 2, 2); //plotter point
 
  t++;// counter
  }
}


What you get is a nice circle.

Then do this: adding another sin()...change this line starting with "int x =" into 

int x = int(200 + 150 * sin ( t/100 ) * sin ( t/99 ) );


and you get a nice knotlike figure, you can very the density with the 99 parameter.

(hm some problems with the images?)






Fun2.
Start with a double knot, drawing parallel lines between these points, nice figure?
(In fact where you seem to perceive lines, there are rather big jumps in connections, start playing with the sketch!)


void draw() {

while (t<700){

int x1 = int(100 + 100 * sin ( t/10 ) * sin ( t/15 ) );
int y1 = int(200 + 140 * cos ( t/10 ) );
int x2 = int(300 + 100 * sin ( t/10 ) * sin ( t/15 ) );
int y2 = int(200 + 140 * cos ( t/10 ) );
line(x1,y1, x2, y2); //plotter line 
t+=1;// counter }


Then fiddle with the parameters in one knot:

void draw() {

while (t<700){

int x1 = int(100 + 100 * sin ( t/100 ) * sin ( t/15 ) );
int y1 = int(200 + 140 * cos ( t/100 ) );
int x2 = int(300 + 100 * sin ( t/10 ) * sin ( t/15 ) );
int y2 = int(200 + 140 * cos ( t/10 ) ); 
line(x1,y1, x2, y2); //plotter line 
t+=1;// counter



sometimes you get chaos, sometimes you get beautiful order.

You can plot all the results, but then you burn a lot of pens. First exploring the possibilities of certain formula's on screen seems to be a good idea. We can vary the parameters using the mouse position, mouseX, mouseY.

Looking at the different drawings on screen we can choose some we like, and discard others.

You can download the sketch here:
plotterLibExample.pde

Aucun commentaire:

Enregistrer un commentaire