I have encountered a problem with the alpha
color component when experimenting with plotting points to represent Collatz orbits. See Wikipedia: Collatz conjecture.
This code does what is expected:
# plots Collatz orbits for numbers 1 to width - 1
def setup():
size(360, 360)
background(0)
noLoop()
noFill()
strokeWeight(1)
# stroke with and without transparency
# stroke(255, 254) # -> misses some points
stroke(255, 255) # -> draws all points
noSmooth()
def draw():
# plot each x, y where is y is in the orbit of x
for x in range(1, width):
c = collatz(x)
for y in c:
point(x, y)
def collatz(n):
# returns Collatz orbit for n, as a list
c = [n]
# terminate orbit at 1
while n > 1:
if n % 2 == 0:
# even number
n //= 2
else:
# odd number
n = 3 * n + 1
c.append(n)
return c
Here’s the result:
Note this statement:
stroke(255, 255) # -> draws all points
If I comment out that statement and uncomment the previous one to use this statement, which reduces alpha
to 254
, the result is quite different:
stroke(255, 254) # -> misses some points
The result becomes:
Many points are missing.
I have performed much experimentation, and found ways to work around this problem. For instance, using squares consisting of a single point, utilizing fill with transparency and no stroke, produces the desired result. However, I would still like to understand why reducing the alpha
component from 255
to 254
, when plotting points, causes the observed problem.
In case it matters, I am doing this on an old MacBook Air with El Capitan.
The title of this discussion was edited on July 20, 2021.