TI NSpire CX II: Animation Demo
Introduction
This blog entry demonstrates the use of drawing commands from the TI Nspire CX II (and TI Nspire CX II CAS) to animate objects. The main loop used in these animations used has the structure:
...
Local variables needed including coordinates
For coordinate 1, begin, end, step
For coordinate 2, begin, end, step (if necessary)
UseBuffer
...
SetColor red, green, blue
draw objects
....
PaintBuffer
Wait seconds
EndFor
EndFor (if a second for loop is used)
...
Demo 1: Animation of a Circle Across the Screen
Define ani1()=
Prgm
:© animate a circle across the screen part 1
:Local x
:SetWindow 0,10,0,10
:For x,1,9,2
: UseBuffer
: Clear
:© cherry red
: SetColor 255,27,34
: FillCircle x,9,2
: PaintBuffer
: Wait 1
:
:EndFor
:EndPrgm
Demo 2: Animation of a Circle Across and Down the Screen
Define ani2()=
Prgm
:© 2019-07-29 EWS
:© animate a circle
:Local x,y
:For y,10,190,20
: For x,10,270,20
: UseBuffer
: Clear
: SetColor 255,27,34
: FillCircle x,y,20
: PaintBuffer
: Wait 0.25
: EndFor
:EndFor
:
:SetColor 0,0,0
:DrawText 10,10,"Done!"
:EndPrgm
Demo 3: Animation of a Circle with Alternating Colors
Define ani3()=
Prgm
:© 2019-07-29 EWS
:© animate a circle
:Local x,y,flag
:flag:=0
:For y,10,190,20
: For x,10,270,20
: UseBuffer
: Clear
: If flag=0 Then
: SetColor 255,27,34
: flag:=1
: Else
: SetColor 0,228,221
: flag:=0
: EndIf
: FillCircle x,y,20
: PaintBuffer
: Wait 0.175
: EndFor
:EndFor
:
:SetColor 0,0,0
:DrawText 10,10,"Done!"
:EndPrgm
Demo 4: Barbell Animation
Define ani4()=
Prgm
:© barbell animation
:© 2019-07-30 EWS
:Local x,y,xc,yc,θ
:
:© radians mode
:setMode(2,1)
:
:For θ,0,8*π,((π)/(12))
: UseBuffer
: Clear
:© the bar
: xc:=60*cos(θ)+159
: yc:=60*sin(θ)+106
: SetColor 48,48,48
: DrawLine 159,106,xc,yc
: SetColor 205,127,50
: FillCircle xc,yc,15
: SetColor 0,0,0
: FillCircle 159,106,15
: PaintBuffer
: Wait 0.15
:EndFor
:DrawText 0,25,"Done!"
:EndPrgm
Demo 5: Bouncing Box Animation
Define ani5()=
Prgm
:© bouncing box
:Local r,g,b,x,y,t,θ
:© use pixels
:x:=106
:y:=159
:© degrees
:setMode(2,2)
:
:© set initial angle
:θ:=randInt(1,359)
:
:For t,1,1000
:UseBuffer
:Clear
:r:=randInt(0,255)
:g:=randInt(0,255)
:b:=randInt(0,255)
:SetColor r,g,b
:FillRect x,y,10,10
:
:x:=10*cos(θ)+x
:y:=10*sin(θ)+y
:
:If x≥310 or x≤10 or y≥200 or y≤10 Then
: θ:=mod(θ+90,360)
:EndIf
:SetColor 0,15,96
:DrawPoly {10,10,310,310,10},{10,200,200,10,10}
: PaintBuffer
: Wait 0.05
:EndFor
:EndPrgm
A copy of the tns document can be downloaded here: https://drive.google.com/open?id=1bkKEsLxaOd4svqw-S-ftZ3CkUe_NUDOm
Eddie
All original content copyright, © 2011-2019. 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.
Introduction
This blog entry demonstrates the use of drawing commands from the TI Nspire CX II (and TI Nspire CX II CAS) to animate objects. The main loop used in these animations used has the structure:
...
Local variables needed including coordinates
For coordinate 1, begin, end, step
For coordinate 2, begin, end, step (if necessary)
UseBuffer
...
SetColor red, green, blue
draw objects
....
PaintBuffer
Wait seconds
EndFor
EndFor (if a second for loop is used)
...
Demo 1: Animation of a Circle Across the Screen
Define ani1()=
Prgm
:© animate a circle across the screen part 1
:Local x
:SetWindow 0,10,0,10
:For x,1,9,2
: UseBuffer
: Clear
:© cherry red
: SetColor 255,27,34
: FillCircle x,9,2
: PaintBuffer
: Wait 1
:
:EndFor
:EndPrgm
Demo 2: Animation of a Circle Across and Down the Screen
Define ani2()=
Prgm
:© 2019-07-29 EWS
:© animate a circle
:Local x,y
:For y,10,190,20
: For x,10,270,20
: UseBuffer
: Clear
: SetColor 255,27,34
: FillCircle x,y,20
: PaintBuffer
: Wait 0.25
: EndFor
:EndFor
:
:SetColor 0,0,0
:DrawText 10,10,"Done!"
:EndPrgm
Demo 3: Animation of a Circle with Alternating Colors
Define ani3()=
Prgm
:© 2019-07-29 EWS
:© animate a circle
:Local x,y,flag
:flag:=0
:For y,10,190,20
: For x,10,270,20
: UseBuffer
: Clear
: If flag=0 Then
: SetColor 255,27,34
: flag:=1
: Else
: SetColor 0,228,221
: flag:=0
: EndIf
: FillCircle x,y,20
: PaintBuffer
: Wait 0.175
: EndFor
:EndFor
:
:SetColor 0,0,0
:DrawText 10,10,"Done!"
:EndPrgm
Demo 4: Barbell Animation
Define ani4()=
Prgm
:© barbell animation
:© 2019-07-30 EWS
:Local x,y,xc,yc,θ
:
:© radians mode
:setMode(2,1)
:
:For θ,0,8*π,((π)/(12))
: UseBuffer
: Clear
:© the bar
: xc:=60*cos(θ)+159
: yc:=60*sin(θ)+106
: SetColor 48,48,48
: DrawLine 159,106,xc,yc
: SetColor 205,127,50
: FillCircle xc,yc,15
: SetColor 0,0,0
: FillCircle 159,106,15
: PaintBuffer
: Wait 0.15
:EndFor
:DrawText 0,25,"Done!"
:EndPrgm
Demo 5: Bouncing Box Animation
Define ani5()=
Prgm
:© bouncing box
:Local r,g,b,x,y,t,θ
:© use pixels
:x:=106
:y:=159
:© degrees
:setMode(2,2)
:
:© set initial angle
:θ:=randInt(1,359)
:
:For t,1,1000
:UseBuffer
:Clear
:r:=randInt(0,255)
:g:=randInt(0,255)
:b:=randInt(0,255)
:SetColor r,g,b
:FillRect x,y,10,10
:
:x:=10*cos(θ)+x
:y:=10*sin(θ)+y
:
:If x≥310 or x≤10 or y≥200 or y≤10 Then
: θ:=mod(θ+90,360)
:EndIf
:SetColor 0,15,96
:DrawPoly {10,10,310,310,10},{10,200,200,10,10}
: PaintBuffer
: Wait 0.05
:EndFor
:EndPrgm
A copy of the tns document can be downloaded here: https://drive.google.com/open?id=1bkKEsLxaOd4svqw-S-ftZ3CkUe_NUDOm
Eddie
All original content copyright, © 2011-2019. 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.