How can I change this to lines?

edited October 2016 in Questions about Code

I'm in a processing class and I'm terrible at it.

    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;
    }
Tagged:

Answers

  • By "change this to lines" do you mean that you want to change this:

    ellipse(x, y, diameter, diameter);
    

    to drawing a line, e.g. using the line() function?

  • https://forum.processing.org/two/discussion/18509/how-can-i-change-the-circles-to-triangles

    First we changed from circles to triangles. Now we're changing from circles to lines?

    Oh dear. See, when I gave you an answer before, and you accepted it, I assumed that you understood that by CHANGING THE CODE I had also CHANGED WHAT THE SKETCH DID.

    The are like, related.

    So if you want to CHANGE WHAT THE SKETCH DOES, that means that you are going to have to CHANGE SOME CODE.

    What code do you change? Well, you first need to understand what your code does. Hopefully you can determine which line of code it is that draws the circles. HINT: It's the line of code I changed before to draw triangles instead.

    Once you have found the code that draws the circles, change it to draw lines.

    Seriously now, UNDERSTAND the code. That you have failed to do this so far is obviously the cause for why you're doing so terrible at it.

    Then try to make the change yourself. Post the code of your attempt for more help.

  • @Franz654 --

    Try reading the code -- slowly -- and following what is happening where. Then you will know how to change it.

    1. in setup(), which sets everything up...
    2. ...frameRate(2) means that draw will get called twice a second
    3. now draw() is being called (twice a second) for as long as the sketch runs
    4. draw has two nested loops, like looping through the rows of a checkerboard (outer loop) and, on each row, looping through each square (inner loop).
    5. In them, some math makes the numbers x, y, and diameter keep changing. Then an ellipse is drawn. You could use those numbers to draw something else! Those things are listed in the Processing Reference.
    6. if your mouse is pressed at any time (mousePressed()) it sets a variable saveOnFrame to true. If when draw happens (twice a second!) it sees that variable is true, it starts writing a PDF at the beginning, then saves the PDF at the end. You could instead make your mouse do something else (or additionally do something else).

    Programming isn't like memorizing a big long list of words -- most of it is about learning grammar. Once you begin to learn how things work in general, you can find where unfamiliar words are, what they are, learn new words, and substitute old things for new things to make changes. Check out the introductory tutorials.

Sign In or Register to comment.