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.
IndexProgramming Questions & HelpPrograms › Changing boxes along a curve to tails on a curve
Page Index Toggle Pages: 1
Changing boxes along a curve to tails on a curve? (Read 383 times)
Changing boxes along a curve to tails on a curve?
May 29th, 2009, 5:26am
 

I want to change these boxes along a curve (CODE A) to tails (CODE B) so it looks like hair? I cannot make it work so have copied both codes separately below. Any code help would be very appreciated. Thanks Jane

//CODE A - Example 17.7 Boxes along curve Shiffman

float r = 100;//boxes
float w = 100;//boxes
float h = 40;//boxes

void setup(){
size(320,320);
smooth();
}

void draw (){
background(255);
translate(width/2,height/2);
noFill();
stroke(0);
ellipse(0,0,r*2,r*2);

//10 boxes on curve
int totalBoxes =10;
float arclength =0;
//for every box
for (int i=0; i< totalBoxes; i++){
arclength += w/2;
float theta = arclength/2;

pushMatrix();
translate(r*cos(theta), r*sin(theta));
rotate(theta);

fill(0,100);
rectMode(CENTER);
rect(0,0,w,h);
popMatrix();
arclength += w/2;
}
}

//CODE B - Tails - P297 Blue Processing book - Reas
float inc = 0.0;
void setup() {
size(100, 100);
stroke(255, 204);
smooth();
}
void draw() {
background(0);
inc += 0.01;
float angle = sin(inc)/10.0 + sin(inc*1.2)/20.0;
tail(18, 9, angle/1.3);
tail(33, 12, angle);
tail(44, 10, angle/1.3);
tail(62, 5, angle);
tail(88, 7, angle*2);
}
void tail(int x, int units, float angle) {
pushMatrix();
translate(x, 100);
for (int i = units; i > 0; i--) {
strokeWeight(i);
line(0, 0, 0, -8);
translate(0, -8);
rotate(angle);
}
popMatrix();
}

Page Index Toggle Pages: 1