If you use NaN
as pen hue, the pen [hue V] block can return an incorrect result.
Reproduce/Replicate
Drag the script below to the Snap! editor or try to rcreate the script below:
Try running the block.
Observe that the pen color turned to either yellow, aqua, or fuchsia, but the pen [hue V] block returns 0
as you can see.
Fix
Either:
Don't allow NaN
in the pen hue block.
Set color to black if NaN
.
Every time I run the script, I get tje exact same color, in fact, it's pretty consistent. Sure the value reported is wrong, but it's still consistent.
bh
January 18, 2025, 5:26am
3
Good grief, do you spend all your time looking for edge cases?
checking for NaN would slow down snap, not worth it at all.
try changing the original pen color in the first block.
ten_6044:
yellow, aqua, or fuchsia
or white, for me.
ten_6044:
the block returns 0
even funnier, check the pen rgba block!
I don't think it would slow it down as much as you think it would, since it's just as simple as
if isNaN(value) {
value = 0
}
bh
January 18, 2025, 11:56pm
6
ego-lay_atman-bay:
I don't think it would slow it down as much as you think it would, since it's just as simple as
if isNaN(value) {
value = 0
}
Sure, but how many places are there in Snap! where such tests would be needed to ensure that you couldn't find an edge case? Each individual test is minor, but they add up. (Even one such test adds up if it happens in a loop in redisplay.)
me trying something similar
everything with the (a variable there is unnecessary - why is it there?
bh
February 5, 2025, 12:19am
9
to remember and restore the original pen color!