# PGraphics + noSmooth() + alpha = drawing artifacts

**URL:** https://discourse.processing.org/t/pgraphics-nosmooth-alpha-drawing-artifacts/7892
**Category:** Coding Questions
**Created:** [January 28, 2019, 12:44am UTC](https://discourse.processing.org/t/pgraphics-nosmooth-alpha-drawing-artifacts/7892 "2019-01-28T00:44:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 28, 2019, 12:44am UTC](https://discourse.processing.org/t/pgraphics-nosmooth-alpha-drawing-artifacts/7892/1 "2019-01-28T00:44:31Z")

</div>

**Note:** I also asked this question on Stack Overflow [here](https://stackoverflow.com/q/54408259/873165).

I have this sample code:

```auto
PGraphics pg;

void setup() {
  size(400, 500);
  pg = createGraphics(width, height);

  pg.noSmooth();
  pg.beginDraw();
  pg.background(0, 0, 255);
  pg.endDraw();
}

void draw() {

  if (mousePressed) {
    pg.beginDraw();
    pg.stroke(255, 254);
    pg.point(mouseX, mouseY);
    pg.endDraw();
  }

  image(pg, 0, 0, width, height);
}

```

I would expect this code to show a point wherever the user presses the mouse. Instead, I am only able to see points in a couple rectangular areas:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0f204dc6a073290d7ed442fef7eec33881aa4de8.png)

If I remove the call to `pg.noSmooth()` or if I remove the alpha value in the `pg.stroke()` call, then it works fine:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8ec82c53e19278b4aa86b1652fdcd4e2d9f42057.png)

If I replace the `pg.point()` call with `pg.ellipse()` or `pg.rect()` then it also works fine.

It seems like the combination of using a `PGraphics`, the `noSmooth()` function, the `point()` function, and an alpha value results in this buggy behavior. I’ve tried in Processing 3.3 and Processing 3.5.2 and I see the same behavior in both.

Am I missing something obvious?

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 28, 2019, 8:35pm UTC](https://discourse.processing.org/t/pgraphics-nosmooth-alpha-drawing-artifacts/7892/2 "2019-01-28T20:35:09Z")

</div>

After doing a bit of testing I’m starting to think it just might be a bug with processing’s aliasing/anti-aliasing. Maybe there’s a bug where it thinks the point is the ‘incorrect’ size and doesn’t need to be drawn?

I also noticed that using

**_pg.set(mouseX,mouseY,color(255))_**

works for whatever reason

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 28, 2019, 10:48pm UTC](https://discourse.processing.org/t/pgraphics-nosmooth-alpha-drawing-artifacts/7892/3 "2019-01-28T22:48:07Z")

</div>

Yeah, the `pg.set()` function works okay, even if it contains transparency:

```auto
color c = color(255, 255, 255, 64);
pg.set(mouseX, mouseY, c);

```

I’ve filed a bug on GitHub about this [here](https://github.com/processing/processing/issues/5777).

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 29, 2019, 6:06pm UTC](https://discourse.processing.org/t/pgraphics-nosmooth-alpha-drawing-artifacts/7892/4 "2019-01-29T18:06:53Z")

</div>

[This answer](https://stackoverflow.com/a/54420174/873165) from [George Profenza](https://stackoverflow.com/users/89766/george-profenza) provides more info.

Apparently the Java2D renderer draws a point as a line [here](https://github.com/processing/processing/blob/9c89b78e057f2898bb39b5768d06120369110841/core/src/processing/awt/PGraphicsJava2D.java#L1190):

```auto
static final float EPSILON = 0.0001f;

```

```auto
public void point(float x, float y) {
    if (stroke) {
// if (strokeWeight > 1) {
      line(x, y, x + EPSILON, y + EPSILON);
// } else {
// set((int) screenX(x, y), (int) screenY(x, y), strokeColor);
// }
    }

```

We can reproduce this error by drawing our points as tiny lines:

```auto
PGraphics pg;

void setup() {
  size(400, 500);
  pg = createGraphics(width, height);
  pg.noSmooth();

  pg.beginDraw();
  pg.background(0, 0, 255);
  pg.stroke(255, 254);

  for (int y = 0; y < pg.height; y+=2) {
    for (int x = 0; x < pg.width; x+=2) {
      //pg.point(x, y);
      pointNoSmooth(pg, x, y);
    }
  }

  pg.endDraw();
}

void pointNoSmooth(PGraphics pg, float x, float y) {
  // any less than 0.75 distance between vertices 
  // and there's nothing to render with aliasing
  float epsilon = 0.01;
  pg.beginShape();
  pg.vertex(x, y);
  pg.vertex(x + epsilon, y);
  pg.endShape();
}

void draw() {
  image(pg, 0, 0, width, height);
}

```

With a small `epsilon` value, we see the same artifacts I was seeing:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6f17c27d18eb600fe8e002628b9bc78febea48ba.png)

If we increase `epsilon` to anything larger than `0.75`, then it renders correctly:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dac64fc373b83cc3b21135b3f0a264ec9655c9a7.png)

Interestingly, if we remove the alpha argument, then we don’t see any dots at all.

I’m going to update [the bug](https://github.com/processing/processing/issues/5777) with this info, but for my purposes I’m happy that I’m not doing something obviously wrong. Thanks again George!
