can anyone think of a way to make a "add square x:() y:() to x:() y:() to costumes" block? It would be very, very useful for rendering images that are smaller than the stage in Panther!
I assume that it could be done if the method for the "grab screen region for new costume" method could be found and edited to take the block arguments as a reference rather than a mouse selection.
Last edited by sparks (2011-09-11 09:12:48)
Offline
*following*
I've always wanted this block in panther.
Offline
I want it because it would make Panther a very useful rendering tool. Currently, using the add stage to costumes button you can't render anything other than 240X360 images and those images are saved in gif format, losing a LOT of quality. This block would then allow you to eliminate both of these problems.
Offline
I needed this ages back for a project I was working on. Please somebody get this working so I can restart my project. Storing data in images!
Offline
johnnydean1 wrote:
I needed this ages back for a project I was working on. Please somebody get this working so I can restart my project. Storing data in images!
That would be a handy application actually! I made one in Scratch years ago but you had to grab the image by hand.
Offline
sparks wrote:
Any idea, LS97?
Wait, why me?
I do have an idea actually. Find the method that gets called when the user clicks "grab stage region" from the menu (I forgot the exact name). You'll need to scan through it and look where it says about mouse dragging, and substitute those values with variables.
That wasn't explained too well at all, was it?
Sorry. It's 11PM and I've been working for 5 hours.
Last edited by LS97 (2011-09-13 16:52:15)
Offline
So far I've located this method:
Scratch-Objects >> ScratchSpriteMorph>>all>>grabFormFromScreen
grabFormFromScreen
| t1 t2 |
t1 _ Form fromUser.
t2 _ (Form extent: t1 extent + 2 depth: t1 depth) fillWhite.
t1
displayOn: t2
at: 1 @ 1
rule: Form over.
t2 shapeFill: Color transparent interiorPoint: 0 @ 0.
t1 _ t2 trimBordersOfColor: Color transparent.
t1 width = 0 | (t1 height = 0) ifTrue: [^ nil].
^ t1
It's taking the form directly here though, so there's no user input - I have a feeling this isn't the method we need but I'll document it as it took ages to find, I wish the browser had a full-browser search option...
grabFromScreen is just below.
grabFromScreen
| t1 t2 |
(t1 _ self grabFormFromScreen) ifNil: [^ self].
t2 _ ImageMedia new form: t1.
t2 mediaName: (self unusedMediaNameFromBaseName: 'costume1').
media addLast: t2.
self lookLike: t2 mediaName.
self updateMediaCategory
Scratch-Objects >>ScratchStageMorph >> all >> grabSpriteFromScreen could help:
grabSpriteFromScreen
| t1 t2 t3 |
(t1 _ self ownerThatIsA: ScratchFrameMorph) ifNil: [^ self].
t2 _ ScratchSpriteMorph new.
(t3 _ t2 grabFormFromScreen) ifNil: [^ self].
t2 onlyCostume: t3.
t1 addAndView: t2
Last edited by sparks (2011-09-13 16:59:23)
Offline
I wish I could help sparks, but unfortunately I don't know squeak, and I can't just "see" what's going on as it's so different to any programming language I know. It's too object oriented :S
Offline
Dunno if this would work.
Read the pixels from the screen into an Ordered-Collection,
Make a new costume for the sprite (Blank, but to the correct dimensions )
Draw the pixels onto the sprite's costume.
Offline
something similar to
colorAtX: t1 y: t2
| t3 t4 t5 t6 t7 |
t3 _ self ownerThatIsA: ScratchFrameMorph.
t3
ifNil:
[(t4 _ self ownerThatIsA: OffscreenWorldMorph) ifNil: [^ self].
t3 _ t4 frame].
t5 _ t1.
t5 isNaN ifTrue: [t5 _ 0].
t5 > 240 ifTrue: [t5 _ 240].
t5 < -240 ifTrue: [t5 _ -240].
t6 _ t2.
t6 isNaN ifTrue: [t6 _ 0].
t6 < -180 ifTrue: [t6 _ -180].
t6 > 180 ifTrue: [t6 _ 180].
DoubleSize
ifTrue:
[t5 _ t5 * 2.
t6 _ t6 * 2].
t7 _ t5 @ t6 negated.
^ Display colorAt: ScratchOrigin + t7(code for panther find colour of pixel at location x()y())
Offline
I'm not sure how you do anything in smalltalk, but you could create an array of the output, by using a loop to go through all the different co-ordinates of the area then saving the colours to the array
Offline
rookwood101 wrote:
I'm not sure how you do anything in smalltalk, but you could create an array of the output, by using a loop to go through all the different co-ordinates of the area then saving the colours to the array
That's what I was getting at...
Offline