Skip to content

Instantly share code, notes, and snippets.

@yuriks
Created March 12, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriks/d20a9b382b18ea7e170362ea506929c4 to your computer and use it in GitHub Desktop.
Save yuriks/d20a9b382b18ea7e170362ea506929c4 to your computer and use it in GitHub Desktop.
Befunge-98 wrapping
dpx = 0
dpy = 0
bx1 = 0
bx2 = 180
by1 = 0
by2 = 909
if 0:
px_s = -2
py_s = 18
dpx = -1
dpy = 0
bx1 = 0
bx2 = 180
by1 = 0
by2 = 909
if 0:
px_s = -1
py_s = 17
dpx = -1
dpy = 0
if 0:
px_s = -2
py_s = 99
dpx = -1
if 0:
px_s = 181
py_s = 40
dpx = 1
if 0:
px_s = 181
py_s = 54
dpx = 1
bx1 = -3
bx2 = 180
by1 = -2
by2 = 909
if 0:
px_s = 192
py_s = 69
dpx = 13
dpy = 2
bx1 = -3
bx2 = 180
by1 = -2
by2 = 909
def manual():
px = px_s
py = py_s
def inbounds():
return (px >= bx1 and px <= bx2) and (py >= by1 and py <= by2)
while not inbounds():
px -= dpx
py -= dpy
print("at ({}, {})".format(px, py))
while inbounds():
px -= dpx
py -= dpy
print("at ({}, {})".format(px, py))
px += dpx
py += dpy
print("[manual] Started at ({}, {}), end at ({}, {})".format(px_s, py_s, px, py))
def mathy():
px = px_s
py = py_s
x_steps = 999999999999
y_steps = 999999999999
if dpx < 0:
x_steps = int((px - bx2) / dpx)
elif dpx > 0:
x_steps = int((px - bx1) / dpx)
if dpy < 0:
y_steps = int((py - by2) / dpy)
elif dpy > 0:
y_steps = int((py - by1) / dpy)
steps = min(x_steps, y_steps)
print("[mathy] x_steps {}, y_steps {}".format(x_steps, y_steps))
px -= steps * dpx
py -= steps * dpy
print("[mathy] Started at ({}, {}), end at ({}, {})".format(px_s, py_s, px, py))
manual()
mathy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment