Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How can I translate Scratch color codes to actual HEX color codes?
- ShinyEevee68
-
26 posts
How can I translate Scratch color codes to actual HEX color codes?
I'm working on something outside of Scratch that involves a lot of colors. (About 50 - 100) I want the colors to be smoothly transitioned, and Scratch colors codes are very smooth. Also, the number of colors in Scratch is definitely better for basic understanding since HEX color codes involve Hexadecimal color coding. The thing I'm working on uses HEX color codes and nothing else, so I'm wondering if there is any way to translate them.
- ajskateboarder
-
1000+ posts
How can I translate Scratch color codes to actual HEX color codes?
Scratch uses HSV (hue, saturation, and value/brightness). Here's how you would do that in Scratch:
1. Convert the original HSV values to RGB space. This was derived from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGBThis was much more concise as a formula - if only Scratch had switch statements or at least “else if”…
2. Convert the RGB values into hexadecimal
3. Combine it!
1. Convert the original HSV values to RGB space. This was derived from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGBThis was much more concise as a formula - if only Scratch had switch statements or at least “else if”…
define hsv to rgb (h) (s) (v)
set [r v] to [0]
set [g v] to [0]
set [b v] to [0]
set [_i v] to ([floor v] of ((h) * (6))
set [_f v] to ((h) * (_i))
set [_p v] to ((v) * ((1) - (s)))
set [_q v] to ((v) * ((1) - ((f) * (s))))
set [_t v] to ((v) * ((1) - (((1) - (_f)) * (s))))
set [_space v] to ((_i) mod (6))
if <(_space) = [0]> then
set [r v] to (v)
set [g v] to (_t)
set [b v] to (_p)
else
if <(_space) = [1]> then
set [r v] to (_q)
set [g v] to (v)
set [b v] to (_p)
else
if <(_space) = [2]> then
set [r v] to (_p)
set [g v] to (v)
set [b v] to (_t)
else
if <(_space) = [3]> then
set [r v] to (_p)
set [g v] to (_q)
set [b v] to (v)
else
if <(_space) = [4]> then
set [r v] to (_t)
set [g v] to (_p)
set [b v] to (v)
else
if <(_space) = [5]> then
set [r v] to (v)
set [g v] to (_p)
set [b v] to (_q)
end
end
end
end
end
end
2. Convert the RGB values into hexadecimal
define to base16 (base10)
set [_digits v] to [0123456789abcdef]
set [base16 v] to []
repeat until <(base10) < [0]>
set [base16 v] to (join (letter ((base10) mod (16)) of (_digits)) (base16))
set [base10 v] to ((base10) / (16))
end
define rgb part to hex (part)
to base16 (part)
if <(length of (base16)) = [1]> then
set [part v] to (join (0) (base16))
else
set [part v] to (base16)
end
define rgb to hex (r) (g) (b)
set [hex v] to [#]
rgb part to hex (r)
set [hex v] to (join (hex) (part))
rgb part to hex (g)
set [hex v] to (join (hex) (part))
rgb part to hex (b)
set [hex v] to (join (hex) (part))
3. Combine it!
when green flag clicked
ask [Enter a hue value] and wait
set [h v] to (answer)
ask [Enter a saturation value] and wait
set [s v] to (answer)
ask [Enter a brightness value] and wait
set [v v] to (answer)
hsv to rgb (h) (s) (v) ::custom
rgb to hex (r) (g) (b) ::custom
say (join [The hex for that is: ] (hex))
Last edited by ajskateboarder (June 11, 2024 13:41:40)
- BigNate469
-
1000+ posts
How can I translate Scratch color codes to actual HEX color codes?
Or, just hack the color reporter into the
Here's a link to a project with it, which you can backpack the block from:
https://scratch.mit.edu/projects/1036286267/
(join () ())block, and let Scratch do the work.
Here's a link to a project with it, which you can backpack the block from:
https://scratch.mit.edu/projects/1036286267/
- acnh_gamess
-
1 post
How can I translate Scratch color codes to actual HEX color codes?
I just search up the conversion to scratch colors lol
- Discussion Forums
- » Advanced Topics
-
» How can I translate Scratch color codes to actual HEX color codes?