mirror of
https://github.com/dschmenk/PLASMA.git
synced 2026-01-22 18:15:59 +00:00
Use fractional coordinates to improve angular movement accuracy
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,7 @@ const CLIP_RIGHT = 2
|
||||
const CLIP_TOP = 4
|
||||
const CLIP_BOTTOM = 8
|
||||
|
||||
var turtleX, turtleY, turtleAngle, drawLine
|
||||
var turtleXp4, turtleYp4, turtleAngle, drawLine
|
||||
byte pen
|
||||
var clipLeft, clipRight, clipTop, clipBottom
|
||||
|
||||
@@ -35,7 +35,7 @@ def lerp(a1, b1, a2, b2, n)#1
|
||||
word[2] i32
|
||||
|
||||
if b2 == b1; return b1; fin // Horizontal lerp
|
||||
if a2 == a1; return n; fin // Vertical lerp
|
||||
if a2 == a1; return n; fin // Vertical lerp
|
||||
loadi16(b2 - b1)
|
||||
muli16(n - a1)
|
||||
divi16(a2 - a1)
|
||||
@@ -105,8 +105,8 @@ end
|
||||
export def initTurtle(width, height, linefunc)#0
|
||||
drawLine = linefunc
|
||||
clipRect(0, 0, width - 1, height - 1)
|
||||
turtleX = width / 2
|
||||
turtleY = height / 2
|
||||
turtleXp4 = width << 3
|
||||
turtleYp4 = height << 3
|
||||
turtleAngle = 0
|
||||
pen = 1
|
||||
end
|
||||
@@ -127,18 +127,26 @@ end
|
||||
|
||||
export def moveTo(x, y)#0
|
||||
if pen
|
||||
clipLine(turtleX, turtleY, x, y)
|
||||
clipLine(turtleXp4 >> 4, turtleYp4 >> 4, x, y)
|
||||
fin
|
||||
turtleX = x
|
||||
turtleY = y
|
||||
turtleXp4 = x << 4
|
||||
turtleYp4 = y << 4
|
||||
end
|
||||
|
||||
export def moveForward(dist)#0
|
||||
moveTo(turtleX + mulcos(dist, turtleAngle), turtleY + mulsin(dist, turtleAngle))
|
||||
var oldX, oldY
|
||||
|
||||
oldX = turtleXp4 >> 4
|
||||
oldY = turtleYp4 >> 4
|
||||
turtleXp4 = turtleXp4 + mulcos(dist << 4, turtleAngle)
|
||||
turtleYp4 = turtleYp4 + mulsin(dist << 4, turtleAngle)
|
||||
if pen
|
||||
clipLine(turtleXp4 >> 4, turtleYp4 >> 4, oldX, oldY)
|
||||
fin
|
||||
end
|
||||
|
||||
export def moveBackward(dist)#0
|
||||
moveTo(turtleX - mulcos(dist, turtleAngle), turtleY - mulsin(dist, turtleAngle))
|
||||
moveForward(-dist)
|
||||
end
|
||||
|
||||
export def penUp#0
|
||||
|
||||
Reference in New Issue
Block a user