Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Hex to Scratch Color effects
- WhillieHotDog
-
Scratcher
18 posts
Hex to Scratch Color effects
I got bored and started testing out making screens in scratch when I came across this roadblock.
I need to convert hexadecimal color codes (ex: #FFFFFF) to scratch sprite effects.
I would have to convert HEX to RGB, RGB to HSV, then HSV, to CSB (Color, Ghost, Brightness - The scratch look block effects)
Does anybody know what math I need to do to make these conversions?
Honestly, just having other people to pitch ideas with helps– but if you already know how to do this that's awesome (:
I need to convert hexadecimal color codes (ex: #FFFFFF) to scratch sprite effects.
I would have to convert HEX to RGB, RGB to HSV, then HSV, to CSB (Color, Ghost, Brightness - The scratch look block effects)
Does anybody know what math I need to do to make these conversions?
Honestly, just having other people to pitch ideas with helps– but if you already know how to do this that's awesome (:
- CHEEZ_ITZ_12oz
-
Scratcher
100+ posts
Hex to Scratch Color effects
Starting with #B60023 (for example), B6 represents Red, 00 Green, and 23 Blue. All you have to do for HEX - RGB is to convert each individual number from hexadecimals to decimals.
From here, start by dividing each RGB value by 255 to get a value between 0 and 1. Whichever value is biggest, lets call it MAX, and whatever is smallest, call MIN. For calculating HSV, V = MAX.
For Saturation, S = (V - MIN) / V. If V = 0, S = 0.
For Hue, if RGB are all the same values, H=0.
If V = R, H = 60 * (G - B) / (V - MIN).
If V = G, H = 120 + 60 (B - R) / (V - MIN)
If V = B, H = 240 +60 * (R - G) / (V - MIN)
From here, I have no idea how to convert it to CSB, but hopefully you can work with this.
From here, start by dividing each RGB value by 255 to get a value between 0 and 1. Whichever value is biggest, lets call it MAX, and whatever is smallest, call MIN. For calculating HSV, V = MAX.
For Saturation, S = (V - MIN) / V. If V = 0, S = 0.
For Hue, if RGB are all the same values, H=0.
If V = R, H = 60 * (G - B) / (V - MIN).
If V = G, H = 120 + 60 (B - R) / (V - MIN)
If V = B, H = 240 +60 * (R - G) / (V - MIN)
From here, I have no idea how to convert it to CSB, but hopefully you can work with this.
- 2468mariotime2
-
Scratcher
80 posts
Hex to Scratch Color effects
To convert from HSV to Scratch:
Color = H/3.6
Other values are the same
Color = H/3.6
Other values are the same
- Cat_Dusty
-
Scratcher
500+ posts
Hex to Scratch Color effects
To convert from HSV to Scratch:
Color = H/3.6
Other values are the same
that's not correct… color would be (h/360)*200
also there is no block for value in the editor
- 2468mariotime2
-
Scratcher
80 posts
Hex to Scratch Color effects
To convert from HSV to Scratch:
Color = H/3.6
Other things are the same
that's not correct… color would be (h/360)*200
also there is no block for value in the editor
i did a (simplified) version of (h/360)*100
value is renamed to brightness in scratch
- WhillieHotDog
-
Scratcher
18 posts
Hex to Scratch Color effects
I found this… thing
define rgb2hsv (r) (g) (b)
set [h v] to ((60) * (((((g) - (b)) <not<< (r) < (g)> or <(r) < (b)>>>) + (((((b) - (r)) * <<not< (g) < (b)>> and <(g) > (r)>>) + (((r) - (g)) * <<(b) > (r)> and <(b) > (g)>>))) / ((((r) * <not<< (r) < (g)> or <(r) < (b)>>>) + (((g) * <<not< (g) < (b)>> and <(g) > (r)>>) + ((b) * <<(b) > (r)> and <(b) > (g)>>)))) mod ((6) + (<< (r) < (g)> or <(r) < (b)>> * [Infinity])))
set [s v] to (((((r) * <not<< (r) < (g)> or <(r) < (b)>>>) + (((g) * <<not< (g) < (b)>> and <(g) > (r)>>) + ((b) * <<(b) > (r)> and <(b) > (g)>>))) / (255)) * (100))
set [v v] to (((((r) * <not<< (r) < (g)> or <(r) < (b)>>>) + (((g) * <<not< (g) < (b)>> and <(g) > (r)>>) + ((b) * <<(b) > (r)> and <(b) > (g)>>))) / (255)))
- Cat_Dusty
-
Scratcher
500+ posts
Hex to Scratch Color effects
To convert from HSV to Scratch:
Color = H/3.6
Other things are the same
that's not correct… color would be (h/360)*200
also there is no block for value in the editor
i did a (simplified) version of (h/360)*100
value is renamed to brightness in scratch
true, but this block
change [color v] effect by (25)
takes a value between 0 and 200, not 100 for some weird reason….
then whats saturation?
Last edited by Cat_Dusty (Dec. 19, 2023 00:46:31)
- WhillieHotDog
-
Scratcher
18 posts
Hex to Scratch Color effects
yeah i forgot about that. you have to divide by 1.8-1.9(i can't remember what I used to get a good color) because it goes from 0-200 instead of 0-100
I was originally using ghost effect for value but it doesn't work with brightness(cuz it completely disapears you can't see colors with low value no matter the darkness)
I'm making an NES emulator and it only has about 64 colors so I might as well just use indexed color
Thats what the real one uses anyways.
Thanks for your help
I was originally using ghost effect for value but it doesn't work with brightness(cuz it completely disapears you can't see colors with low value no matter the darkness)

I'm making an NES emulator and it only has about 64 colors so I might as well just use indexed color

Thats what the real one uses anyways.
Thanks for your help
Last edited by WhillieHotDog (Dec. 20, 2023 11:10:24)
- dylbot3000
-
Scratcher
2 posts
Hex to Scratch Color effects
if you have a fully red (CSB(0, 100, 100)) sprite, you can use this:
only works when saturation is 100
set [color v] effect to ((H) * (0.55555555555555))
set [brightness v] effect to ((L) - (50))
only works when saturation is 100
- Discussion Forums
- » Help with Scripts
-
» Hex to Scratch Color effects




