Discuss Scratch

jaden0327
Scratcher
4 posts

How to make hexadecimal in scratch?

I want to make a color hex project
Who can tell me how to do it?

https://scratch.mit.edu/projects/705835403/

Last edited by jaden0327 (June 17, 2022 00:43:08)

ANTNEST2
Scratcher
3 posts

How to make hexadecimal in scratch?

jaden0327 wrote:

I want to make a color hex project
Who can tell me how to do it?

https://scratch.mit.edu/projects/705835403/

Thank you for your query! In fact, I am also working on a similar project but using LUM format. Is it alright if I get back to you in a while?
jaden0327
Scratcher
4 posts

How to make hexadecimal in scratch?

ANTNEST2 wrote:

jaden0327 wrote:

I want to make a color hex project
Who can tell me how to do it?

https://scratch.mit.edu/projects/705835403/

Thank you for your query! In fact, I am also working on a similar project but using LUM format. Is it alright if I get back to you in a while?
ok
awesome-llama
Scratcher
1000+ posts

How to make hexadecimal in scratch?

What do you want to do with hexadecimal colours exactly?
ANTNEST2
Scratcher
3 posts

How to make hexadecimal in scratch?

jaden0327 wrote:

ANTNEST2 wrote:

jaden0327 wrote:

I want to make a color hex project
Who can tell me how to do it?

https://scratch.mit.edu/projects/705835403/

Thank you for your query! In fact, I am also working on a similar project but using LUM format. Is it alright if I get back to you in a while?
ok
Okay, I got an idea. Firstly, create variables for each digit, then code a program that divides the RBG format into 16 and obtain the remainder. Then, create a function that converts digits beyond 9 into hexadecimal format. Then, join the digits using Red, Green And blue, with the hashtag in front!

Hope this helps!
jaden0327
Scratcher
4 posts

How to make hexadecimal in scratch?

awesome-llama wrote:

What do you want to do with hexadecimal colours exactly?
I want to make a format that can convert RGB colors into hex
jaden0327
Scratcher
4 posts

How to make hexadecimal in scratch?

ANTNEST2 wrote:

jaden0327 wrote:

ANTNEST2 wrote:

jaden0327 wrote:

I want to make a color hex project
Who can tell me how to do it?

https://scratch.mit.edu/projects/705835403/

Thank you for your query! In fact, I am also working on a similar project but using LUM format. Is it alright if I get back to you in a while?
ok
Okay, I got an idea. Firstly, create variables for each digit, then code a program that divides the RBG format into 16 and obtain the remainder. Then, create a function that converts digits beyond 9 into hexadecimal format. Then, join the digits using Red, Green And blue, with the hashtag in front!

Hope this helps!
oh….he doesn't run correctly, can you give me the program?
god286
Scratcher
1000+ posts

How to make hexadecimal in scratch?

2 digit hex can be from 0-255 and each letter in RGB is also 0-255 which is great
To convert from base10 to base16 we can divide the input number by 16 and then use the quotient and remainder.
For example, to convert 255 into base 16,
254 / 16 = 15 and the remainder is 14
Base 10 has 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Base 16 has 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
10 is A, 11 is B, 12 is C, 13 is D, 14 is E, 15 is F
Since 15 (the quotient) is greater than 9, 15 is F, so the first character is F.
The remainder is 14, it is greater than 9, 14 is E, so the second character is E.
'F' + ‘E’ is FE so FE is your answer.
define rgb to hex (number)
set [quotient v] to ([floor v] of ((number) / (16))) // 'number / 16' returns a decimal number, and 'floor' rounds it down to an integer or whole number
set [remainder v] to ((number) mod (16)) // mod block
if <(quotient) > [9]> then
if <(quotient) = [10]> then
set [first digit v] to [A]
end
if <(quotient) = [11]> then
set [first digit v] to [B]
end
if <(quotient) = [12]> then
set [first digit v] to [C]
end
if <(quotient) = [13]> then
set [first digit v] to [D]
end
if <(quotient) = [14]> then
set [first digit v] to [E]
end
if <(quotient) = [15]> then
set [first digit v] to [F]
end
else
set [first digit v] to (quotient)
end
if <(remainder) > [9]> then
if <(remainder) = [10]> then
set [first digit v] to [A]
end
if <(remainder) = [11]> then
set [second digit v] to [B]
end
if <(remainder) = [12]> then
set [second digit v] to [C]
end
if <(remainder) = [13]> then
set [second digit v] to [D]
end
if <(remainder) = [14]> then
set [second digit v] to [E]
end
if <(remainder) = [15]> then
set [second digit v] to [F]
end
else
set [second digit v] to (remainder)
end
set [result v] to (join (first digit) (second digit))
This only works for numbers between 0 and 255 though.
If your RGB is 123, 233, 453 then you need to do this individually, and join them all together with the join block. Then add a “#” at the front.
Retr0id
Scratcher
68 posts

How to make hexadecimal in scratch?

god286 wrote:

2 digit hex can be from 0-255 and each letter in RGB is also 0-255 which is great
To convert from base10 to base16 we can divide the input number by 16 and then use the quotient and remainder.
For example, to convert 255 into base 16,
254 / 16 = 15 and the remainder is 14
Base 10 has 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Base 16 has 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
10 is A, 11 is B, 12 is C, 13 is D, 14 is E, 15 is F
Since 15 (the quotient) is greater than 9, 15 is F, so the first character is F.
The remainder is 14, it is greater than 9, 14 is E, so the second character is E.
'F' + ‘E’ is FE so FE is your answer.

-snip-

This only works for numbers between 0 and 255 though.
If your RGB is 123, 233, 453 then you need to do this individually, and join them all together with the join block. Then add a “#” at the front.

You can go a lot simpler than all those if() blocks

set [result v] to (letter ((digit) + (1)) of [0123456789abcdef])
Olaxee
Scratcher
1 post

How to make hexadecimal in scratch?

when this sprite clicked
when backdrop switches to [ v]
when backdrop switches to [ v]
when backdrop switches to [ v]

Powered by DjangoBB