0% found this document useful (0 votes)
10 views9 pages

TI-Nspire Scripting: Graphical Shapes

This document discusses a scripting tutorial that teaches how to use Lua's graphic commands to display shape numbers like squares, rectangles, and triangles. It explains how to create a grid pattern by drawing lines, and how to vary the grid to display the different shapes depending on a type variable. The script defines a drawArray function that takes parameters to draw the lines, and varies the loops and additional lines used to create the different patterns for each shape type.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

TI-Nspire Scripting: Graphical Shapes

This document discusses a scripting tutorial that teaches how to use Lua's graphic commands to display shape numbers like squares, rectangles, and triangles. It explains how to create a grid pattern by drawing lines, and how to vary the grid to display the different shapes depending on a type variable. The script defines a drawArray function that takes parameters to draw the lines, and varies the loops and additional lines used to create the different patterns for each shape type.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Home TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 9

Scripting Tutorial - Lesson 9: Graphical Shape Numbers


Download supporting files for this tutorial Texas Instruments TI-Nspire Scripting Support Page

It is time to try and put together everything that we have learned so far. In this lesson and lesson 10 we will use Lua's graphic commands along with many of the enhancements we have learned to create documents that are both useful, clear and easy to use. We will begin with the graphical display of shape numbers - square, rectangular and triangular numbers. Take a moment to watch the accompanying movie and then have a play with this document using the Player to get a feel for the possibilities and for some of the design choices that have been made. For example, while it is great to use arrow keys and enter, escape and even tab keys

to make control by both computer and handheld easy, if we want our documents to be usable with the Player then it is worth leaving in the sliders. In the example shown, pressing up and down arrows controls the value of n, increasing and decreasing the number being studied. Left and right arrows show the three options square, rectangular and triangular numbers. Pressing enter shows different views - the shape created using circles, with a border, and using squares. finally, pressing the tab key steps through the building up of that pattern, making it easy to see the relationships involved -

Click anywhere on this image for a video demonstration

square numbers are the sums of odd numbers, rectangular numbers the sum of even numbers, and because every rectangle is double the corresponding triangle, the triangular numbers are built by adding the counting numbers. Pressing escape takes you back through this progression.

Lesson 9.1: Building a Grid Pattern We will begin by using drawLine to create a square grid corresponding to the current value of n. But first, some practical considerations - plan your design and layout! We would like our grid to lie centered on the page. We know how to do that. But we would also like it if the

size of our grid remained within the visible page, with a bit of white space around it. So we could divide the width and height of the page up by the value of n (and a bit more for white space). Will also need a slider for n (and more sliders to follow!). So set up a split page with a Geometry window and slider on one side and our script window for the main window. Look closely at the code here. We define a function (drawArray) that takes as its arguments the current value of n, the x and y coordinates of the starting position, and the length and width of each cell. You will see that the drawLine function takes four

function drawArray(number, x, y, length, height, gc) for k = 0, number do for m = 0, number do gc:drawLine( x, y + height * m, x + length * number, y + height * m)

gc:drawLine( x + length * k, y,

arguments: the x and y coordinates of start and end points. We will use one variable (m) to define the horizontal lines and the other (k) for the vertical lines. Again, study the code provided to see one way in which to achieve what we desire. Once the function is defined, we need to paint the screen to actually see it. here we choose to define the required variables within the [Link] function. Hence we define the window width and height, recall the current value of n and use it to calculate the x and y coordinates for the starting point, and the width and length of the cells. For the latter values, we divide the window

x + length * k, y + height * number) end end end

function [Link](gc) w = [Link]:width() h = [Link]:height() num = [Link]("n") or 1 xval = [Link](w/(num+4)) yval = [Link](h/(num+4)) x = w/2 - num * xval / 2 y = h/2 - num * yval / 2

gc:setPen("thin", "smooth") gc:setColorRGB(165,42,42) drawArray(num, x, y, xval, yval, gc) end

dimensions by the value of n (and a little more), then take the lowest integer value. This will ensure that our model always remains within the screen dimensions. Finally, we set the color and the pen values and call our function, drawArray. This produces a dynamic square grid, as required, controlled by the current value of a variable n within TINspire.

Lesson 9.2: Varying our Grid Pattern So we have a square grid - we would like to have two variations on this theme: a rectangular grid (with one side one longer

one longer than the other) and a triangular grid. We will control these with a slider variable we will call type. First, the rectangular numbers: essentially the same script as for the square numbers, but with one variable one more than the other. Recall the value of variable type at the start of our drawArray function, then use it as the basis of a test: if type == 1 then (the square routine) elseif type == 2 then (rectangles) else (triangles) end.

elseif types == 2 then for k = 0, number + 1 do for m = 0, number do gc:drawLine( x, y + height * m, x + length * (number + 1), y + height * m)

gc:drawLine( The triangle x + length * k,

follows the main variation from the two previous forms is that, instead of the second variable running from 0 or 1, it begins at the current value for k, thus indenting each line to form the triangle. In order to close the figure, it was necessary to add an additional line at top and another at the right side hence the four lines in this script where the others had only two.

k, y, x + length * k, y + height * number) end end else gc:drawLine(x, y, x + length * (number+1) length, y ) gc:drawLine(x + length * number, y, x + length * number, y + height * number) for k = 1, number do for m = k, number do gc:drawLine(x + length*(m1), y + height * m, x + length * number, y + height * m) gc:drawLine(x + length * (k1), y, x + length * (k1), y + height * k) end end end

Add the line which defines the variable types from type and the first condition

(if types == 1 then) at the start of the function definition, and this script will deliver the three shapes drawn using a grid. In the final tutorial in this series this script is further enhanced using circles to dynamically build each of the patterns, and our usual arrow key controls will be added.
Home TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial Lesson 9

Common questions

Powered by AI

The on.paint function orchestrates the grid scalability by setting up the graphical context, determining the screen dimensions, recalling current grid values, calculating cell dimensions, and ultimately calling the drawArray function. This ensures the grid is drawn correctly regarding the current script state and user control input .

The on.paint function calculates display-related variables, such as window width and height, divides them by the value of n plus a margin to determine the cell size, and adjusts the x and y starting coordinates to center the grid. This ensures that the grid dimensions are dynamically adjusted to fit within the visible screen area .

Square numbers are represented as sums of odd numbers. Rectangular numbers are represented as sums of even numbers. Triangular numbers, being half of rectangular numbers, are built by adding the counting numbers. These relationships are visually represented using Lua scripting to dynamically display patterns, each number type showing a distinct geometry .

Graphical shape numbers provide a visual and interactive way to study mathematical patterns, fostering an intuitive understanding of number properties such as squared and triangular numbers. By visualizing these patterns through scripting, learners can explore mathematical relationships dynamically, which aids in deep comprehension over abstract representations. Insights into number series sum and geometrical shape transformations are naturally developed .

Lua scripting can be enhanced by incorporating arrow and tab key controls for input variability, sliders for parameter adjustments, and defining color schemes and pen settings to improve visual clarity. The use of graphical functions such as these allows for interactive user experiences, such as stepping through pattern progressions or altering grid types between square, rectangular, and triangular shapes .

Triangular numbers are differentiated by scripting the second loop to begin at a variable 'k,' which indents lines progressively to form a triangle. Additional lines crisply complete the shape within the grid. This contrasts with rectangular and square numbers where lines are parallel and uniformly spaced, without indentation offset by 'k' .

To adapt a square grid script for rectangular grids, one variable must be increased relative to the other, controlled by a 'type' variable. For triangular grids, the script modifies the second loop to start at the current 'k' value and draws additional lines to close the figures. The script uses a conditional structure to test and apply different grid shapes based on the 'type' variable value .

The drawArray function creates a graphical grid based on input parameters, which include the current value of n (grid size), starting coordinates, and the cell dimensions. It uses nested loops to draw horizontal and vertical lines, forming the grid structure. The function adapts to type variations to draw square, rectangular, or triangular grids .

The grid should be centered on the page and remain within the visible area, with additional white space for clarity. Variables such as window width and height, and cell dimensions must be calculated dynamically based on the current value of 'n' to ensure the grid's adaptability to different zoom levels. A slider should control the value of 'n,' which is crucial for testing various grid densities .

Scripting strategies include dynamically calculating cell size by dividing the window dimensions by the grid's size plus margin, thus ensuring fitting within the screen. Careful computation of starting coordinates centralizes the grid on the page. Adjustments are done through the 'on.paint' function, alongside variable handling to keep grids neatly within boundaries .

You might also like