[Cuis-dev] AbstractVectorCanvas method to draw ovals

Juan Vuletich juan at cuis.st
Wed Mar 12 12:42:17 PDT 2025


Just pushed to GitHub. Apologies for the delay.

Thanks!

On 3/5/2025 7:42 PM, Mark Volkmann via Cuis-dev wrote:
> Yes, I love it! I think I was taught the wrong meaning of the word 
> "oval" in grade school and never learned the correct definition 
> despite having a B.S. in Math. ;-)
> Stadium it is!
>
> Let me know when your version is pushed and I'll change my Switch 
> morph to use the stadium method.
>
> On Wed, Mar 5, 2025 at 3:14 PM Juan Vuletich <juan at cuis.st 
> <mailto:juan at cuis.st>> wrote:
>
>     Hi Mark,
>
>     I expected more what https://en.wikipedia.org/wiki/Oval describes
>     as a "technical drawing oval". This could perhaps be called a
>     'Stadium'. Additionally, in VectorCanvas, coordinates describe the
>     points that the pen goes through, not a rectangle where the figure
>     is contained.
>
>     I suggest this:
>
>     stadium: aRectangle
>         "
>     | r |
>     r := 500 at 150 extent: 100 at 250.
>     (VectorCanvas onForm: Display)
>         strokeWidth: 2.0 color: Color red do: [ :canvas |
>                 canvas stadium: r ].
>     (VectorCanvas onForm: Display)
>         geometryTransformation: (AffineTransformation withRadians: 1
>     scale: 1.2 position: 200 at 100);
>         strokeWidth: 2.0 color: Color red do: [ :canvas |
>             canvas
>                 stadium: r ].
>     Display forceToScreen
>     "
>         | height p1 p2 p3 p4 radius width x1 x2 y1 y2 |
>         width := aRectangle width.
>         height := aRectangle height.
>         radius := (width min: height) / 2.
>         height < width
>             ifTrue: [
>                 x1 := aRectangle left + radius.
>                 x2 := aRectangle right - radius.
>                 y1 := aRectangle top.
>                 y2 := aRectangle bottom.
>                 p1 := x1 @ y1.
>                 p2 := x2 @ y1.
>                 p3 := x2 @ y2.
>                 p4 := x1 @ y2 ]
>             ifFalse: [
>                 x1 := aRectangle left.
>                 x2 := aRectangle right.
>                 y1 := aRectangle top + radius.
>                 y2 := aRectangle bottom - radius.
>                 p1 := x1 @ y2.
>                 p2 := x1 @ y1.
>                 p3 := x2 @ y1.
>                 p4 := x2 @ y2].
>         self
>             moveTo: p1;
>             lineTo: p2;
>             arcTo: p3 radius: radius angleOfXAxis: 0 largeFlag: false
>     sweepFlag: true;
>             lineTo: p4;
>             arcTo: p1 radius: radius angleOfXAxis: 0 largeFlag: false
>     sweepFlag: true.
>
>     Would this work?
>
>     On 3/5/2025 4:19 PM, Mark Volkmann via Cuis-dev wrote:
>>     Below is the AbstractVectorCanvas method I mentioned in the
>>     meetup today for drawing an oval. Here is an example of using it
>>     from a drawOn: method of a morph. See the TODO comment below
>>     related to getting the stroke width. I'm open to suggestions for
>>     improving this.
>>
>>     aCanvas strokeWidth: 5 color: Color red fillColor: Color yellow do: [
>>         aCanvas drawOval: rect strokeWidth: 5.
>>     ].
>>
>>     ---
>>
>>     drawOval: aRect strokeWidth: aStrokeWidth
>>         | diameter halfStrokeWidth height p1 p2 p3 p4
>>           radius strokeWidth width x1 x2 y1 y2 |
>>
>>         width := aRect width.
>>         height := aRect height.
>>
>>     "TODO: Why does this give the wrong value?"
>>     "strokeWidth := engine strokeWidth."
>>     strokeWidth := aStrokeWidth.
>>     halfStrokeWidth := strokeWidth / 2.
>>     diameter := (height min: width) - strokeWidth.
>>     radius := diameter / 2.
>>
>>     height < width
>>     ifTrue: [
>>     x1 := halfStrokeWidth + radius.
>>     x2 := width - x1.
>>     y1 := halfStrokeWidth.
>>     y2 := height - y1.
>>     p1 := x1 @ y1.
>>     p2 := x2 @ y1.
>>     p3 := x2 @ y2.
>>     p4 := x1 @ y2.
>>     ]
>>     ifFalse: [
>>     x1 := halfStrokeWidth.
>>     y1 := halfStrokeWidth + radius.
>>     x2 := width - x1.
>>     y2 := height - y1.
>>     p1 := x1 @ y2.
>>     p2 := x1 @ y1.
>>     p3 := x2 @ y1.
>>     p4 := x2 @ y2.
>>     ].
>>
>>     self
>>     moveTo: p1;
>>     lineTo: p2;
>>     arcTo: p3 radius: radius angleOfXAxis: 0 largeFlag: false
>>     sweepFlag: true;
>>     lineTo: p4;
>>     arcTo: p1 radius: radius angleOfXAxis: 0 largeFlag: false
>>     sweepFlag: true.
>>
>>     -- 
>>     R. Mark Volkmann
>>     Object Computing, Inc.
>
>
>     -- 
>     Juan Vuletich
>     cuis.st  <http://cuis.st>
>     github.com/jvuletich  <http://github.com/jvuletich>
>     researchgate.net/profile/Juan-Vuletich  <http://researchgate.net/profile/Juan-Vuletich>
>     independent.academia.edu/JuanVuletich  <http://independent.academia.edu/JuanVuletich>
>     patents.justia.com/inventor/juan-manuel-vuletich  <http://patents.justia.com/inventor/juan-manuel-vuletich>
>     linkedin.com/in/juan-vuletich-75611b3  <http://linkedin.com/in/juan-vuletich-75611b3>
>     twitter.com/JuanVuletich  <http://twitter.com/JuanVuletich>
>
>
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc.


-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250312/fcaf0c84/attachment.htm>


More information about the Cuis-dev mailing list