[Newbies] how to create multiple colorforms from a master colorform

Jerome Peace peace_the_dreamer at yahoo.com
Mon Mar 2 05:21:27 UTC 2009

Hi mstramba,

If you want a deck of playing cards from a master form consider using bitmap fill. It is fast and flexible and you do not need to deal with things on the bit level.


Drag and drop the picture on the image that gives you a sketch.

The sketch's form will be your master image.

Now make a card prototype. Usually a rectangle or a polygon will do.
For a rectangle set its extent to the size of a particular card.

protoCard :=
RectangleMorph new extent: cardWidth @ cardHeight.
protoFill := BitmapFillStyle from: masterImage .

protoCard fillStyle: protoFill .

cardOrigins := OrderedCollection new .

( 0 to: masterForm width -1 by: cardWidth ) do: [ :eachCol |
  ( 0 to: masterForm height -1 by: cardHeight ) do: [ :eachRow |
  cardOrigins add: eachCol at eachRow ] .

cards :=
  cardOrigins collect: [ :each |
    protoCard copy fillStyle: (protoFill copy origin: each) ] .

or alternately,

cards :=
  cardOrigins collect: [ :each |
    protoCard copy position: each ; fillStyle: protoFill copy ] .

This code is unchecked. You may need to do some light debugging.
Browse the classes involve to learn their methods.

If you need separate forms you can always do

cardForms :=
 cards collect: [ :each | each imageForm ] .
I don't know offhand if that will give you colorForms.

If this doesn't work you you look at BitBlt and figure out how to copy rectangles from your master form.

Good luck. hth,

Yours in curiosity and service, --Jerome Peace


--- On Sun, 3/1/09, mstramba <mikestramba at gmail.com> wrote:

> From: mstramba <mikestramba at gmail.com>
> Subject: [Newbies] how to create multiple colorforms from a master colorform
> To: beginners at lists.squeakfoundation.org
> Date: Sunday, March 1, 2009, 6:48 PM
> Greetings,
> I have a ColorForm create from  : (Form fromFileNamed:
> cards).
> It's an 840x504x8  png file of a deck of playing cards,
> i.e. showing all the
> cards.
> I want to create individual ColorForms, each representing
> one playing card
> from the 'master' colorform.
> So I guess I need to (in a loop) extract a rectangular area
> of pixels from
> the original ColorForm and then create a new colorform from
> those extracted
> pixels.
> I'm looking at the ColorForm, ImageMorph, Form .. and
> other superlcasses
> methods, but haven't figured out which combination of
> methods I need to use.
> Mike
> -- 


More information about the Beginners mailing list