' Display
_TITLE "If these curves were smoother they'd steal your wife."
' Meta
start:
' Data structures
' Object type
' Object storage
' Initialize
ShapeCount = 0
' Main loop
TheReturn = 0
' Keyboard input
CALL NewMouseShape
(7.5, 150, 15) UserInput = TheReturn
CALL cprintstring
(16 * 17, "PRESS SPACE and then drag MOUSE 1 to draw a new shape.") FOR ShapeIndex
= 1 TO ShapeCount
FOR i
= 1 TO Shape
(ShapeIndex
).Elements
- 1 CALL lineSmooth
(PointChain
(ShapeIndex
, i
).x
, PointChain
(ShapeIndex
, i
).y
, PointChain
(ShapeIndex
, i
+ 1).x
, PointChain
(ShapeIndex
, i
+ 1).y
, Shape
(ShapeIndex
).Shade
)
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
'translated from
'https://en.wikipedia.org/w/index.php?title=Xiaolin_Wu%27s_line_algorithm&oldid=852445548
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.