p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

ellipseMode(CORNERS) with circle() does not draw a circle

Open dipamsen opened this issue 4 years ago • 6 comments
trafficstars

Most appropriate sub-area of p5.js?

  • [ ] Accessibility (Web Accessibility)
  • [ ] Build tools and processes
  • [ ] Color
  • [x] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Friendly error system
  • [ ] Image
  • [ ] IO (Input/Output)
  • [ ] Localization
  • [ ] Math
  • [ ] Unit Testing
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Details about the bug:

  • p5.js version:
  • Web browser and version:
  • Operating System:

Example Code

function setup() {
  createCanvas(100, 100);
  ellipseMode(CORNERS);
}

function draw() {
  background(220);
  circle(10, 30, 70);
}

Output

image

Reason

The p5.js circle() function passes on the arguments to ellipse(), by specifying the third arg twice.

So, circle(x, y, d) becomes ellipse(x, y, d, d)

With ellipseMode(CORNERS), the corners of the ellipse are specified as coords.

image

dipamsen avatar Jun 01 '21 15:06 dipamsen

Good find. I wonder in this case should circle simply bypass ellipseMode or does it need to calculate the corners manually? What happens when ellipseMode is CORNERS but only passed three arguments?

limzykenneth avatar Jun 03 '21 11:06 limzykenneth

Note that the Java version of Processing behaves in the same way - and that the docs for the Java version, doesn't explicitly describe what is supposed to happen.

soegaard avatar Jun 07 '21 17:06 soegaard

Parity with Processing is not a goal here so we can decide here what the behaviour should be.

limzykenneth avatar Jun 13 '21 13:06 limzykenneth

Hi! @limzykenneth Using ellipse(10, 30, 70) i have the same result as circle(10, 30, 70). Also, yes as @dipamsen mentioned, it looks that the coordinates are used as width/height, and the diameter as the circle coordinates.

function setup() {
  createCanvas(100, 100);
  ellipseMode(CORNERS);
}

function draw() {
  background(220);
  circle(50, 50, 0); //drawing a circle of 50 by 50 with diameter=0
}

imagen

I got the same behaviour using Processing. Honestly, i feel that this is not very intuitive, and I am interested on working on this, if there is a chance :)

bryanidem avatar Jun 18 '21 15:06 bryanidem

Well, there's no bug here, it works as intended. It is just not intuitive/useful the way it currently works.

In @BryanMed's example, circle(50, 50, 0) turns into ellipse(50, 50, 0, 0) which translates as "draw a ellipse with corner coords (50, 50) and (0, 0)"

Would a way to fix this be to ignore ellipseMode(CORNERS) just for circle()?

dipamsen avatar Jun 21 '21 15:06 dipamsen

Would a way to fix this be to ignore ellipseMode(CORNERS) just for circle()?

If you want circle() to respond to CORNERS you could do something like this: Taking the third parameter in circle(a,b,c) as the x coordinate of the second corner calculate the fourth parameter to pass ellipse() so that your corners describe a square.

circle(x1, y, x2) should become ellipse(x1, y, x2, y + x2 - x1).

circle(10, 30, 70), for instance, would become ellipse(10, 30, 70, 90), staying nice and circley.

This is unintuitive, but if you're going to stay circular then either x2 or y2 has to be a dependent variable.

Ignoring ellipseMode(CORNERS) just for circle() might be a cleaner solution.

awelles avatar Dec 07 '21 12:12 awelles