-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
127 lines (113 loc) · 5.5 KB
/
main.py
File metadata and controls
127 lines (113 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import numpy as np
import settings
import pickle
import exact
import help
import datastorage
# set global variable system and N
settings.init()
# Define menu items
# Define used variables
menuItems = np.array(["Choose type of Lindenmayer system and number of iterations", "Generate plots", "Change number of iterations", "Save current L-system", "Factory reset of loaded L-systems", "Quit"])
# Start
while True:
# Display menu options and ask user to choose a menu item
choice = help.displayMenu(menuItems, "\nPlease choose a menu item: ")
# Menu item chosen
# ------------------------------------------------------------------
# 1. Load data
if choice == 1:
settings.SystemsList = np.array(["Koch curve","Sierpinski triangle"])
# load previously saved systems
loaded_systems = list(datastorage.loadall('systems.dat'))
# load all systems, update the settings list and add user defined option
for sys in loaded_systems:
settings.SystemsList = np.append(settings.SystemsList, sys.name)
settings.SystemsList = np.append(settings.SystemsList, "User defined")
# Ask user which type of Lindenmayer system to use
Systemnumber = int(help.displayMenu(settings.SystemsList, "\nplease enter the Lindenmayer system you would like to work with: "))
settings.System = settings.SystemsList[Systemnumber-1]
# Have to rename the systems, since this is the input they need in LindIter()
if settings.System == "Koch curve":
settings.System = "Koch"
elif settings.System == "Sierpinski triangle":
settings.System = "Sierpinski"
# To ask the user of the amount of iterations, and to tell them if they choose a lot of iterations if they're certain they want to continue
while True:
settings.N = help.inputInt("\nPlease choose the amount of iterations (recommended 0-9): ")
if settings.N < 0:
print("Iterations cannot be less than 0")
elif settings.N > 9:
while True:
print("\nLarge amount of iterations, might have a long computing time")
svar = input('Do you still wish to continue (y/n): ')
if svar.lower() == "y" or svar.lower() == "n":
break
else:
print('\nPlease input either y or n')
if svar.lower == "n":
pass
else:
break
else:
break
if settings.System == 'User defined':
help.selfDefinedSystem() # asks for user input for the self defined system. Saves input globally.
# ------------------------------------------------------------------
# 2. Generate plot
elif choice == 2:
# Is there chosen system and iteration?
if settings.System == "":
# Display error message
print("\nError: No system and iteration chosen, please choose those")
else:
LindenmayerString = exact.LindIter(settings.System,settings.N)
turtleCommands = exact.turtleGraph(LindenmayerString)
exact.turtlePlot(turtleCommands)
# ------------------------------------------------------------------
# 3. Change number of iterations
elif choice == 3:
# Is there chosen system and iteration?
if settings.System == "":
# Display error message
print("\nError: No system and iteration chosen, please choose those")
else:
settings.N = help.inputInt("\nPlease choose the amount of iterations (recommended 0-9): ")
# ------------------------------------------------------------------
# 4. Save current system
elif choice == 4:
# Is there chosen system and iteration?
if settings.System == "":
# Display error message
print("\nError: No system and iteration chosen, please choose those")
elif settings.System == 'Sierpinski' or settings.System == 'Koch':
print('\nSierpinski and Koch are already defined, these cannot be saved')
else:
while True:
answer = input("Do you wish to rename the current L-system from " + settings.name + ' (y/n)? ')
if answer == 'y':
settings.name = input('What do you want to save it as?\n')
break
elif answer == 'n':
break
# Dump the new system along with all preexisting ones
current_system = datastorage.system(settings.name, settings.lettermapping, settings.selfdefined_start, settings.iteration_scaling) # create system based on system class
previous_systems = datastorage.loadall('systems.dat')
list_of_loaded_systems = []
for sys in loaded_systems:
list_of_loaded_systems = list_of_loaded_systems + [sys]
with open('systems.dat', 'wb') as systemsfile:
for s in list_of_loaded_systems:
pickle.dump(s, systemsfile) # Dump all preexisting systems
pickle.dump(current_system, systemsfile) # Dump new system to pickle
# Update the list of loaded systems
loaded_systems = list(datastorage.loadall('systems.dat'))
# ------------------------------------------------------------------
# 5. Factory reset of loaded L-systems
elif choice == 5:
help.factoryReset()
# ------------------------------------------------------------------
# 6. Quit
elif choice == 6:
# End
break