This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-12-08 07:21:39

rico
Scratcher
Registered: 2007-05-22
Posts: 47

Can anyone help program the pencil sprite to color within the lines?

The drawing_pencil (in the Things folder in Scratch) comes with one script that puts down a blue pen and draws as the mouse is clicked and dragged. I would like the drawing_pencil to draw but only when it is within the bounds of a certain area of the Stage (i.e., "color within the lines"), but I am not smart enough to figure out how to do it (please know I have tried -- for about three days). Would anyone mind helping?

Last edited by rico (2008-12-08 07:25:27)

Offline

 

#2 2008-12-08 10:52:19

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Can anyone help program the pencil sprite to color within the lines?

You could do this:

[blocks]<when green flag clicked>
<forever>
<if><mouse down?>
<if><touching color[ color
<pen down>
<end>
<else>
<pen up>
<end>[/blocks]

That will make the pen draw only if it is touching certain color.


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#3 2008-12-08 17:07:08

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Can anyone help program the pencil sprite to color within the lines?

I did a simple approach a few months ago:

http://scratch.mit.edu/projects/JSOlabs/192030


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#4 2008-12-08 21:49:30

rico
Scratcher
Registered: 2007-05-22
Posts: 47

Re: Can anyone help program the pencil sprite to color within the lines?

technoguy: thank you for the reply. i was able to get limited success with your suggestion. i think i'm not sure whether the "if" blocks go inside each other or on top of each other. i will experiment a little more.

JSO: what an elegant solution. the results you got are exactly what i want to do, now i just have to figure out how you did it.

THANK YOU!

Offline

 

#5 2008-12-09 04:50:28

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Can anyone help program the pencil sprite to color within the lines?

rico wrote:

technoguy: thank you for the reply. i was able to get limited success with your suggestion. i think i'm not sure whether the "if" blocks go inside each other or on top of each other. i will experiment a little more.

JSO: what an elegant solution. the results you got are exactly what i want to do, now i just have to figure out how you did it.

THANK YOU!

JSO is a very clever guy...he has made a masking sprite (sprite1) with a cat-shaped hole in it lined up right over the cat picture on the background.  The pen will never draw over a sprite (it only draws on the background) so the pen can only be seen through the cat-shaped hole in the masking sprite.  If you hide sprite1 you will see that the pen is actually drawing everywhere...but you can only see it on the cat because of the masking sprite.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-12-09 07:05:04

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Can anyone help program the pencil sprite to color within the lines?

Is this for general drawing program or is it going to be a specific picture that can be coloured?

If the former, this method will not really work for you.  Finding a method that will could be very tricky, especially as scratch has no "in-program colour sampling" which can pick up and use the colour as a variable.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

Board footer