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 › PLEASE HELP! rotating question
Page Index Toggle Pages: 1
PLEASE HELP! rotating question (Read 225 times)
PLEASE HELP! rotating question
Mar 4th, 2009, 9:55pm
 
Hi! I am playing around with processing for the first time and I'm getting stuck. I have this code that draws multiple squares from the center.

Here is what I have,

int i = 50;

void setup()
{
 size(300, 300);
 smooth();
 background(224);
 noLoop();
}

void draw()
{
  for(int i=15;i<300; i += x) {
    noFill();
    stroke(254,243,75);
    rectMode(CENTER);
    rect(150, 150, i, i);    
 }
}

Now I'm trying to repeat those same squares at a 45 degree angle and without translation. Is this possible? And how do I do it?

Any help would be greatly appreciated Smiley Thanks
Re: basic question but need help. ROTATING
Reply #1 - Mar 4th, 2009, 9:57pm
 
I just noticed that at the top of the code it is missing int x=15
Re: basic question but need help. ROTATING
Reply #2 - Mar 4th, 2009, 10:43pm
 
I'm not clear on what you mean "and without translation."

Do you mean you want to do it without using the Processing "translate()" function?

Do you mean you want sets of rotated squares where a rotated square is centered on its corresponding unrotated (or less rotated) squares?

I'm not positive what you want, but looking at your code you should wrap the for() loop that draws the squares with the following:

translate(150,150);
for(angle = 0; angle <= 45; angle += 45) {

// your for() loop goes here, except you change the rect call to "rect(0,0,i,i);"

}

Also note that you can pull the call to stroke() out of all the loops (put it up in setup()) because it is persistent to all subsequent drawing commands, until replaced by a call to stroke() with different values.
Re: basic question but need help. ROTATING
Reply #3 - Mar 10th, 2009, 2:13am
 
I am still having trouble with this so if anyone could lend a helping hand, it would be greatly appreciated.

I want to set of squares, the second set of rotated squares would be just a 45 degree rotation and centered on its corresponding unrotated squares. And I also want the two different sets to be different colours. Can this be done? And what am I doing wrong?

float x = 15;
int i = 50;  

void setup()  
{
 size(300, 300);
 smooth();
 background(224);
 noLoop();
}


void drawFirst(){  
for(int i=15;i<300; i += x) {
    noFill();
    stroke(254,243,75);
    rectMode(CENTER);
    rect(150, 150, i, i);      
 }
}

void draw(){
 translate(150,150);
 rotate(angle = 0; angle <= 45; angle += 45);
   for(int i=15;i<300; i += x) {
     noFill();
     stroke(254,243,75+x);
     rectMode(CENTER);
     rect(0, 0, i, i);    
 }
}
Re: PLEASE HELP! rotating question
Reply #4 - Mar 10th, 2009, 1:24pm
 
cloister was right (of course).
Corrected code:
Code:
float x = 15;
int i = 50;

void setup()
{
size(300, 300);
smooth();
background(224);
noFill();
rectMode(CENTER);
translate(width/2, height/2);
stroke(254, 243, 75);
drawRectangles();
rotate(QUARTER_PI); // 45°
stroke(254, 200, 175);
drawRectangles();
}


void drawRectangles() {
for(int i = 15; i < 300; i += x) {
rect(0, 0, i, i);
}
}
Re: PLEASE HELP! rotating question
Reply #5 - Mar 10th, 2009, 1:56pm
 
Thank you! Thank you! Thank you! Thank you! Thank you!

This programming stuff has been so difficult for me to grasp Sad
I really appreciate your help!!
Page Index Toggle Pages: 1