-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexponent-plot.py
executable file
·51 lines (40 loc) · 1.1 KB
/
exponent-plot.py
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
#!/usr/bin/env python3
import turtle
import math
def main(pen_color = (1, 1/2, 0), bg_color = "black"):
# Function to draw a point at a given (x, y) coordinate
def draw_point(x, y, color=pen_color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.dot(2, pen_color)
# Function to draw a point at a given (x, y) coordinate
def draw_tack(x, y, color=pen_color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.seth(90)
turtle.pencolor(color)
turtle.forward(10)
turtle.pencolor(pen_color)
# Set up the turtle
turtle.hideturtle()
turtle.tracer(20,0)
turtle.bgcolor(bg_color)
turtle.pencolor(pen_color)
scale = 20
grid = range(-30, 30)
# Draw X and Y axis
for point in grid:
draw_point(0, point * 20)
draw_point(point * scale, 0)
# Y = X²
for x in grid:
y = x * x
draw_tack(x * scale, y * 2, 'cyan')
# Y = X³
for x in grid:
y = x * x * x
draw_tack(x * scale, y * 0.5, 'red')
turtle.done()
main()