parametric_graphing.py

Created by ferr0fluidmann

Created on October 22, 2019

1.08 KB

Plot parametric graphs with parametric_graph(x_function, y_function, tMin, tMax).


from math import *
from kandinsky import *
from turtle import *
#from my_functions import *

tMin = 0
tMax = 2*pi

def x_function(x):
  return sqrt(x)
  
def y_function(x):
  return x
  
def parametric_graph(it=1000,fx=x_function,fy=y_function,tmax=tMax,tmin=tMin,xmin=-14.4,xmax=14.4,ymin=-10,ymax=10):
  col=color(0,0,255)
  blk=color(0,0,0)
  gry=color(220, 220, 220)
  y_0=int(ymax*221/(ymax-ymin))
  x_0=int(xmin*319/(xmin-xmax))
  gridx = int(xmin)
  while gridx <= xmax:
    x=int(319.0*(gridx-xmin)/(xmax-xmin))
    for y in range(222):
      set_pixel(x,y,gry)
    gridx+=1
  gridy = int(ymin)
  while gridy <= ymax:
    y=int(221.0*(gridy-ymin)/(ymax-ymin))
    for x in range(320):
      set_pixel(x,y,gry)
    gridy+=1
  for x in range(320):
    set_pixel(x,y_0,blk)
  for y in range(222):
    set_pixel(x_0,y,blk)
  for t in range(it):
    T = tmin+t*(tmax-tmin)/float(it)
    try:
      X=fx(T)
      Y=fy(T)
      pixel_x=int((X-xmin)*319/(xmax-xmin))
      pixel_y=int((Y-ymax)*221/(ymin-ymax))
      set_pixel(pixel_x,pixel_y,col)
    except:
      X=0
      Y=0

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.