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

#1 2011-09-11 09:12:39

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

"add region x:() y:() to x:() y:() of stage to costumes" block?

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)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-09-11 11:09:13

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

*following*
I've always wanted this block in panther.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#3 2011-09-11 11:13:10

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#4 2011-09-12 16:34:29

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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!


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2011-09-13 04:45:50

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#6 2011-09-13 16:45:31

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

Any idea, LS97?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#7 2011-09-13 16:51:51

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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?  hmm
Sorry. It's 11PM and I've been working for 5 hours.

Last edited by LS97 (2011-09-13 16:52:15)

Offline

 

#8 2011-09-13 16:53:31

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2011-09-16 12:29:59

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

Bump


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#10 2011-09-16 17:39:53

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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


http://i.imgur.com/zeIZW.png

Offline

 

#11 2011-09-18 15:59:38

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

Bump


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#12 2011-09-19 03:23:57

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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.


You can now reach me on Twitter @johnnydean1_

Offline

 

#13 2011-09-19 14:17:27

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

Possibly... No idea what code that would take though.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#14 2011-09-19 14:28:05

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

something similar to

Code:

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())


http://i.imgur.com/zeIZW.png

Offline

 

#15 2011-09-19 14:58:49

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

That's a good point! Though it's going to have to take more than one pixel into account...


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#16 2011-09-19 15:09:22

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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


http://i.imgur.com/zeIZW.png

Offline

 

#17 2011-09-20 11:18:13

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: "add region x:() y:() to x:() y:() of stage to costumes" block?

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...


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer