TI-84 Plus CE Python: Drawing Random Paths
The Python script PATHS draws a path from the left side to one of the other three sides of the screen: bottom, right, or up.
The path is laid on a 70 x 70 grid, consisting on 10 x 10 blocks. Due to the how the screen is set up, the grid does not look like squares. A random number between 1 and 3 is picked and the path moves in one of three ways:
1: The path moves up
2: The path moves right
3: The path moves down
Three modules are used:
> random module
> ti_draw module (exclusive to TI): drawing commands
> time module (exclusive to TI): used for the sleep command
TI-84 Plus CE Python Script: paths.py
This code should work on the TI-83 Premium CE and the TI-Nspire CX II.
# draw a random path
# EWS 2023-06-19
from ti_draw import *
from random import *
from time import *
# draw using upper left corner
# main loop
while x<60 and y>10 and y<60:
# set end indicator
# text - allow for text height
# have to play around
> The show_draw() command on the end let's us see all the steps. A sleep command (time module) at the end of the loop to slow down between each execution of the loop.
> The fill_rect both take coordinates to be the upper-left hand corner of box.
> The draw_text works similarly to fill_rect except we have to account for the size of the font.
> The set_window command allows us to set the coordinates for the window. If there is no set_window command, the screen would operate by pixels instead. The TI-84 Plus CE screen is 319 x 209 pixels.
Three example paths are shown below:
All original content copyright, © 2011-2023. 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.