Setting pen color to NaN can cause inconsistencies

If you use NaN as pen hue, the pen [hue V] block can return an incorrect result.

Reproduce/Replicate

  1. Drag the script below to the Snap! editor or try to rcreate the script below:
    untitled script pic (62)

  2. Try running the block.

  3. 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.

Good grief, do you spend all your time looking for edge cases? :slight_smile:

checking for NaN would slow down snap, not worth it at all.

try changing the original pen color in the first block.

or white, for me.

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
}

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?

to remember and restore the original pen color!

Of course. Sorry.