[Cuis-dev] AbstractVectorCanvas method to draw ovals
Mark Volkmann
r.mark.volkmann at gmail.com
Wed Mar 5 11:19:41 PST 2025
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250305/d1d486a6/attachment-0001.htm>
More information about the Cuis-dev
mailing list