CCCPaste

# tk_recaman.py

# tk_recaman.py

from tkinter import *
import math

w = 1200
h = 600
span = 5

root = Tk()
root.geometry("+0+0")

frame = Frame(root)
frame.pack(fill=BOTH, expand=True)

h_scroll = Scrollbar(frame, orient=HORIZONTAL)
h_scroll.pack(side=BOTTOM, fill=X)

c = Canvas(frame, width=w, height=h, xscrollcommand=h_scroll.set, bg='white')
c.pack(side=LEFT, fill=BOTH, expand=True)
h_scroll.config(command=c.xview)

used = {0}
current = 0
n = 0
y = h // 2

cv_w = w

def recaman():
	global n, current, cv_w

	prev = current
	candidate = current - n
	if candidate > 0 and candidate not in used:
		current = candidate
	else:
		current = current + n
	used.add(current)

	r = abs(current - prev) * 2.5
	x1 = min(prev, current) * span
	x2 = max(prev, current) * span
	
	s = 0
	if n % 2:
		s = 180
	
	c.create_arc(x1, y - r, x2, y + r, start=s, extent=180, style='arc')

	cv_w = max(cv_w, current * span)
	c.config(scrollregion=(0, 0, (cv_w), h))

	n += 1
	root.after(500, recaman)

recaman()
root.mainloop()