[squeak-dev] PolygonMorph textures

Edgar J. De Cleene edgardec2005 at gmail.com
Thu Dec 16 10:05:42 UTC 2010




On 12/15/10 8:30 PM, "Robin Schreiber" <The_robin_hood at gmx.net> wrote:

> Hi everyone,
> 
> What I would like to have, is a Polygon Morph that can be painted with a
> specified texture e.g. a certain image that repeats multiple times so that it
> covers up the PolygonMorph from inside with a pattern, but still preserve the
> Polygons outline.
> My first idea was, to create a simple polygonMorph, add Imagemorphs as
> Submorphs, containing he specified images, and then make use of the
> clipSubmorphs method. Unfortunately It turns out that the requried clipping
> bounds can only be specifed by a rectangel and not by  a polygonMorph or an
> array of vertices.
> I then tried a different idea, basically creating a new class consisting out
> of a simple Morph with setheral Submorphs (textureParts) who each contain the
> texture Image (therefore ImageMorphs).
> 
> drawTexture
> "This method 'fills up' the PgiMorph with its specified texture image"
> | xStep yStep xUpper xLower yUpper yLower|
> xUpper := self bounds topRight x.
> xLower := self bounds topLeft x.
> yUpper := self bounds bottomRight y.
> yLower := self bounds topLeft y.
> xStep := self baseImage width.
> yStep := self baseImage height.
> self textureParts: Bag new.
> 
> xLower to: xUpper by: xStep do:
> [:ax | 
> yLower to: yUpper by: yStep do:
> [:ay |
> self textureParts add: (((ImageMorph new image: (self baseImage form copy:
> self baseImage form boundingBox)) position: ax at ay) openInWorld).].].
> 
> self textureParts do:[:each | self addMorph:each].
> 
>  I then create a PolygonMorph specify the desired form factor and then iterate
> over every SubImageMorph, setting each Imagemoprhs Form Pixelvalue transparent
> where the Point is outside the PolygonMorph and leave it untouched where it is
> inside.
> 
> clipTextures
> self textureParts do:[:each | self clipTexture: each].
> 
> ********************************
> 
> clipTexture: aTexturePart
> "this method clips the selected texturepart with respect to the maskMorph"
> | xUpper xLower yUpper yLower |
> xUpper := aTexturePart bounds topRight x. Transcript show: aTexturePart bounds
> topRight.
> xLower := aTexturePart bounds topLeft x.
> yUpper := aTexturePart bounds bottomRight y.
> yLower := aTexturePart bounds topLeft y.
> 
> xLower to: xUpper do:
> [ :ax |
> yLower to: yUpper do:
> [ :ay |
> (self maskMorph containsPoint: (ax at ay)) ifFalse: [
> aTexturePart form colorAt: (ax at ay) put: (Color transparent).].].].
> 
> It turns out however that I receive a very strangebe haviour of this new kind
> of Morph, meaning it does not seem to transparentize every Pixel of the Form
> that would be needed.
> 
> Anyway I can include the complete code segment if you wish, however it may be
> of course that I am on a completely wrong track with all of this, so if anyone
> of you knows of a better solution I'd be delighted to hear from you.
> 
> Robin
> 
> 


Maybe badly misunderstand you , but this is on image for a long time.

Rompecabezas do the opposite, cut bigger image and clip to the exact form or
PolygonMorph.
And Jerome Peace have several nice fills for PolygonMorph, some published in
previous FunSqueak images and some he still do not publish.

Jerome , please send any you have, do not be shy





More information about the Squeak-dev mailing list