Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Pen color
- OrangeWorld
-
Scratcher
89 posts
Pen color
There is a block like this:
in my game both 2 players will chose a pen color of their own using color, brightness, saturation variables. The game will save the color and use it when the game starts but how can I do that?
set pen color to [#5afdee]
in my game both 2 players will chose a pen color of their own using color, brightness, saturation variables. The game will save the color and use it when the game starts but how can I do that?
Last edited by OrangeWorld (Sept. 17, 2020 10:50:59)
- SMKAS
-
Scratcher
500+ posts
Pen color
Is this for one of those games were you make a trail, and hit another player's trail, you die?
- SMKAS
-
Scratcher
500+ posts
Pen color
Why not just have it so that the positions are recorded, since color touching is very buggy, and etc.
when green flag clickedUse 2 if player 1 and 1 if player 2
forever
if <Game is On going :: custom> then
set [☁ X1/2 v] to (x position)
set [☁ Y1/2 v] to (y position)
end
end
when green flag clicked
forever
if <Game is On going :: custom> then
add (☁ X1/2) to [Don't Hit X v]
add (☁ Y1/2) to [Don't Hit Y v]
end
end
when green flag clicked
forever
if <Game is On going :: custom> then
if <([Don't Hit X v] contains (x position)) and ([Don't Hit Y v] contains (y position))> then
LOSE :: custom
end
end
end
- OrangeWorld
-
Scratcher
89 posts
Pen color
Why not just have it so that the positions are recorded, since color touching is very buggy, and etc.when green flag clickedUse 2 if player 1 and 1 if player 2
forever
if <Game is On going :: custom> then
set [☁ X1/2 v] to (x position)
set [☁ Y1/2 v] to (y position)
end
end
when green flag clicked
forever
if <Game is On going :: custom> then
add (☁ X1/2) to [Don't Hit X v]
add (☁ Y1/2) to [Don't Hit Y v]
end
end
when green flag clicked
forever
if <Game is On going :: custom> then
if <([Don't Hit X v] contains (x position)) and ([Don't Hit Y v] contains (y position))> then
LOSE :: custom
end
end
end
But HOW would I save the pen colors?
- SMKAS
-
Scratcher
500+ posts
Pen color
For the sprite, only color can be affected.
For the pen, every feature can be.
So just save those in cloud.
For the pen, every feature can be.
So just save those in cloud.
- awesome-llama
-
Scratcher
1000+ posts
Pen color
But HOW would I save the pen colors?Firstly, the pen colour block can take inputs from reporters.
set pen color to [#8aff79]
set pen color to (pen colour) // like this
What you can do instead is store the colour values in variables and set the pen colour from the variables when you need it.
But what goes in the variable? A number from 0 to 16777215, which is 16777216 possible numbers.
Hopefully you are aware that colours have three components - red, green, and blue. Because of the three channels, a colour can be represented as a set of three values.
Green for example is:
red = 0
green = 255 (100%)
blue = 0
A light grey would be:
red = 180
green = 180
blue = 180
—
With these three components, they can actually be stored as hexadecimal values. 100% or a value of 255 is FF, whilst a 0 is just 0.
Using this, here is green as a hexadecimal colour: 00FF00.
This is the grey from above: B4B4B4.
The first two characters are for the red component, 3rd and 4th are green, and the last two are blue.
So, to store the colour, you need to store these hexadecimal numbers in the variable.
When putting them into the set pen colour, you need to do one trick: add “0x” to the start of the number. These two characters ensure scratch sees it as a hexadecimal number rather than a string, and it will automatically be converted to the correct colour number.
Example:
set [colour v] to [FF00FF] // magenta
set pen color to (join [0x] (colour)) // setting the pen colour
Now, note that earlier, I mentioned the variable can store a number from 0 to 16777215. That is actually the numbers of 0 to FFFFFF in hexadecimal. So the variable containing FFFFFF (white) is actually the number 16777216.
Last edited by awesome-llama (Sept. 17, 2020 12:52:57)
- TheColaber
-
Scratcher
500+ posts
Pen color
Simply Just create 2 lists. One called player1 color and the other is player2 color. Then put this code in
when green flag clickedIt would be more easier if you shared the project so we can see but anyway…
delete (all v) of [player1 color v]
delete (all v) of [player2 color v]
wait until <(player1 picked color) = [true]>
add (color) to [player1 color v]
add (saturation) to [player1 color v]
add (brightness) to [player1 color v]
wait until <(player2 picked color) = [true]>
add (color) to [player2 color v]
add (saturation) to [player2 color v]
add (brightness) to [player2 color v]
// Put this code in both players but switch the values so it matches the players.
when green flag clicked
forever
set pen (color v) to (item (1 v) of [player1 v] :: list)::pen
set pen (saturation v) to (item (2 v) of [player1 v] :: list)::pen
set pen (brightness v) to (item (3 v) of [player1 v] :: list)::pen
end
- Discussion Forums
- » Help with Scripts
-
» Pen color