[squeak-dev] Arc morph?

Henrik Nergaard draagren at outlook.com
Tue Apr 4 11:24:58 UTC 2017


You could use a Form to draw the arc/circle to get nice antialiasing, and then transfer it onto the canvas.

Here is an example:

-----------------------------------------------------------------------------------------------------------------------------

| circle painter canvas |

circle := [ :radius :lineWidth |

| form halfR aaw color center |

aaw := 1.3.
color := Color white.
halfR := radius / 2.0.
center := halfR asPoint.
form := Form extent: radius asPoint depth: 32.

0 to: radius - 1 do: [ :y |
0 to: radius - 1 do: [ :x | | l rp |
rp := (x @ y) distanceTo: center.
l := rp + aaw > halfR
ifTrue: [ (halfR - rp min: aaw max: 0.0) / aaw ]
ifFalse: [ (rp - halfR + lineWidth min: aaw max: 0.0) / aaw ].
form colorAt: x @ y put: (color alpha: l)
]
].
form
].

painter := [ :form :color | | output bitBlt |
output := Form extent: form extent depth: 32.
bitBlt := BitBlt toForm: output.
output fillColor: color.
bitBlt sourceForm: form;
combinationRule: 37;
sourceRect: form boundingBox;
copyBits.
output
].

"====================================="
canvas := FormCanvas extent: 200 at 200.
World fullDrawOn: canvas.

canvas
translucentImage: (painter value: (circle value: 50 value: 10) value: Color orange) at: 20 at 20;
translucentImage: (painter value: (circle value: 60 value: 15) value: Color purple) at: 90 at 20;
fillRectangle: (40 at 45 extent: 12 at 12) color: Color green;
fillRectangle: (110 at 55 extent: 12 at 12) color: Color blue;
fillRectangle: (77 at 75 extent: 16 at 21) color: Color brown;
translucentImage: (painter value: (circle value: 100 value: 7) value: Color red)
at: 30 at 95 sourceRect: (0 at 60 extent: 100 @ 40).

canvas form inspect
--------------------------------------------------------------------------------------------------------------------

Best regards,
Henrik


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170404/111af696/attachment.html>


More information about the Squeak-dev mailing list