jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

PShape Contour (holes) not working in example #249

Closed villares closed 5 years ago

villares commented 5 years ago

This fragment from the examples "BeginEndContour" works in Java Mode but not in Python Mode (the internal quad is filled, when it should be a hole):

size(300, 300, P2D)
translate(width / 2, height / 2)
beginShape()
fill(0)
stroke(255)
strokeWeight(2)
# Exterior part of shape
vertex(-100, -100)
vertex(100, -100)
vertex(100, 100)
vertex(-100, 100)
# Interior part of shape
beginContour()
vertex(-10, -10)
vertex(10, -10)
vertex(10, 10)
vertex(-10, 10)
endContour()
# Finishing off shape
endShape(CLOSE)

I believe P2D renderer is needed even on Java Mode.

villares commented 5 years ago

I'm stunned! This works:

size(300, 300, P2D)
translate(width / 2, height / 2)
beginShape()
# Exterior part of shape
vertex(-100, -100)
vertex(100, -100)
vertex(100, 100)
vertex(-100, 100)
# Interior part of shape
beginContour()
circleRes = 4
for i in range(circleRes):
        angle = TWO_PI * i / circleRes
        x = 10 * sin(angle)
        y = 10 * cos(angle)
        vertex(x, y)
endContour()
# Finishing off shape
endShape(CLOSE)

But the code on the first post still doesn't.

villares commented 5 years ago

Eureka! Only counter-clockwise "contours" (holes) work. This is a common spec in many graphic engines. It seems Processing adopted it at some point and now it is documented here: https://processing.org/reference/beginContour_.html

So we should fix it here: https://py.processing.org/reference/beginContour.html (notice the image!) And I'll help fix the example too :)


size(300, 300, P2D)
translate(width / 2, height / 2)
beginShape()
fill(0)
stroke(255)
strokeWeight(2)
# Exterior part of shape
vertex(-100, -100)
vertex(100, -100)
vertex(100, 100)
vertex(-100, 100)
# Counter-clockwise interior poly
beginContour()
vertex(-10, -10)
vertex(-10, 10)
vertex(10, 10)
vertex(10, -10)
endContour()
# Finishing off shape
endShape(CLOSE)
villares commented 4 years ago

Hi @jdf! Thanks for merging my updates.

Could you please have a look on why the reference page has not incorporated the fixes? https://py.processing.org/reference/beginContour.html Updated on Fri Aug 16 21:51:56 2019.

This is an issue also with the PVector docs merged: https://github.com/jdf/Processing.py-Bugs/issues/236