Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Importing time so you can see how long generation took
- import time
- #Screen size finder shamelessly stolen from StackOverflow
- import ctypes
- user32=ctypes.windll.user32
- width=user32.GetSystemMetrics(0)
- height=user32.GetSystemMetrics(1)
- middle=height/2
- #Preparing variables for sequence generator
- #limit is how far the sequence is generated for
- print("Recaman sequence generator by u/-Kasai-")
- limit=int(input("How many numbers do you want generated? "))
- sequence=[0]
- location=0
- #Generator loop
- print("Generating sequence...")
- start_time=time.time()
- for i in range(1,limit):
- if location-i>0 and location-i not in sequence:
- location-=i
- sequence.append(location)
- else:
- location+=i
- sequence.append(location)
- #print(sequence)
- #^ You can delete the hashtag above and see the sequence in the shell
- #Zoom dictates the pixel to number ratio
- #Zoom is auto-fit to sequence limit. If you wanted, you could continue the sequence for a true image, but things get a bit messy
- #Originally zoom was based off the size of the sequence. It's now set to just fit the sequence from end to end
- zoom=width/max(sequence)
- #Drawing the tkinter canvas
- print("Drawing...")
- from tkinter import *
- Tk=Tk()
- Screen=Canvas(Tk,width=width,height=height)
- #Adding white background
- Screen.create_rectangle(0,0,width,height,fill='#ffffff')
- Screen.pack()
- #This function draws the semicircles that make up the pattern
- def semicircle(start,end,direction):
- if direction=='up':
- starting=0
- elif direction=='down':
- starting=180
- #The middle variable here is half the screen height, as defined earlier. Changing the middle variable will shift the sequence up or down vertically
- Screen.create_arc(start,middle-abs((start-end)/2),end,middle+abs((start-end)/2),style=ARC,start=starting,extent=180)
- #This variable dictates whether the first step will go up or down. Numberphile goes down. Change it to 'up' if you want!
- direct='down'
- #This loop draws the pattern
- for i in range(len(sequence)-1):
- semicircle(sequence[i]*zoom,sequence[i+1]*zoom,direct)
- if direct=='up':
- direct='down'
- else:
- direct='up'
- #Finding the ending time
- end_time=time.time()
- print("Done!")
- print("Generated and drawn in", round(end_time-start_time,4), "seconds.")
- print("Drawing should be in another window.")
- print("\nProgram created by u/-Kasai-")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement