Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you draw a pen line without problems if the line goes outside the stage?
- helloworldbyeworld
-
Scratcher
1000+ posts
How do you draw a pen line without problems if the line goes outside the stage?
Hello,
Usually, you can simply draw a straight pen line by going to the starting location, “pen down”, then going to the end location. However, if the end location is outside the stage, an incorrect line will be drawn because Scratch limits sprite positions inside the stage.
Is there a way to prevent this from happening? If the line goes outside the stage, the line will simply be cut off, not modified. Here's a diagram:

Thanks!
Usually, you can simply draw a straight pen line by going to the starting location, “pen down”, then going to the end location. However, if the end location is outside the stage, an incorrect line will be drawn because Scratch limits sprite positions inside the stage.
Is there a way to prevent this from happening? If the line goes outside the stage, the line will simply be cut off, not modified. Here's a diagram:

Thanks!
- mstone326
-
Scratcher
1000+ posts
How do you draw a pen line without problems if the line goes outside the stage?
You could set parameters, for the example above, if Y < -180, set Y to -180. That should keep the pen on the stage I would think.
- helloworldbyeworld
-
Scratcher
1000+ posts
How do you draw a pen line without problems if the line goes outside the stage?
You could set parameters, for the example above, if Y < -180, set Y to -180. That should keep the pen on the stage I would think.No, I want lines that go outside the stage to still be drawn, but without “distortion”. So the line would still be cut off, but the angle would not be changed.
- mstone326
-
Scratcher
1000+ posts
How do you draw a pen line without problems if the line goes outside the stage?
Can you share your project. I am not seeing my line with pen do that exactly.
here is a pen that can off stage but here I do see the angle change when we scroll.
https://scratch.mit.edu/projects/743751586/
here is a pen that can off stage but here I do see the angle change when we scroll.
https://scratch.mit.edu/projects/743751586/
Last edited by mstone326 (Oct. 11, 2022 02:17:40)
- awesome-llama
-
Scratcher
1000+ posts
How do you draw a pen line without problems if the line goes outside the stage?
The word you are looking for is “clip”, this should help if you want to search for it.
https://scratch.mit.edu/search/projects?q=line%20clip
https://scratch.mit.edu/search/projects?q=line%20clipping
https://en.wikipedia.org/wiki/Line_clipping
Generally what's done is the line's intersection point is found with the clipping line (in your case the edges of the screen). With the intersection point, the part of the line that you don't want to keep can be removed by using the intersection point as a new end point.
https://scratch.mit.edu/search/projects?q=line%20clip
https://scratch.mit.edu/search/projects?q=line%20clipping
https://en.wikipedia.org/wiki/Line_clipping
Generally what's done is the line's intersection point is found with the clipping line (in your case the edges of the screen). With the intersection point, the part of the line that you don't want to keep can be removed by using the intersection point as a new end point.
- Scratch-Minion
-
Scratcher
1000+ posts
How do you draw a pen line without problems if the line goes outside the stage?
Sprites can move to accurate positions off the stage provided that about 15 pixels of their costumes remain on the stage.
If you make your drawing costume very big in the costume editor using the full height and width there which is twice the screen size, then you will be able to move approximately one screen size off the screen in any direction (minus the 15 pixels).
Provided your offscreen points are never further away than this, you can use this method and avoid line clipping.
If you make your drawing costume very big in the costume editor using the full height and width there which is twice the screen size, then you will be able to move approximately one screen size off the screen in any direction (minus the 15 pixels).
Provided your offscreen points are never further away than this, you can use this method and avoid line clipping.
- Discussion Forums
- » Help with Scripts
-
» How do you draw a pen line without problems if the line goes outside the stage?



