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 › Diagonal Striped Rect
Page Index Toggle Pages: 1
Diagonal Striped Rect (Read 797 times)
Diagonal Striped Rect
Mar 4th, 2007, 10:46pm
 
I'd like to do something like fjen's diagonal striped rect but with polygons.

http://snippet.seltar.org/index.php?pid=3&sid=15

I've gotten entertaining results out of it but not the diagonal polygon bands I was hoping for. This effort is to generate a pdf file for a background to a game. Here's how far I've gotten:

Code:

void setup ()
{
size( 200, 200 );
}

void draw ()
{
background(200);

int x = 20, y=20, w=width-40, h=height-40;

//stroke( 0xFFFF9900 ); noFill();

for ( int ss = 15; ss < w+h ; ss += 15 )
{
//stroke( ss > h ? (ss > w ? 0xFF00FF00 : 0xFFFF0000) : 0 );
/* line( ss <= h ? x : x-h+ss,
ss <= h ? y+ss : y+h,
ss <= w ? x+ss : x+w,
ss <= w ? y : y-w+ss
);*/
beginShape();
vertex(ss <= h ? x : x-h+ss, ss <= h ? y+ss : y+h);
vertex(ss <= w ? x+ss : x+w, ss <= w ? y : y-w+ss);
vertex(ss + 15 <= w ? x+ss+15 : x+w, ss <= w ? y : y-w+ss+15);
vertex(ss + 15 <= h ? x : x-h+ss + 15, ss <= h ? y+ss+15 : y+h);
endShape();

}
}


I haven't got a clue on how to change this code to produce thick diagonal stripes (strokeWeight not an option). Can anyone help me please?
Re: Diagonal Striped Rect
Reply #1 - Mar 4th, 2007, 11:42pm
 
sorry, i feel bad for the code ( ? .. : .. )
hope this helps.

Code:

void setup ()
{
size( 200, 100 );
}

int step = 0;

void draw ()
{
background(200);

int x = 20, y=20, w=width-40, h=height-40;

for ( int ss = step; ss < w+h-15 ; ss += 30 )
{
beginShape();
// left
vertex(ss <= h ? x : x-h+ss, ss <= h ? y+ss : y+h);
// top
vertex(ss <= w ? x+ss : x+w, ss <= w ? y : y-w+ss);
// corner top right
if ( ss <= w && ss + 15 > w )
vertex( x+w, y );
// top
vertex(ss + 15 <= w ? x+ss+15 : x+w, ss + 15 <= w ? y : y-w+ss+15);
// left
vertex(ss + 15 <= h ? x : x-h+ss + 15, ss + 15 <= h ? y+ss+15 : y+h);
// corner lower left
if ( ss <= h && ss + 15 > h )
vertex( x, y+h );
endShape(CLOSE);
}
step += 1;
step %= 30;
}


F
Re: Diagonal Striped Rect
Reply #2 - Mar 4th, 2007, 11:58pm
 
Thanks a lot. That's pretty damned helpful.

I've added your code as a comment back on snippets.

http://snippet.seltar.org/index.php?pid=3&sid=15
Page Index Toggle Pages: 1