Change color palette dynamically

Hello there,

I want to change the color palette of my MakeCode Arcade project dynamically. There seem to be some extensions that can do that for me, but documentation is lacking and I don’t understand how to use it.

Is there any documentation or extensions that can help me change the color palette dynamically easily?

Yes use the “palette” extensions. Hopefully the blocks are self-explanatory.

This one?

I’ve added it but I don’t see any new blocks

It’s in the explorer though

That extension is JavaScript only. We have this one for blocks:

It’s not very useful right now, I’m afraid, because there is no way to create palettes. @jwunderl

That’s why!

I’ve used the color extension but the only thing that seems to work is the screen to fade to black or white

Yeah, that’s why we marked it as beta. We still need to figure out what the API for creating palettes should look like.

Do you have any suggestions? What would the ideal block look like for you @UnsignedArduino?

This is what I thought of when you first asked me, but there is one major drawback - You wouldn’t see the color changes immediately so you wouldn’t know which color is being changed.

1 Like

Or maybe something like this

1 Like

This would probably be the easiest to implement

The second one you mentioned (numbers 1-15 w/ a color picker field editor along the lines of the chrome one here) is what I’ve been wanting to do, but just haven’t had time / forgotten about doing it when I have had time. Might be a good thing to start over the weekend, now that I’m stuck at home…

The last one you mentioned should be trivial to add, and I suppose a version with slots for values instead of a field editor will be helpful for changing colors programmatically anyways, so I’ll take a look at doing that real quick :slight_smile: It’s an extension in a separate repo anyways so it can be updated without a release of the editor

RGB HSV light blocks

You could use the second one and be able to use these blocks.

suggestion

Or these blocks in the light extension.

1 Like

Hm, that might be a little harder looking at it; no problem implementation wise, but it would add a dependency on the neopixel light for just those two blocks, and would probably be harder to find / interact with across two different categories; for now I think I’ll duplicate those in the color extension and we can take a look deduping that in the future (changing that package requires a full update to arcade itself). Thanks for pointing that out though!

Thanks for helping me!

1 Like

No problem! Thanks for helping design the blocks / confirming what the design of the field editor block should ideally be!

Just added the blocks to the color fading extension, you’ll need to update it to get them. Sorry for the delay, was at the store for a bit getting some stuff for dinner :slight_smile: Please let me know if they give you any trouble, haven’t built anything with it besides a trivial test example but I’ll probably play around with it this weekend. (also need to figure out why the set color palette and fade from blocks broke, I think I had checked them just before the last release but for some reason the builtin palettes aren’t loading as a drop down anymore… weird this should be fixed as well with v0.1.1, minor internal bug I could work around :slight_smile: )

1 Like

Thank you so much!

I haven’t updated them yet, because I am replying on a phone. But I am so excited to try them out. :smile:

Thanks.

1 Like

Just tried it, looks so cool! I love the built in color palettes!

I cannot express my thanks enough :smiley:

1 Like

Glad to hear it’s useful, and thanks for pointing out it broke a while back :slight_smile:

Also, if you want to add your own color palettes (or make an extension with your own!) they’re defined here: https://github.com/jwunderl/pxt-color/blob/master/palettes.ts – the little comment magic above it is what turns it from a constant into a value in the dropdown – besides a few of the specialty ones, most are from https://lospec.com/palette-list

1 Like

Another variation on the theme: Palette blocks extension

Can I set a custom colour palette for just certain sprites and then reset the default palette for the rest of the game in JavaScript?

Only 16 colors (including clear) can be on the screen at once - if you change colors it will change for all sprites.

One workaround, if you can find a few colors that you can live without, is to use those indices as special placeholder colors for the sprites and only ever change those - I do something like that for the team colors in https://arcade.makecode.com/nfl - leave all but 4 colors as one color palette, and change the last 4 based on the teams that are chosen.