This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
147 lines (130 loc) · 4.72 KB
/
main.pyw
File metadata and controls
147 lines (130 loc) · 4.72 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Python Graphing Calculator
# Version 1.39
# Import Libraries
import math
import turtle
turtle = turtle.Turtle()
turtle.hideturtle()
turtle.speed(0)
# "Move" Subroutine
def move(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
def draw_axis(resolution):
turtle.width(3)
move(resolution, 0)
turtle.setx(-resolution)
move(0, 0)
move(0, resolution)
turtle.sety(-resolution)
def draw_gridlines(resolution):
turtle.width(1)
move(-resolution, -resolution)
turtle.sety(resolution)
turtle.setx(resolution)
turtle.sety(-resolution)
turtle.setx(-resolution)
for offset in range(-resolution, resolution + 1):
move(offset, resolution)
turtle.sety(-resolution)
for offset in range(-resolution, resolution + 1):
move(resolution, offset)
turtle.setx(-resolution)
def get_float_input(prompt_title):
return float(turtle.screen.textinput("Input", prompt_title))
def get_confirm_input(prompt_title, buttons):
return turtle.screen.textinput("Input", f"{prompt_title} ({'/'.join(buttons)})")
def draw_line():
lineType = get_confirm_input("Angle or Straight Line?", ["Angled", "Straight"])
if lineType == "Angled":
slope = get_float_input("Slope")
intercept = get_float_input("Intercept")
move(-resolution, (resolution * slope) + intercept)
turtle.goto(resolution, -((resolution * slope) + intercept))
elif lineType == "Straight":
axis = get_confirm_input("Axis", ["X", "Y"])
intercept = get_float_input("Intercept")
if axis == "Y":
move(-resolution, intercept)
turtle.setx(resolution)
elif axis == "X":
move(intercept, -resolution)
turtle.sety(resolution)
def draw_parabola():
functionType = get_confirm_input("Parabola Type", ["X", "Y"])
slope = get_float_input("Slope")
intercept = get_float_input("Intercept")
if functionType == "Y":
for x in range(-resolution, resolution + 1):
y = ((x ** 2) * slope) + intercept
if x == -resolution:
move(x, y)
else:
turtle.goto(x, y)
elif functionType == "X":
for y in range(-resolution, resolution + 1):
x = ((y ** 2) * slope) + intercept
if x == -resolution:
move(x, y)
else:
turtle.goto(x, y)
def draw_circle():
radius = get_float_input("Radius")
xOrigin = get_float_input("X Point Origin")
yOrigin = get_float_input("Y Point Origin")
move(xOrigin, yOrigin - radius)
turtle.circle(radius, None, resolution)
def draw_trig():
trigType = get_confirm_input("Trig Type", ["Sin", "Cos"])
functionType = get_confirm_input("Function Type", ["X", "Y"])
a = get_float_input("Amplitude (a)")
b = get_float_input("Frequency (b)")
c = get_float_input("Horizontal Shift (c)")
d = get_float_input("Vertical Shift (d)")
if functionType == "Y":
for x in range(-resolution, resolution + 1):
y = a * (math.sin if trigType == "Sin" else math.cos)((b * x) + c) + d
if x == -resolution:
move(x, y)
else:
turtle.goto(x, y)
elif functionType == "X":
for y in range(-resolution, resolution + 1):
x = a * (math.sin if trigType == "Sin" else math.cos)((b * y) + c) + d
if y == -resolution:
move(x, y)
else:
turtle.goto(x, y)
def change_settings():
settingsType = get_confirm_input("What Setting Would You Like To Change?", ["Line Width", "Line Color", "Reset to Default Settings"])
if settingsType == "Line Width":
turtle.width(get_float_input("Line Width"))
elif settingsType == "Line Color":
turtle.color(get_confirm_input("Line Color:", ["Black", "Blue", "Red", "Yellow", "Green"]))
elif settingsType == "Reset to Default Settings":
turtle.width(2)
turtle.color("black")
resolution = int(turtle.screen.textinput("Input", "Enter grid resolution"))
turtle.screen.tracer(False)
turtle.screen.screensize(600, 600)
turtle.screen.setworldcoordinates(-resolution, -resolution, resolution, resolution)
turtle.screen.title("Main Graph")
draw_axis(resolution)
draw_gridlines(resolution)
turtle.width(2)
turtle.color("black")
graphType = ""
while graphType != "Finish":
move(0, 0)
graphType = get_confirm_input("Graph Type:", ["Line", "Parabola", "Circle", "Trig", "Settings", "Finish"])
if graphType == "Line":
draw_line()
elif graphType == "Parabola":
draw_parabola()
elif graphType == "Circle":
draw_circle()
elif graphType == "Trig":
draw_trig()
elif graphType == "Settings":
change_settings()