Sunday, August 4, 2024

TI-84 Plus CE Python: Drawing Shapes with the ti_plotlib module

 TI-84 Plus CE Python: Drawing Shapes with the ti_plotlib module


Introduction


Here are four scripts to draw shapes:


RECT8: rectangles and squares centered at (0, 0)

ELLIPSE8: ellipses and circles centered at (0, 0)

POLYGON8: polygons given the vertex points and number of vertices

INVFUNC8: draws a function f(x) and it’s inverse f^-1(x). Define the function is defined in the f(x) subroutine in the program.


The plot window is sized in sync with the TI-84’s screen size (320 pixels x 220 pixels) so that squares look like squares and circles look like circles. The window parameters are set as such:

Xmin = -16, Xmax = 16

Ymin = -10.5, Ymax = 10.5



TI-84 PLUS CE Python Script: RECT8.py





import ti_plotlib as plt

from math import *


# draw an rectangle using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")

a=eval(input("horiz. length? "))

b=eval(input("vert. length? "))


# plot routine

plt.cls()

plt.title("Rectangle")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")


# color: blue

plt.color(0,0,192)


# pen size

plt.pen("medium","solid")


plt.line(-a/2,b/2,a/2,b/2,"")

plt.line(-a/2,-b/2,a/2,-b/2,"")

plt.line(-a/2,-b/2,-a/2,b/2,"")

plt.line(a/2,-b/2,a/2,b/2,"")


plt.show_plot()


TI-84 PLUS CE Python Script: ELLIPSE8.py





import ti_plotlib as plt

from math import *


# draw an ellipse using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")

a=eval(input("x axis? "))

b=eval(input("y axis? "))


# plot routine

plt.cls()

plt.title("Ellipse")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.pen("medium","solid")

plt.grid(1,1,"dot")


# color: green

plt.color(0,192,0)


for i in range(128):

  x=a*cos(i*pi/64)

  y=b*sin(i*pi/64)

  plt.plot(x,y,"o")


plt.show_plot()



TI-84 PLUS CE Python Script: POLYGON8.py





import ti_plotlib as plt

from math import *


# draw an rectangle using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")


n=int(input("# of vertices? "))

a=eval(input("x1? "))

b=eval(input("y1? "))


x=[a]

y=[b]


for i in range(n-1):

  print("vertex ",i+2)

  c=eval(input("x? "))

  d=eval(input("y? "))

  x.append(c)

  y.append(d)

x.append(a)

y.append(b)



# plot routine

plt.cls()

plt.title("Polygon")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")

plt.color(75,0,130)

plt.pen("medium","solid")


for i in range(n):

  x0=x[i]

  y0=y[i]

  x1=x[i+1]

  y1=y[i+1]

  plt.line(x0,y0,x1,y1,"")


plt.show_plot()



TI-84 PLUS CE Python Script: INVFUNC8.py





Define f(x) in the def f(x) function routine. The math module is imported.



import ti_plotlib as plt

from math import *


# f(x) and f**-1(x)

# define f(x)

def f(x):

  return x**2+6


# plot routine

plt.cls()

plt.title("f(x) and its inverse")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")


plt.pen("medium","solid")


for i in range(320):

  x=-16+i*32/320

  y=f(x)

  plt.color(0,0,192)

  plt.plot(x,y,"o")

  plt.color(255,165,0)

  plt.plot(y,x,"o")



plt.show_plot()



Download the four scripts here: https://drive.google.com/file/d/1ELL6mEzMXrIJlOSSFocOZGJTza-kBZoU/view?usp=sharing



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...