How can I change the size of this composition to a 9x9?

edited November 2016 in Questions about Code

I've tried changing the size code but then the composition was not centered so I tried changing the number of what i is greater than but it did not work. I'm just lost right now

PFont fFont;

void setup() {
  size(800,800);

  background(255, 255, 255);


  translate(400,400);
  fFont = createFont("BodoniOrnamentsITCTT", 48);
  textFont(fFont, 290);

  for(int i=0;i<800;i=i+100) {

    for(int j=0;j<800;j=j+100){

      for(int k=0;k<6; k=k+1){

        fill(80,214,179,50);

       pushMatrix();
       textAlign(CENTER);
       rotate(PI*k/3);
       text("*", i, j);

       popMatrix();
      }
    }
  }
}

Answers

  • edited November 2016 Answer ✓

    I tried changing the number of what i is greater

    You were correct; that is the way to do it. If I understand what you are trying to do (and I'm not sure) it may not have been working because of the way you were using rotate.

    1. For clarity, make your loops work by checkerboard squares (1,2,3) not pixels (100,200,300).
    2. If you want to rotate something in-place, don't rotating then drawing at (x,y) -- you should instead translate to (x,y), there then rotate, then draw at (0,0).

    int k;
    int cols = 9;
    int rows = 9;
    
    void setup() {
       size(800,800);
       // PFont temporarily removed to make sketch work for anyone
       textAlign(CENTER, CENTER);
       textSize(36);
       fill(80,214,179,50);
       noLoop();
    }
    void draw(){
       background(128, 128, 128);
    
       for(int i=0;i<cols;i=i+1) {
          for(int j=0;j<rows;j=j+1){
             k=k+1;
             pushMatrix();
             translate(i*40,j*40);
             text("•", 0, 0); // temp check if rotation is aligned
             rotate(PI*(k%6)/3);
             text("*", 0, 0);
             popMatrix();
          }
       }
    }
    
  • hi, so when I use this code it tells me that "cols" can not be resolved

  • wait just kidding translate(i40, j40); cant be resolved to a variable

  • that's because the code isn't formatted for the forum... it's taken the * between i and 40 and j and 40 as markup. see how those are italicised?

    jeremy's code reposted:

    int k;
    int cols = 9;
    int rows = 9;
    
    void setup() {
       size(800,800);
       // PFont temporarily removed to make sketch work for anyone
       textAlign(CENTER, CENTER);
       textSize(36);
       fill(80,214,179,50);
       noLoop();
    }
    void draw(){
       background(128, 128, 128);
    
       for (int i = 0; i < cols; i = i + 1) {
          for(int j = 0; j < rows; j = j + 1){
             k = k + 1;
             pushMatrix();
             translate(i * 40, j * 40);
             text("•", 0, 0); // temp check if rotation is aligned
             rotate(PI * (k % 6) / 3);
             text("*", 0, 0);
             popMatrix();
          }
       }
    }
    

    (spaces would also stop that, and make things more readable)

  • ahhh thank you

  • Sorry about that formatting blip. I indented the code block, but it looks like having it after a bullet list messed something up. Should have refreshed the page after posting to confirm.

  • edited November 2016 Answer ✓

    @Franz654 --To understand why your original rotate-then-translate error was giving you crazy results, see the Processing Tutorial 2D Transformations -- in particular look at the "Rotation" section starting with "Hey, what happened?" ....

Sign In or Register to comment.