'_OE
_TITLE "If these curves were smoother they'd steal your wife."
' Hardware
' Meta
' Data structures
' Object type
' Object storage
' Initialize
ShapeCount = 0
' Main loop
TheReturn = 0
' Keyboard input
CALL NewMouseShape
(7.5, 400, 15)
MasterDraw = ""
CALL cPrintstring
(16 * 17, "PRESS SPACE and then drag MOUSE 1 to draw a new shape.") z$
= "c" + STR$(Shape
(k
).Shade
) + " " FOR i
= 1 TO Shape
(k
).Elements
- 1 x1 = PointChain(k, i).x
y1 = PointChain(k, i).y
x2 = PointChain(k, i + 1).x
y2 = PointChain(k, i + 1).y
'CALL lineSmooth(x1, y1, x2, y2, Shape(k).Shade)
'''
' Fellippe, this was it ...
dr
= SQR((x2
- x1
) ^ 2 + (y2
- y1
) ^ 2) ang
= (180 / 3.1416 * ATN((y2
- y1
) / (x2
- x1
))) ang = 180 + ang
z$
= z$
+ "TA " + STR$(ang
- 90) + " U" + STR$(dr
) + " " '''
' Make a point to get DRAW started.
CALL cPset
(PointChain
(k
, 1).x
, PointChain
(k
, 1).y
, Shape
(k
).Shade
) ' Draw replaces CLine.
MasterDraw = MasterDraw + z$ + "___"
ShapeCount = ShapeCount + 1
numpoints = 0
xold = 999 ^ 999
yold = 999 ^ 999
delta
= SQR((x
- xold
) ^ 2 + (y
- yold
) ^ 2) IF (delta
> rawresolution
) AND (numpoints
< targetpoints
- 1) THEN numpoints = numpoints + 1
PointChain(ShapeCount, numpoints).x = x
PointChain(ShapeCount, numpoints).y = y
xold = x
yold = y
DO WHILE (numpoints
< targetpoints
) rad2max = -1
kmax = -1
FOR k
= 1 TO numpoints
- 1 xfac = PointChain(ShapeCount, k).x - PointChain(ShapeCount, k + 1).x
yfac = PointChain(ShapeCount, k).y - PointChain(ShapeCount, k + 1).y
rad2 = xfac ^ 2 + yfac ^ 2
kmax = k
rad2max = rad2
PointChain(ShapeCount, j + 1).x = PointChain(ShapeCount, j).x
PointChain(ShapeCount, j + 1).y = PointChain(ShapeCount, j).y
PointChain(ShapeCount, kmax + 1).x = (1 / 2) * (PointChain(ShapeCount, kmax).x + PointChain(ShapeCount, kmax + 2).x)
PointChain(ShapeCount, kmax + 1).y = (1 / 2) * (PointChain(ShapeCount, kmax).y + PointChain(ShapeCount, kmax + 2).y)
numpoints = numpoints + 1
FOR j
= 1 TO smoothiterations
FOR k
= 2 TO numpoints
- 1 TempChain(ShapeCount, k).x = (1 / 2) * (PointChain(ShapeCount, k - 1).x + PointChain(ShapeCount, k + 1).x)
TempChain(ShapeCount, k).y = (1 / 2) * (PointChain(ShapeCount, k - 1).y + PointChain(ShapeCount, k + 1).y)
FOR k
= 2 TO numpoints
- 1 PointChain(ShapeCount, k).x = TempChain(ShapeCount, k).x
PointChain(ShapeCount, k).y = TempChain(ShapeCount, k).y
Shape(ShapeCount).Elements = numpoints
SelectedShape = ShapeCount
'Credit: FellippeHeitor qb64.org (2020)
' Adapted from https://en.wikipedia.org/w/index.php?title=Xiaolin_Wu%27s_line_algorithm&oldid=852445548
'Edit: Correction to alpha channel (2020-11-20)
steep
= ABS(y1
- y0
) > ABS(x1
- x0
)
dx = x1 - x0
dy = y1 - y0
gradient = dy / dx
gradient = 1
'handle first endpoint
DIM xend
, yend
, xgap
, xpxl1
, ypxl1
yend = y0 + gradient * (xend - x0)
xgap
= (1 - ((x0
+ .5) - INT(x0
+ .5))) xpxl1 = xend 'this will be used in the main loop
plX = ypxl1
plY = xpxl1
plI
= (1 - (yend
- INT(yend
))) * xgap
plX = ypxl1 + 1
plY = xpxl1
plI
= (yend
- INT(yend
)) * xgap
plX = xpxl1
plY = ypxl1
plI
= (1 - (yend
- INT(yend
))) * xgap
plX = xpxl1
plY = ypxl1 + 1
plI
= (yend
- INT(yend
)) * xgap
intery = yend + gradient 'first y-intersection for the main loop
'handle second endpoint
yend = y1 + gradient * (xend - x1)
xgap
= ((x1
+ .5) - INT(x1
+ .5)) xpxl2 = xend 'this will be used in the main loop
plX = ypxl2
plY = xpxl2
plI
= (1 - (yend
- INT(yend
))) * xgap
plX = ypxl2 + 1
plY = xpxl2
plI
= (yend
- INT(yend
)) * xgap
plX = xpxl2
plY = ypxl2
plI
= (1 - (yend
- INT(yend
))) * xgap
plX = xpxl2
plY = ypxl2 + 1
plI
= (yend
- INT(yend
)) * xgap
'main loop
FOR x
= xpxl1
+ 1 TO xpxl2
- 1 plY = x
plI
= (1 - (intery
- INT(intery
)))
plY = x
plI
= (intery
- INT(intery
))
intery = intery + gradient
FOR x
= xpxl1
+ 1 TO xpxl2
- 1 plX = x
plI
= (1 - (intery
- INT(intery
)))
plX = x
plI
= (intery
- INT(intery
))
intery = intery + gradient
plot:
' Change to regular PSET for standard coordinate orientation.