Can a script draw and paint (on) a sprite?

Is so, how?

I want to make some way to compose "drawing" or "graphic" values -- lines, rectangles, circles, arcs, ... groups, ... (with a bitmap image as just one special case) each with colored fills, borders, etc. -- and to eventually draw the result on the stage (or actually, in the workspace as a displayable value).

I can build the values by manually writing abstract data types represented as lists, awkward but workable. I cannot find a way to paint the result.

Thanks!

you can simulate drawing on a sprite by changing the costume of the drawing sprite to a small dot, and then use the paste on block to paste the drawing sprite on the sprite you want to draw on.

yes! sorta: You can paste a sprite onto another one, basically giving the impression of drawing on it:

https://snap.berkeley.edu/embed?project=Triangle&user=jens&showTitle=true&showAuthor=true&editButton=true&pauseButton=true

This is a project with stamping on another sprite

Thanks. This seems to use repeated paste to "paint" a line on a sprite, true? Is there a more direct way, like pen down on [sprite], assuming coordinates etc. can be sorted out?

Use-case: I want each sprite's smile to broaden or shrink over time.

Also, I would like students to make compound expressions of my shape structs (just like they do with numbers & operators), and visualize the result value in the workspace (not stage) using a throw-away sprite

the only way to do that would be to record the starting pos, then move, then use the end pos, and then draw a line between those positions, but that would mean, place that script in every time you move. The only way I can think of making it efficient (and a lot less copy and paste code), would be to make custom blocks for the motion blocks which have the script in them. Not very ideal, but pretty much the only way you can do it.

You can paint an image on the Stage then create a costume with theuntitled script pic - 2021-12-05T001231.212
That idea is used by the text costume library.

Thanks, @dardoro. Good pointer, but (a) needs JS enabled, and (b) it does not appear to pick up drawn strokes unless the pen is down, which messes up the stage.

Any suggestions for (b)?
Any longer-term solution planned for (a)? I heard something in Snap!Con 21 that suggested it is being considered.

Just remove the javascript from the block.

Here is what I made:
https://snap.berkeley.edu/snap/snap.html#present:Username=joecooldoo&ProjectName=Pen%20Down%20On%20Sprite

Thanks, @joecooldoo ! Will have to study this one, looked at code and don't understand how it works!

It the drawing slow by design? How would I make a finite drawing, say a small square, instantly?

[Edit:] I think I know. Might still have some questions. Thanks!

If you look in the second sprite, its doing that on purpose. You can just use the pen as normal when using the block. What it does is it creates a hidden clone that detects when the parent moves. When it does move, the clone will switch to the costume of the pen trails, and stamps it on the sprite. This has only one problem: If you set the sprite on an already painted pen trail, the pen trail will appear on the sprite, even though it hasn't been drawn on.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.