Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How would I make a 2-colored line (using pen) that changes color at the middle point.
- Vericosi
- New to Scratch
5 posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
For context, please view the project I'm going to implement this to at https://scratch.mit.edu/projects/614589168/ (sorry for technically advertising, but it'll be easier to understand my question if you see the project yourself). My goal is to have the laser which connects the two sprites have 2 colors. I want it to be red on the half closer to the red sprite, and blue on the half closer to the blue sprite. I'd also like to have a white circle in the center where the two sides meet. Unfortunately, I have no clue how to find the center of a line using pen and that's why I'm here. Thanks for stopping by, and if you need me to further clarify what I'm looking for then feel free to reach out.
- Jareddddddd
- Scratcher
1000+ posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
take the 2 coords and use pythagoream theorum to find distance\
<([sqrt v] of (((x2) - (x1)) + ((y1) - (y2)))) = ([sqrt v] of (total distance))>
- Vericosi
- New to Scratch
5 posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
But then how would I use this to find the middle point of the line? take the 2 coords and use pythagoream theorum to find distance\<([sqrt v] of (((x2) - (x1)) + ((y1) - (y2)))) = ([sqrt v] of (total distance))>
- The_Imaginarium
- Scratcher
1000+ posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
Sharing a link to your project for context is not considered advertising.
(You will probably want to make a new sprite to control all the pen drawings)
How I would solve this problem is by first calculating the midpoint of the two sprites. This can be accomplished by adding the x and y values together and dividing them by two.
Now we can just switch colors when we reach the midpoint:
Now that the line has two colors, we just need to draw the circle at the midpoint of the sprites
(You will probably want to make a new sprite to control all the pen drawings)
How I would solve this problem is by first calculating the midpoint of the two sprites. This can be accomplished by adding the x and y values together and dividing them by two.
set [mid x v] to ((([x position v] of [Player 1 v]) + ([x position v] of [Player 2 v])) / (2))
set [mid y v] to ((([y position v] of [Player 1 v]) + ([y position v] of [Player 2 v])) / (2))
Now we can just switch colors when we reach the midpoint:
go to x: ([x position v] of [Player 1 v]) y: ([y position v] of [Player 1 v])
set pen color to [#0f9ae1]
pen down
go to x: (mid x) y: (mid y)
set pen color to [#fc0303]
go to x: ([x position v] of [Player 2 v]) y: ([y position v] of [Player 2 v])
pen up
Now that the line has two colors, we just need to draw the circle at the midpoint of the sprites
set pen color to [#ffffff]
set [radius v] to [50] // so you can adjust the size of the circle
set [angle v] to [0]
repeat (360)
pen down
go to x: ((([cos v] of (angle)) * (radius)) + (mid x)) y: ((([sin v] of (angle)) * (radius)) + (mid y))
change [angle v] by (1)
end
pen up
- Vericosi
- New to Scratch
5 posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
Sharing a link to your project for context is not considered advertising.
(You will probably want to make a new sprite to control all the pen drawings)
How I would solve this problem is by first calculating the midpoint of the two sprites. This can be accomplished by adding the x and y values together and dividing them by two.set [mid x v] to ((([x position v] of [Player 1 v]) + ([x position v] of [Player 2 v])) / (2))
set [mid y v] to ((([y position v] of [Player 1 v]) + ([y position v] of [Player 2 v])) / (2))
Now we can just switch colors when we reach the midpoint:go to x: ([x position v] of [Player 1 v]) y: ([y position v] of [Player 1 v])
set pen color to [#0f9ae1]
pen down
go to x: (mid x) y: (mid y)
set pen color to [#fc0303]
go to x: ([x position v] of [Player 2 v]) y: ([y position v] of [Player 2 v])
pen up
Now that the line has two colors, we just need to draw the circle at the midpoint of the spritesset pen color to [#ffffff]
set [radius v] to [50] // so you can adjust the size of the circle
set [angle v] to [0]
repeat (360)
pen down
go to x: ((([cos v] of (angle)) * (radius)) + (mid x)) y: ((([sin v] of (angle)) * (radius)) + (mid y))
change [angle v] by (1)
end
pen up
Thank you so much, dude! I think this should work just fine.
- Vericosi
- New to Scratch
5 posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
Problem solved. Now I just have to make some enemies that are only killed by one of the two colors, or the circle, requiring further teamwork between the two players.
- The_Imaginarium
- Scratcher
1000+ posts
How would I make a 2-colored line (using pen) that changes color at the middle point.
Ah! cool concept! Problem solved. Now I just have to make some enemies that are only killed by one of the two colors, or the circle, requiring further teamwork between the two players.
- Discussion Forums
- » Help with Scripts
- » How would I make a 2-colored line (using pen) that changes color at the middle point.