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 & HelpSyntax Questions › iteratively drawing a triangle strip...
Page Index Toggle Pages: 1
iteratively drawing a triangle strip... (Read 452 times)
iteratively drawing a triangle strip...
Aug 1st, 2009, 10:42am
 
hi all,

I'm confused about how to draw a triangle strip with a FOR structure.. new to all this, so sorry about my novice-esque question. here goes my logic - what am I not understanding properly? the triangles draw all weird...

Quote:
// ok global triangle strip positioning time

int initxpos=400;
int initypos=100;

void setup() {

size(800, 800);
background( 25, 25, 25);
noLoop();
}

void draw() {

noFill();
strokeWeight(1);
stroke(200, 200, 200);

// ok let's try to draw a triangle strip in the first place... 
//let's find out the draw order..

strokeWeight(5);
stroke(152, 49, 49); //red
point(75, 30);

stroke(83, 152, 49); //green
point(10, 20);

stroke(50, 49, 152); //blueish
point(75, 50);

stroke(201, 18, 162); //pink
point(20, 60);

stroke(46, 175, 165); //cyan
point(90, 70);

stroke(251, 255, 26); //yellow
point(35, 85);

strokeWeight(1);
stroke(200, 200, 200);

beginShape(TRIANGLE_STRIP);
vertex(75, 30);
vertex(10, 20);
vertex(75, 50);
vertex(20, 60);
vertex(90, 70);
vertex(35, 85);


// now can we "variablize" that logic?? c'mon pls.. OK WORKS


int xinit=400;
int yinit=100;

//
//int triwidth = 200;
//int yheight = 100;
//
//stroke(35, 200, 50);
//
//beginShape(TRIANGLE_STRIP);
//vertex(xinit, yinit);
//vertex(xinit - triwidth, yinit);
//vertex(xinit, yinit + yheight);
//vertex(xinit - triwidth, yinit + yheight);


// now iterate that structure! doesn't wpork... why?

int triwidth = 200;

for (int yheight=100; yheight<800; yheight += 100) {

beginShape(TRIANGLE_STRIP);
vertex(xinit, yinit); //400, 100
vertex(xinit - triwidth, yinit); //200, 100
vertex(xinit, yinit + yheight); //400, 200
vertex(xinit - triwidth, yinit + yheight);//200, 200


}


}

Page Index Toggle Pages: 1