Action Won't Stop

I have a simple code drawing multiple shapes with various colors, sizes and thicknesses. Oddly, a fill line with one color combination, or a translation line with one set of points, is effecting other colors and translation points. For example, at the beginning of my code, I have a white circle, and towards the end have a red line. Yet for some reason, the white head is outlined in red. Is there a way I can prevent that? And is there a way I can "section" off each shape so that their characteristics are determined individualy rather than by the other aspects from different shapes.

Thanks, G

Tagged:

Answers

  • You can enclose your drawings between calls to pushStyle() and popStyle(), but really you should be setting the fill and stroke colors correctly before drawing each of your shapes. The settings will persist until you change them!

  • My code (that you need to see) is like this-

    void draw() { background(0, 0, 0); fill(255, 255, 255); ellipse(250, 100, 75, 75);

    strokeWeight(3); stroke(255, 255, 255); line(250, 136, 250, 300);

    strokeWeight(3); translate(250, 300); stroke(255, 0, 0); rotate(radians(angle + 180)); line(0, 0, 0, 100); }

    Yet the ellipse is outlined in red

  • edited April 2015
    void draw() { // 2) ... but the next time draw is called...
      background(0, 0, 0);
      fill(255, 255, 255);
      // stroke(0); // 3) ... there's nothing changing it back to the default...
      ellipse(250, 100, 75, 75); // 4) ...so it will show up in red!
      strokeWeight(3); // 6) ... up here!
      stroke(255, 255, 255);
      line(250, 136, 250, 300);
      translate(250, 300);
      rotate(radians(angle + 180));
      strokeWeight(3); // 5) And this setting was already set...
      stroke(255, 0, 0); // 1) You set the stroke to red here...
      line(0, 0, 0, 100);
    }
    
  • TfGuy44, There is a space between line 7 and 8. And the next shape also includes a translation however when it translates, it just adds to the previous translation. How do I fix that?

  • A space? So what? White space doesn't matter.

    I think you're confused about how fill/stroke colors and translations work.

    Ok, imagine you are going to paint a picture. Your paintbrush is magic, because it draws shapes. You say, "Hey paintbrush, I want the next shape I draw to be filled with white and have a blue outline."

    fill(255,255,255); stroke(0,0,255);
    

    Now you draw a shape. "Hey paintbrush, draw a circle."

    ellipse(20,20,40,40);
    

    Now you say "Hey paintbrush, I want the next shape to be filled with red!"

    fill(255,0,0);
    

    "Another circle!"

    ellipse(60,20,40,40);
    

    Whoa, wait, what? Why is that circle ALSO outlined in blue? It's because the paintbrush remembers the last colors you told it to use. (Even between finishing painting one picture (the end of draw()) and starting the next (draw() running again).

    size(220,220);
    background(0);
    fill(255, 255, 255); 
    stroke(0, 0, 255);
    ellipse(20, 20, 40, 40);
    fill(255, 0, 0);
    ellipse(60, 20, 40, 40);
    
  • What you need to do is make sure that, before you draw any shape, you set both the fill color and the stroke color, or disable them with noStroke() and noFill().

    As for translations, they add together too.

    size(220,220);
    background(0);
    
    fill(255, 255, 255); 
    stroke(0, 0, 255);
    
    translate(20,20);
    ellipse(0, 0, 40, 40);
    
    translate(40,100);
    ellipse(0, 0, 40, 40);
    
    translate(40,40);
    ellipse(0, 0, 40, 40);
    
  • No worries I found the problem, needed pushMatrix() and popMatrix()

Sign In or Register to comment.