Compare commits

...

14 Commits

2 changed files with 44 additions and 23 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -1,4 +1,4 @@
from math import sin, cos, pi, sqrt, asin
from math import sin, cos, pi, asin
from tkinter import *
laby_w, laby_h = 20, 12
@ -6,8 +6,8 @@ laby_w, laby_h = 20, 12
wl = [676499, 819210, 704161, 828804, 911396, 1010837, 772540, 600182, 526017, 803480, 756064, 701196, 1756736, 1376344, 1158834, 1315990, 1102792, 1323847, 1497194, 1810708, 1327018, 1094903, 1349813]
zint = 2
screen_w, screen_h = laby_w * 50 + 2, laby_h * 50 + 2
zx, zy = (screen_w - zint) / laby_w, (screen_h - zint) / laby_h
zx, zy = 50, 50
screen_w, screen_h = laby_w * zx + zint, laby_h * zy + zint
master = Tk()
master.resizable(0, 0)
@ -21,7 +21,7 @@ def escape(event):
def add(event):
global path, index
if len(path) < 28:
if len(path) < 24:
index += 1
path.append((0.0, 0.5))
aller_selon(path)
@ -81,12 +81,12 @@ def print_code(event):
master.bind('<Escape>', escape)
master.bind('<Return>', add)
master.bind('<BackSpace>', remove)
master.bind('<Prior>', previous)
master.bind('<Next>', next)
master.bind('<Control-Left>', previous)
master.bind('<Control-Right>', next)
master.bind('<Left>', lambda e: left(e, 0.1))
master.bind('<Right>', lambda e: right(e, 0.1))
master.bind('<Shift-KeyPress-Left>', lambda e: left(e, 0.01))
master.bind('<Shift-KeyPress-Right>', lambda e: right(e, 0.01))
master.bind('<Shift-Left>', lambda e: left(e, 0.01))
master.bind('<Shift-Right>', lambda e: right(e, 0.01))
master.bind('<Up>', up)
master.bind('<Down>', down)
master.bind('p', print_code)
@ -96,33 +96,54 @@ canvas = Canvas(master, width = screen_w, height = screen_h + 68, bg = 'white')
canvas.pack()
def clean_screen():
global canvas
canvas.delete('all')
def draw_rect(x, y, w, h, color):
global canvas
x += 1
y += 1
canvas.create_rectangle(x, y, x + w, y + h, fill = color, outline = '')
def draw_line(x1, y1, x2, y2, color):
global canvas
canvas.create_line(x1 + 1, y1 + 1, x2 + 1, y2 + 1, fill = color, width = 2.0)
def draw_help():
help = 'change angle: [Shift+] Left/Right, change length: Up/Down, add/remove element: Enter/BackSpace, previous/next element: PgUp/PgDn, print code: P, exit: Esc'
global canvas
help = 'change angle: [Shift+]Left/Right, change length: Up/Down, add/remove element: Enter/BackSpace, previous/next element: Ctrl+Left/Right, print code: P, exit: Esc'
canvas.create_text(4, screen_h + 36, anchor = NW, text = help, fill = 'black')
def draw_path():
global path
canvas.create_text(4, screen_h + 4, anchor = NW, text = '%s' % path[0:14], fill = 'black')
canvas.create_text(4, screen_h + 20, anchor = NW, text = '%s' % path[14:28], fill = 'black')
global canvas, path
for i in range(len(path)):
if i == index:
color = 'red'
else:
color = 'blue'
if i < 12:
y = 0
else:
y = 16
canvas.create_text(4 + (i % 12) * 80, screen_h + 4 + y, anchor = NW, text = '(%5.2f, %3.1f)' % path[i], fill = color)
def draw_score(score):
canvas.create_text(4, screen_h + 52, anchor = NW, text = 'score: %f' % score, fill = 'black')
def draw_score(state):
global canvas
canvas.create_text(4, screen_h + 52, anchor = NW, text = 'score: %18.14f (state[6]: %5.1f, state[7]: %5.1f)' % (state[5], state[6], state[7]), fill = 'black')
def fix_angle(a):
return a * 2 * asin(1) / pi
def cout(x):
return len(str(round(abs(x)/1.,5)))
n, c = 5, 1
x = round(abs(x) * 10**n)
if x:
c = max(n + 1 - len(str(x)), 0)
while n and not (x % 10):
x = x // 10
n -= 1
c += not n
return 1 + len(str(x)) + c
def tourner(a):
global state
@ -132,6 +153,7 @@ def tourner(a):
def avancer(l, color):
global state
start = state[0:2]
t = fix_angle(state[2])
dx, dy = cos(t), sin(t)
state[7] += l
@ -148,11 +170,11 @@ def avancer(l, color):
t = dx <= 0 or int(x) < laby_w - 1 or int(y) < laby_h - 1
if t and tx or ty or (drx and dry and (t and tx or ty)) or (drx and dry and (t and vw(iy, laby_w - 2 - min(ix, ix - drx)) or hw(min(iy, iy - dry), laby_w - 1 - ix))):
state[5] += 15
return
break
l -= .25
state[6] += (state[6] < 200)
state[0:2] = (x, y)
draw_line(state[3] * zx, state[4] * zy, state[0] * zx, state[1] * zy, color)
draw_line(start[0] * zx, start[1] * zy, state[0] * zx, state[1] * zy, color)
def aller_selon(path):
global state
@ -168,20 +190,19 @@ def aller_selon(path):
if y < laby_h:
draw_rect(x * zx, y * zy, zint, zy + zint, 'black')
else:
pass
draw_rect(x * zx, (y - laby_h + 1) * zy, zx + zint, zint, 'black')
for i in range(len(path)):
tourner(path[i][0])
if i == index:
avancer(path[i][1], 'red')
color = 'red'
else:
avancer(path[i][1], 'blue')
color = 'blue'
avancer(path[i][1], color)
state[5] += sin(fix_angle(state[7])) - state[6] // 2
draw_help()
draw_path()
draw_score(state[5])
draw_score(state)
aller_selon(path)
if __name__== "__main__":
master.mainloop()
master.mainloop()