setDitherPattern() issues

So In Inside Playdate the function playdate.graphics.setDitherPattern(white, [ditherType]) is described as follow:

white should be a value in the range 0.0 (completely black) to 1.0 (completely white).

I read it as 0 will create a fully black pattern and 1 a fully white pattern and in between will be a mix of black and white.

It seems the function is actually taking the color set by playdate.graphics.setColor() and set the pattern in the alpha (which is great).

I feel the documentation should be a bit clearer.


I also noticed that playdate.graphics.getColor() return max float after a pattern has been set.

playdate.graphics.setDitherPattern( 0.5 )
print( "getColor:", playdate.graphics.getColor() )

getColor: 4.37073e+09

return a value like “pattern” or playdate.graphics.kPattern would be more appropriate.


And here another related issue, because setDitherPattern() is using the current color, if you call the function multiple time in a row, it might look like it fails because it seems it will default to the color black when the current color is a pattern. This is an undocumented behavior that look like a bug in practice.

Ideally the current color should be kept internally but getColor() should return this is a pattern when a pattern is set. On a related note, I think having a function to remove the pattern (like playdate.graphics.removePattern() or playdate.graphics.setPattern() without parameters) would be useful.

1 Like

previous discussion about setDitherPattern here: https://devforum.play.date/t/how-do-you-draw-a-dither-with-white-pixels-solid-and-other-pixels-transparent/274

I’ve fixed getColor() so it returns the pattern array when a pattern was set. As for the rest of this… I haven’t gotten any closer to the “right” answer since I looked at this last March. I’ll think on it some more. :thinking:

Agreed. Removing the pattern by setting colour was not obvious to me (I asked how to do it on Discord).