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 › Repetition of Forms
Page Index Toggle Pages: 1
Repetition of Forms (Read 657 times)
Repetition of Forms
Oct 5th, 2007, 11:26pm
 
hi,

i'm very very new to Processing, and well-known here to ask super dumb qiestions...anyway...

I have a little project on silkscreen printing.
I just want to have some variations of repetitive forms to print on films then do a physical composition.

But as my coding technique is for now very limited,
I just do some stuff very boring...like this,

Quote:


size (500, 500);
background(255);

for (int i=0; i<20; i++){
 smooth();
 strokeWeight(0.3);


noFill();
rect (random(width), random(width), random(width), random(width));
}





can anyone show me some more interesting examples on this type of generating process??

I don't need to have ultra-complex state-of-art compositions, but I just want to have a simple forms which repeats itself, but more "algorithmically" interesting...

sorry if my question is not so clear,
'hope you guys can see what I mean...

many thanks!
Re: Repetition of Forms
Reply #1 - Oct 8th, 2007, 8:58am
 
mmm...

first of all: you can call smooth() once at the start of your program. there's no need to call it each time you want to draw something.

i won't give you any examples - you can find many good ones in the Learning section - but maybe a good advice :

try thinking of your 'simple forms' as simple objects which all have similar properties and some differences. for example, your rectangles have similar properties (4 corners, the same way to draw them, etc.) and differences (i.e. where you used random fonctions : their position on the screen, size, etc.).

so let's reshape your code to take advantage of object-oriented programming :

Code:

// all simple objects will have the same structure :
class SimpleObject {
// parameters : position (x, y) and size (s)
int x, y, s;
// constructor method
SimpleObject(int _x, int _y, int _s) {
x = _x; y = _y; s = _s;
}
// drawing method
void draw() {
pushMatrix();
translate(x, y);
rect(0, 0, s, s);
popMatrix();
}
}

size(500, 500);
background(255);
rectMode(CENTER);
smooth();
for (int i = 0; i < 20; i++) {
SimpleObject s = new SimpleObject((int)random(width-10), (int)random(height-10), 10+(int)random(10));
s.draw();
}


then, by adding parameters and changing the drawing method you can get more complex shapes. for example, try this :

Code:

// drawing method
void draw() {
pushMatrix();
translate(x, y);
rect(0, 0, s, s);
rotate(PI/4);
rect(0, 0, s, s);
popMatrix();
}


have fun!
Re: Repetition of Forms
Reply #2 - Oct 9th, 2007, 6:58pm
 
thank you, nikoony!

I didn't have the time to fully study your code, but it seems very interesting!
I'll do it tonight, line by line...

however, your code runs, but I get this following error message...it seems that it can't load an image? But with your code, I don't see any use of external image?
I've just copied your code then run in Processing without any modification.

I'm running mac osx 10.4 on PPC ibook.


2007-10-09 18:52:41.261 java[206] CFLog (21): Error loading /Library/QuickTime/LiveType.component/Contents/MacOS/LiveType:  error code 4, error number 0 (Library not loaded: /System/Library/PrivateFrameworks/LiveType.framework/Versions/A/LiveType
 Referenced from: /Library/QuickTime/LiveType.component/Contents/MacOS/LiveType
 Reason: image not found)
Page Index Toggle Pages: 1