Arc morph?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Arc morph?

timrowledge
I’m trying to find a nice way to do circular arc morphs; so far CurveMorph isn’t playing very nice for this and google is not finding anything that looks interesting.

Has anyone seen suitable code, or is anyone in possession of the Seekrit Knowledge of how to make CurveMorph do clean circular arcs?

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
For every action, there is an equal and opposite criticism.



Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

Bob Arning-2

Something like this, maybe?

'From Squeak5.1 of 23 August 2016 [latest update: #16548] on 3 April 2017 at 3:24:01 pm'!
Morph subclass: #BobsArcMorph
    instanceVariableNames: 'lineWidth startAngle stopAngle'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'MorphicExtras-AdditionalMorphs'!

!BobsArcMorph methodsFor: 'as yet unclassified' stamp: 'raa 4/3/2017 15:22'!
drawOn: aCanvas
"
 BobsArcMorph new openInWorld
"
    | center radius angle pt lw2 stop step |
   
    aCanvas fillRectangle: self bounds color: Color gray.
    lw2 _ lineWidth // 2.
    center _ self bounds center - (lw2@lw2).
    radius _ (self width min: self height) // 2 - lw2.
    angle _ startAngle min: stopAngle.
    stop _ (startAngle max: stopAngle) min: angle + Float twoPi.
    step _ 0.9 / radius.
    [
        pt _ center + (Point r: radius degrees: angle radiansToDegrees) rounded.
        aCanvas fillRectangle: (pt extent: lineWidth@lineWidth) color: color.
        angle _ angle + step.
        angle > stop
    ] whileFalse! !

!BobsArcMorph methodsFor: 'as yet unclassified' stamp: 'raa 4/3/2017 15:23'!
initialize

    super initialize.
    lineWidth _ 2.
    startAngle _ 0.
    stopAngle _ Float pi * 1.3.
    self color: Color yellow.
    self extent: 200@200.! !


On 4/3/17 2:23 PM, tim Rowledge wrote:
I’m trying to find a nice way to do circular arc morphs; so far CurveMorph isn’t playing very nice for this and google is not finding anything that looks interesting.

Has anyone seen suitable code, or is anyone in possession of the Seekrit Knowledge of how to make CurveMorph do clean circular arcs?

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
For every action, there is an equal and opposite criticism.






Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

timrowledge

> On 03-04-2017, at 12:25 PM, Bob Arning <[hidden email]> wrote:
>
> Something like this, maybe?

Yeah, that’s an interesting start. I also found -http://wiki.squeak.org/squeak/uploads/2624/PieChartMorph-gm.cs which is ancient and I’m afraid  I have no idea who ‘gm’ might be. That uses the low level polygon drawing on Canvas methods.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Any nitwit can understand computers.  Many do.



Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

Bob Arning-2

http://wiki.squeak.org/squeak/2291


On 4/3/17 3:37 PM, tim Rowledge wrote:
I have no idea who ‘gm’ might be.



Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

Ken G. Brown
In reply to this post by timrowledge
gm is for German Morales 

Ken G. Brown

On Apr 3, 2017, at 13:37, tim Rowledge <[hidden email]> wrote:


On 03-04-2017, at 12:25 PM, Bob Arning <[hidden email]> wrote:

Something like this, maybe?

Yeah, that’s an interesting start. I also found -http://wiki.squeak.org/squeak/uploads/2624/PieChartMorph-gm.cs which is ancient and I’m afraid  I have no idea who ‘gm’ might be. That uses the low level polygon drawing on Canvas methods.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Any nitwit can understand computers.  Many do.





Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

Karl Ramberg
Etoys image has a SectorMorph 
Not sure if it is in trunk
Best,
Karl 

On Mon, Apr 3, 2017 at 10:22 PM, Ken Brown <[hidden email]> wrote:
gm is for German Morales 

Ken G. Brown

On Apr 3, 2017, at 13:37, tim Rowledge <[hidden email]> wrote:


On 03-04-2017, at 12:25 PM, Bob Arning <[hidden email]> wrote:

Something like this, maybe?

Yeah, that’s an interesting start. I also found -http://wiki.squeak.org/squeak/uploads/2624/PieChartMorph-gm.cs which is ancient and I’m afraid  I have no idea who ‘gm’ might be. That uses the low level polygon drawing on Canvas methods.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Any nitwit can understand computers.  Many do.









Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

timrowledge

> On 03-04-2017, at 1:32 PM, karl ramberg <[hidden email]> wrote:
>
> Etoys image has a SectorMorph
> Not sure if it is in trunk

It seems to be there and functioning in the latest Squeak6.0alpha-17086-32bit. It is not especially helpful when needing an arbitrary arc, though, since various methods seem to rely upon the first vertex in the list being the centre of the radius. And it draws a really ugly curved edge too.

There’s also the old Arc class that I hadn’t spotted (because I looked for “arcm” thinking to find ArcMorph) but that doesn’t help a great deal without translating to morphland. And anyway we really ought to be able to do good curves by now. Yes, we have the B2Dplugin and BalloonCanvas but it’s not   all that convincing; try `WatchMorph new openInWorld` and then use its red menu to turn on anti-aliasing. A bit naff.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful Latin Phrases:- Cave ne ante ullas catapultas ambules = If I were you, I wouldn't walk in front of any catapults.



Reply | Threaded
Open this post in threaded view
|

Re: Arc morph?

Henrik-Nergaard
In reply to this post by timrowledge

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@200.
World fullDrawOn: canvas.

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

Best regards,
Henrik