How can I change the circles to triangles?

edited October 2016 in Questions about Code

I'm fairly new to processing and I can't figure out how to change the circles to triangles in this code

    float spacing, x, y, diameter;
    import processing.pdf.*;
    boolean saveOneFrame = false;


    void setup(){
      size(720, 720);
      spacing=width/6;
      frameRate(2);

    }

    void draw(){
       if(saveOneFrame == true){
        beginRecord(PDF, "Dots-####.pdf");
      }

      background(255);
      fill(0);
      noStroke();
      translate(width/6, height/6);



      for(int dotX=0; dotX<5; dotX ++){
        for(int dotY=0; dotY<5; dotY ++){
        x= dotX*spacing;
        y= dotY*spacing;
           //diameter=60;
            //diameter=60+dotX*20;
             //diameter= 60+dotY*20;
           //diameter= 20+dotX*20 +dotY*20;
           diameter= random(20+60);
           //  diameter= 60+dist(x+spacing, y+spacing, mouseX, mouseY)/4;
           //diameter= 20-dist(x+spacing, y+spacing, mouseX, mouseY)/6;

           //noLoop();
      ellipse(x, y, diameter, diameter);

      }
      }
      if(saveOneFrame == true){
        endRecord();
        saveOneFrame = false;
      }
    }




    void mousePressed(){
      saveOneFrame = true;
    }

Answers

  • Please format your code: click in edit post, select your code and hit ctrl+o. Then save it.

  • Answer ✓
    float spacing, x, y, diameter; 
    //import processing.pdf.*; 
    boolean saveOneFrame = false;
    
    void setup() { 
      size(720, 720); 
      spacing=width/6; 
      frameRate(2);
    }
    
    void draw() { 
      //if (saveOneFrame == true) { 
      //  beginRecord(PDF, "Dots-####.pdf");
      //}
    
      background(255); 
      fill(0); 
      noStroke(); 
      translate(width/6, height/6);
    
      for (int dotX=0; dotX<5; dotX ++) { 
        for (int dotY=0; dotY<5; dotY ++) { 
          x= dotX * spacing; 
          y= dotY * spacing; 
          //diameter=60; 
          //diameter=60+dotX20; 
          //diameter= 60+dotY20; 
          //diameter= 20+dotX20 +dotY20; 
          diameter= random(20+60); 
          // diameter= 60+dist(x+spacing, y+spacing, mouseX, mouseY)/4; 
          //diameter= 20-dist(x+spacing, y+spacing, mouseX, mouseY)/6;
    
    
          //noLoop();
    
    
          //ellipse(x, y, diameter, diameter);
    
          pushMatrix();
          translate(x, y);
          triangle(0, -diameter, -diameter, diameter, diameter, diameter );
          popMatrix();
    
        }
      } 
      //if (saveOneFrame == true) { 
      //  endRecord(); 
      //  saveOneFrame = false;
      //}
    }
    
    //void mousePressed() { 
    //  saveOneFrame = true;
    //}
    
Sign In or Register to comment.