First-class colors (Part 2)

@bh will explain

okay then i'll wait for him to answer then

A data type is first class in a programming language if it can be

  • the value of a variable
  • a member of a data aggregate (a list, in Snap!)
  • an input to a procedure
  • the value reported by a procedure

So for example in Scratch, lists aren't first class, because you can't make a list of lists, or write a custom block that reports a list, etc. But in Snap! you can do those things, so lists are first class in Snap!.

First classness is a property of a data type, not of a specific value. So don't think some colors are first class and others aren't.

The new Colors and Crayons library (coming soon) makes colors first class: you can make a list of colors, etc. The application everyone is clamoring for is a MIX block that takes two colors as inputs and reports the color you get by mixing them.

When exactly will the new code for Colors and Crayons be deployed?

Why do you expect them to know exactly when it will release?

When I finish writing it! :~P

The immediate issue I'm working on is getting the top half and the bottom half to look the same:

As you can see, it's not terrible, but it needs work, especially in the browns and the purples.

The top half is the Colors scale; the bottom half is the colors I get by asking for the closest Color-scale color to a given color, when I use the Color-scale colors as inputs (so the output should be the same).

I mean, an estimate of the time it will take.

@bh , Isn't that a result of

Doesn't that mean you are using an approximation to make the bottom half, Of course it wouldn't be the exact same as the top half.

Can I have the latest build of the new colors and crayons library?

The link is the same as before:

Here's how the bottom half is made:

The first SET PEN block sets the color to (exactly) one of the color numbers. CURRENT PEN COLOR reports that color (first class data, remember), still exactly right. Then I use COLOR NUMBER FROM COLOR to try to find the closest color number to the color. Since the input color /is/ one of the color numbers, I would expect to get exactly the right color number. And then I use that to set the pen color again.

Nevertheless, I don't insist that the COLOR NUMBER FROM COLOR be exactly right, but it should be close enough so that a user won't notice unless they're paying close attention to the color.

One could argue that I really don't need to accept any color at all and find the closest color number. But other FROM COLOR options clearly work, e.g., RGB FROM COLOR, HSL FROM COLOR, etc. Color numbers, being a one-dimensional space, don't include every possible RGB color, though.


How many of the color numbers would you need to make it close enogh to

ok I am getting impatient so : @helicoptur @sathvikrias , how would you think that these could be used

set the pen to a certain color, get pen color, set costume to a specific color?
i honestly don't think there is or was a lot of reason in the first place except "everything must be first class" and there aren't a lot of uses for colors anyway

If you put your head to it, you'll think of at least 20 ways to use them

we're in different time zones, or you posted that at 9 pm, I was going to bed

uh, but how could you use them

hello, I see that people are taking days to respond so please pay more attention.

i tweaked and added some things in @wunder_wulfe's color block library, and i think it came out pretty good!
any thoughts?


Ooh, I like this:

but I'm not convinced about this:

Shouldn't adding black to something leave it unchanged?

RGB values, your eyes may be tricking you.