Getting 'shadows' from shapes even though noStroke() is off - something to do with floats or ints?

edited February 2015 in Questions about Code

I'm sure this is a known problem but I can't seem to find a solution for it. I currently have lines appearing where shapes join even though there shouldn't really be anything. They are very fine lines so It's not actually a stroke, more of an artifact.

here's an image of what I'm referring to , you can see the lines in the center of the shapes there as they are made up of two adjacent arcs. Weirdly its not happening to one of them, I'm not sure why this would be.

Also it happens when the arcs open out (as it's caused by a background coloured arc overlapping) here's an image of that. Again, it's only happening to two of them, I don't really get it.

Here's the code if anyone wants to run it, it's pretty messy (sorry about that!). But the images might be enough for a diagnoses.

Thank you

void setup() {
  size(600, 600);
  noStroke();
  // noSmooth();
}
float t;
color a = #FA003F;
int frames = 600;
float radius = 70;
int size = 150;
color back = #2D3339;
int num = 3;
float ss = ((2 * PI * size) / num) * 0.9;
void draw() {
  t = (frameCount%frames)/(float)frames;
  background(back);
  translate((int)width/2, (int)height/2);
  if ( t < 0.5) {

    float tt = map(t, 0, 0.5, 0, 1);
    // FIRST QUARTER
    if (tt < 0.5) {
      for (int i = 0; i < num; i++) {
        pushMatrix();
        float r = map(tt, 0, 0.5, ss, 0);

        float move = map(i, 0, num, 0, TWO_PI);    
        rotate(move);
        translate(size, 0);
        rotate(PI/2);
        arc(0, 0, ss, r, 0, PI);
        arc(0, 0, ss, ss, PI, TWO_PI); //doesn't move
        popMatrix();
      }
    } 
    // SECOND QUARTER
    else {

      for (int i = 0; i < num; i++) {
        pushMatrix();
        float move = map(i, 0, num, 0, TWO_PI);    
        rotate(move);
        translate(size, 0);
        rotate(PI/2);
        float r = map(tt, 0.5, 1, 0, ss);
        arc(0, 0, ss, ss, PI, TWO_PI); // doesn't move
        fill(back);
        arc(0, 0, ss, r, PI, TWO_PI);
        fill(255);
        popMatrix();
      }
    }
  }
  // HALF TWO
  else {
    float tt = map(t, 0.5, 1, 0, 1);
    if (tt < 0.5) {
      for (int i = 0; i<num; i++) {
        pushMatrix();
        float move = map(i, 0, num, 0, TWO_PI);    
        rotate(move);

        translate(size, 0);
        rotate(PI/2);
        float r = map(tt, 0, 0.5, ss, 0);
        fill(255);
        arc(0, 0, ss, ss, PI, TWO_PI);
        fill(back);
        arc(0, 0, ss, r, PI, TWO_PI);
        popMatrix();
      }
    } else {
      for (int i=0; i<num; i++) {
        pushMatrix();
        float move = map(i, 0, num, 0, TWO_PI);    
        rotate(move);
        translate(size,0);
        rotate(PI/2);
        float r = map(tt, 0.5, 1, 0, ss);
        fill(255);
        arc(0, 0, ss, ss, PI, TWO_PI);
        arc(0, 0, ss, r, 0, PI);
        fill(255);
        popMatrix();
      }
    }
  }
}

void a() {
  fill(a);
}

Comments

  • It is probably caused by anti-aliasing: lines get toned down pixels to smooth them.
    Turning on the noSmooth() call you commented out solves the problem (but we get aliased edges, of course).

  • hmm cheers Phil, I don't see these lines on anyone elses drawings though?

  • Try using the P2D renderer rather than the default JAVA2D

  • Cheers Quark I'll have a look at that, is this something that you've seen before on your system or not?

  • I have noticed similar problems when combining simple shapes to create larger more complex shapes in that the joins show up.

  • fair, that's annoying. I've seen some people make far more complex things than this, perhaps they vanish when the things are exported or something. thanks

  • P2D uses OpenGL for its rendering whereas the default renderer uses Java's its own system (Graphics2D).

    Judt try replacing thr call to size with

    size (600, 600, P2D);

    and see if it makes a difference.

  • will do later, cheers

  • Just tried it - yeah that works Quark... touch slower loading, but no lines :)

Sign In or Register to comment.