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 › Drawing on a periodic 'tiled' canvas
Page Index Toggle Pages: 1
Drawing on a periodic 'tiled' canvas? (Read 342 times)
Drawing on a periodic 'tiled' canvas?
Oct 28th, 2009, 9:20am
 
Is there any way to get processing to act as if the canvas is periodic?

For instance make it so  line(-20,10,20,10) on a canvas of width 400 would draw a line from x 0  to x 20 and a line from x 380 to x 399? Also, having filters() use the pixels on the other side of the canvas as their nieghbors would be important.

Obvioulsy I can do some of it myself using modulo, but tha requires re-implementing everything I want to use.
Re: Drawing on a periodic 'tiled' canvas?
Reply #1 - Oct 28th, 2009, 10:06am
 
Quote:
Is there any way to get processing to act as if the canvas is periodic?

No. Unless you change Processing itself...
Re: Drawing on a periodic 'tiled' canvas?
Reply #2 - Oct 28th, 2009, 2:16pm
 
Not in your example when you draw one object, like PhiLho said.

But it depends on what you wanna do. If you want moving objects its pretty simple. Look at the stayincanvas part of the code


Code:
Wanderer[] wanderer = new Wanderer[11];

void setup(){
size(200, 200);
background(50);
fill(200);
noStroke();

for (int i=0; i<wanderer.length; i++) {
wanderer[i] = new Wanderer(random(width), random(height));
}
}

void draw(){
fill(0,40);
rect(0,0,width,height);

for (int i=0; i<wanderer.length; i++) {
wanderer[i].stayInsideCanvas();
wanderer[i].move();
}
}
class Wanderer{
float x;
float y;
float wander_theta;
float wander_radius;
float max_wander_offset = 0.3;
float max_wander_radius = 3.5;

Wanderer(float _x, float _y){
x = _x;
y = _y;

wander_theta = random(TWO_PI);
wander_radius = random(max_wander_radius);
}

void stayInsideCanvas() {
if(x<0)x=width;
if(y<0)y=height;
if(x>width)x=0;
if(y>height)y=0;
}

void move(){
float wander_offset = random(-max_wander_offset, max_wander_offset);
wander_theta += wander_offset;
x += cos(wander_theta);
y += sin(wander_theta);
fill(255);
ellipse(x, y, 2, 2);
}

}
Page Index Toggle Pages: 1