|
Author |
Topic: translate() in tiling (Read 285 times) |
|
kevinP
|
translate() in tiling
« on: Feb 22nd, 2004, 11:51pm » |
|
Why does this not tile my rect? translate() has an accumulative effect, so it seems that I should be shifting the matrix 5 times in the y axis for every one time in the x axis, but instead I just get the y axis. Code: void setup() { size(640, 480); float x = ((float)width/500) / 5; scale(x); // draw the 1st pair rect(0, 0, 150, 150); rect(15, 15, 470, 345); for(int i = 0; i < 5; i++) { translate(500, 0); rect(0, 0, 150, 150); for(int j = 0; j < 5; j++) { translate(0, 375); rect(15, 15, 470, 345); } } } |
|
|
« Last Edit: Feb 22nd, 2004, 11:51pm by kevinP » |
|
Kevin Pfeiffer
|
|
|
TomC_ Guest
|
Re: translate() in tiling
« Reply #1 on: Feb 23rd, 2004, 12:06am » |
|
What you're doing there will go... Code: scale rectangle rectangle 5 times { move 500 right rectangle 5 times { move 375 down rectangle } } |
| Notice that you're never moving up again. Each translate is cumulative, you're correct about that, but that means that after your first column your origin is at (500, 1875). Try using push and pop to store/restore the current position. I think the following code does what you were trying to do (but I may have missed the point of the little rectangles?). Code: void setup() { size(640, 480); float x = ((float)width/500) / 5; scale(x); for(int i = 0; i < 5; i++) { push(); for(int j = 0; j < 5; j++) { rect(15, 15, 470, 345); translate(0, 375); } pop(); translate(500, 0); } } |
|
|
|
|
|
TomC_ Guest
|
Re: translate() in tiling
« Reply #2 on: Feb 23rd, 2004, 12:09am » |
|
Should have said... Try changing your scale factor to see what you were actually drawing. e.g. float x = ((float)width/500) / 30;
|
|
|
|
kevinP
|
Re: translate() in tiling
« Reply #3 on: Feb 23rd, 2004, 3:17am » |
|
Hi Tom, Yeah, I see now (operator error). Thanks for the tips. I actually had already figured out a simple version using push/pop, but thought that I'd try it without. But I forgot that you eventually have to do a "carriage return".
|
Kevin Pfeiffer
|
|
|
|