Skip to content

Instantly share code, notes, and snippets.

@TvoozMagnificent
Created August 27, 2022 10:02
Show Gist options
  • Save TvoozMagnificent/eb85299e46bedfae3bae5ed4448c96b6 to your computer and use it in GitHub Desktop.
Save TvoozMagnificent/eb85299e46bedfae3bae5ed4448c96b6 to your computer and use it in GitHub Desktop.
Plotter 2D using turtle
import turtle
import time
t = time.time_ns
turtle_ = turtle.Turtle()
turtle_.penup()
turtle_.hideturtle()
turtle.speed('fastest')
turtle.tracer(0, 0)
height = 500*2
current_time = t()
while t()-3_000_000_000 < current_time: turtle.update()
def point(x, y):
turtle_.goto(x, y)
turtle_.pendown()
turtle_.showturtle()
turtle_.stamp()
turtle_.hideturtle()
turtle_.penup()
def plot(function, start, stop, step):
if color is not None:
turtle.color(color)
turtle.pencolor(color)
rang_ = stop-start
value = start
while value <= stop:
try:
point((value-start)/rang_*height-height/2, function(value)/rang_*height)
except Exception as e:
print(value, e)
value+=step
print(f'{value} done for function {function.__name__}')
print(f'function {function.__name__} done')
turtle.update()
def plots(functions, start, stop, step, color=None):
for function in functions:
plot(function, start, stop, step)
from math import sin, cos, tan
plots([sin, cos], 0, 6.28, 0.001) # change this
turtle.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment