Showing posts with label animation. Show all posts
Showing posts with label animation. Show all posts

Sunday, April 12, 2026

Numworks: Text Demos with a Poem and Rolling Screen Credits

Numworks: Text Demos with a Poem and Rolling Screen Credits 


The two scripts, which developed in Numworks:



nwtext1.py: Displaying a poem one line at a time.

nwtext2d.py: Presenting the credits in a classic TV show format.



They can be downloaded here:

https://drive.google.com/file/d/1IEDbLV4-mz9kngj0bBOkvBLrgKYg_5ha/view?usp=sharing



Display a Poem: newtext.py



Code:


# nwtext1.py

# Text Animation Demo 1

# Numworks

# Edward Shore, 2/18/2026



# import modules

from math import *

from kandinsky import *

from time import *



# Screen: 320 x 220 pixels



# list of text

t=['Roses are red','violets are blue','Nuwmorks is great','and so are you!']

# list of colors: red, violet, amber, ghost white

c=[(255,0,0),(178,0,237),(255,191,0),(245,245,245)]

# black background

fill_rect(0,0,320,220,(0,0,0))



# list the text

# each line is 20 pixels

for i in range(len(t)):

  # draw the string for each line

  # must include the black background

  # draw_string assumes white background if second color

  # is left off

  draw_string(t[i],60,60+20*i,c[i],(0,0,0))

  # time module's sleep

  sleep(1)



Notes:

1. Modules used: math, kandinsky, time. Math was entered by default every time a new script is started in Numworks. The kandinsky and time modules are specific to Numworks. The kandinsky module includes the drawing commands fill_rec and draw_string while the time module has the command sleep.

2. The line fill_rect(0,0,320,220,(0,0,0)) gives the drawing screen a black background.

3. The syntax for kandinsky’s draw_string is: draw_string(string of text, x y, text color, background color). The colors are optional, with the default set at black text color and white background. Since we have a black background for the entire screen, the background color (0,0,0) must be included.

4. To give readability I estimate that each line has a height of 20 pixels.



TV Screen Credits: nwtext2d.py





Code:

# nwtext2d.py

# Text Animation Demo 2

# Numworks

# Edward Shore, 2/19/2026



# Goal: give a classic TV style flashing of credits



# import modules

from math import *

from kandinsky import *

from time import *



# Screen: 320 x 220 pixels



# lists of text

# I'm not going to worry about center justification on this demo



# unicode for pi is u\03C0



# top line

t0=['CREDITS','Programmer','Supervisor','Directed By','Studio','Written By','A Pisces','']

# bottom line

t1=['','PI MAN','MS. SQUARE ROOT','PYTHAGOREAN THEOREM','SINE STUDIOS','PI MAN','Python Production 2026',':) \u03C0']

# black background in the loop, see comments





# roll credits

# each line is 20 pixels

for i in range(len(t0)):

  # draw a string for each line

  # text is in emerald green

  # background is black, must be included

  # since text is being replaced, we must refresh the      screen every time

  fill_rect(0,0,320,220,(0,0,0))

  draw_string(t0[i],40,60,(80,200,120),(0,0,0))

  draw_string(t1[i],40,100,(80,200,120),(0,0,0))

  # delay by 2 seconds

  sleep(2)



Notes:

1. Modules used: math, kandinsky, time. Math was entered by default every time a new script is started in Numworks. The kandinsky and time modules are specific to Numworks. The kandinsky module includes the drawing commands fill_rec and draw_string while the time module has the command sleep.

2. The line fill_rect(0,0,320,220,(0,0,0)) gives the drawing screen a black background.

3. The syntax for kandinsky’s draw_string is: draw_string(string of text, x y, text color, background color). The colors are optional, with the default set at black text color and white background. Since we have a black background for the entire screen, the background color (0,0,0) must be included.

4. In attempt to vertically center the credits, I put the top line at y = 60 and the bottom line at y = 100. In this demo, I did not worry about center justification, only choosing to left justify all the lines. The strings for the top line are stored in the list t0 while the strings for the bottom line are stored in the list t1.



I hope you enjoy these programs as I did making them,



Eddie

All original content copyright, © 2011-2026. 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.



Saturday, November 9, 2024

TI-84 Plus CE Python: Drawing Bars

TI-84 Plus CE Python: Drawing Bars



My inspiration for this post was from a class I was taking at brilliant.org. A free plug: brillant.org is a great web service that offers easy to follow and interactive classes in mathematics, physics, and programming. Classes are offered at every level.



Introduction


The following set of scripts draw a set of bars. The blue bar is the base bar, while orange bars are added to the right of the base bar. The user specifies the length of the base (b) and orange bars, known as the increment (c). The length is in pixels. The screen is 320 pixels long.





Each of the scripts uses the TI-specific module TI-draw module. If you have another calculator or platform, another similar drawing module is needed. The scripts were typed on a TI-84 Plus CE Python Edition, but should work on the TI-83 Premium CE Python Edition and TI-Nspire CX II (I haven’t tested either).



BAR1: Static


This script asks the user for the length of the base bar, increment bar, and the number of bars.


Note that show_draw() command end the execution of the script with the drawing on the screen. Press [clear] to exit the screen.


# static bar


from ti_draw import *

print("Positive Integers Only")
b=int(input("base? "))
c=int(input("increment? "))
n=int(input("# of bars? "))

# total
t=b+c*n

# draw
clear()

# base
set_color(0,120,245)
fill_rect(0,80,b,40)

# increment
set_color(255,135,10)
for i in range(n):
  fill_rect(b+i*c,80,c,40)

# text
set_color(0,0,0)
draw_text(0,160,"Total: "+str(t)+" = "+str(b)+" + "+str(n)+" * "+str(c))
draw_text(0,180,"Press [clear] to exit.")

# draw
show_draw()


BAR2: Animate


This script asks the user for the length of the base bar, increment bar, and the number of bars. Only this time the drawing is animated as the number of increment bars is increased from 0 to n.


This script uses another module, time. This is needed for the sleep(s) command, where s is the number of seconds.



# animate bar


from ti_draw import *
from time import *

print("Positive Integers Only")
b=int(input("base? "))
c=int(input("increment? "))
n=int(input("# of bars? "))

# total
t=b+c*n

# range starts at 0
for i in range(n+1):
  clear()
  # base
  set_color(0,120,245)
  fill_rect(0,80,b,40)
  # increment
  set_color(255,135,10)
  for j in range(i):
    fill_rect(b+j*c,80,c,40)
  t=b+c*i
  # text
  set_color(0,0,0)
  draw_text(0,160,"Total: "+str(t)+" = "+str(b)+" +        "+str(n)+" * "+str(c))
  # draw
  sleep(0.5)

# for the screen to stay on the bars at the end
set_color(255,0,0)
draw_text(0,180,"Press [clear] to exit.")
show_draw()


BAR3: Control


Instead of giving a number of increment bars, the user controls the number of bars by pressing the right [ → ] and left [ ← ] keys. Exit by pressing the [ enter ] key.


This script uses the ti_system module. This allows for the wait_key() command, which stops execution until a key is pressed.


Key codes for TI-84 Plus CE Python and TI-83 CE Premium Python Edition:

[ → ]: right key, code 1

[ ← ]: left key, code 2

[ enter ]: enter key, code 5




# bar with get key

from ti_draw import *
from ti_system import *

def drawsub(b,c,n):
  # total
  t=b+c*n
  # draw
  clear()
  # base
  set_color(0,120,245)
  fill_rect(0,80,b,40)
  set_color(255,135,10)
  for i in range(n):
    fill_rect(b+i*c,80,c,40)
  set_color(0,0,0)
  draw_text(0,160,"Total: "+str(t)+" = "+str(b)+" +        "+str(n)+" * "+str(c))
  draw_text(0,180,"<- or ->, [enter] to quit")


print("Positive Integers Only")
b=int(input("base? "))
c=int(input("increment? "))
print("Press <- or ->")


# default value of n
n=0

# max number of incr
m=int((320-b)/c)

# key
k=0

while k!=5:
  k=wait_key()
  # left key
  if k==2 and n>0:
    n-=1
  # right key
  if k==1 and n<m:
    n+=1
  drawsub(b,c,n)

set_color(255,0,0)
draw_text(0,20,"DONE")
show_draw()



Download the scripts here: https://drive.google.com/file/d/1SKCXBm6lYi5cYurm7nqAqI-868lxvqpz/view?usp=sharing



Until next time and in good health,


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.


Saturday, September 7, 2019

TI NSpire CX II: Animation Demo

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.

Friday, April 26, 2019

TI-84 Plus CE: Time Plot of Two Parametric Equations

TI-84 Plus CE:  Time Plot of Two Parametric Equations

Introduction 

The program TIMEPLOT animates two parametric plots. 

TI-84 Plus Program TIMEPLOT
(237 bytes)

"EWS 2019-04-22"
Param
PlotsOff
FnOff
Input "T START:",A
Input "T STOP:", B
Input "T STEP:", S
int((B-A)/S) → N
A → T: {X1T} → L1 : {Y1T} → L2
{X2T} → L3: {Y2T} → L4
For(I,2,N)
A + S*(I-1) → T
augment(L1, {X1T}) → L1
augment(L2, {Y1T}) → L2
augment(L3, {X2T}) → L3
augment(L4, {Y2T}) → L4
Plot1(Scatter, L1, L2, □, BLUE)
Plot2(Scatter, L3, L4, □, GREEN)
DispGraph 
Wait 1
End



Example

X1T = 2 SIN T
Y1T = 3 SIN T

X2T = SIN (T^2/4)
Y2T = 1/2 * COS(T^2/8)

T START: 0
T STOP: 4 * π
T STEP: π / 24



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.

Wednesday, April 24, 2019

Casio fx-CG50: Animation of a Graph

Casio fx-CG50:  Animation of a Graph

Introduction

You can easily animate a graph with the Dynamic Graphing mode.   While I'm describing this procedure for the fx-CG50, I'm pretty sure it is available for the earlier models such as fx-CG10, fx-9750GII, and fx-9860GII.

Specifically, you can dynamically change a single variable between two points with a specified step.

For example:  y = A*x  where A varies from 0 to 5, and its step is 1.

General Procedure

1.  Enter Dynamic Graph mode.  On the fx-CG50, press [ MENU ], [ 6 ].

2.  Type and select an equation.  The equation can be a function, a set of parametric equations, a polar equation, or on newer calculators, a shaded inequality.

3.  Press [ F4 ] (VAR) to take you to the variable screen.   Select the variable you want to animate.  You can animate any variable A - Z and θ.  Keep in mind that X is used for functions equations, T is used for parametric equations, and θ is for polar equations.

4.  Set the Animation Speed by pressing [ F3 ] (SPEED).  The speeds that can be selected are:

F1:  Stop & Go  (you advance the slides with the right and left arrows)
F2:  Slow speed
F3:  Normal speed
F4:  Fast speed

5.  Press [ F6 ] (DYNA) to start the animation.  To stop it, press [ AC ].

Example 

x1(t) = 1.2 * A * cos T
y1(t) = A * sin (T + 1) * cos (Ï€/(3*T))
with Ï€/12 ≤ T ≤ 2 Ï€, step Ï€/12





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.

Saturday, January 11, 2014

HP Prime: Waterfall Animation

HP Prime: AMNI10
Waterfall Animation

Background boxes with falling water. There is random mist coming from the water.
Colors:
Blue: #FFh, RGB(0,0,255)
White: #FFFFFFh, RGB(255,255,255)
Brown: #964B00h, RGB(150,75,0)
Grass Green: #DA00h, RGB(0,218,0)




EXPORT AMNI10()
BEGIN
// 2014-01-10 Waterfall EWS
LOCAL K,J,I,A:=0;
RECT();

WHILE GETKEY==-1 DO
A:=A+1;

// Static
// Walls
RECT_P(0,5,30,210,#964B00h);
RECT_P(280,5,318,210,#964B00h);
// Water
RECT_P(30,10,280,210,#FFh);
// Grass
TRIANGLE_P(0,210,155,230,318,210,
RGB(0,218,0));

// Animated
// Mist
FOR I FROM 1 TO RANDINT(50,75) DO
TEXTOUT_P(".",RANDINT(30,270),
RANDINT(10,200),3,#FFFFh); END;
// Foam
FOR I FROM 1 TO RANDINT(100,125) DO
TEXTOUT_P("=",RANDINT(25,290),
RANDINT(200,210),3,#FFFFFFh); END;
// Fall
RECT_P(30,10+25*(A+1),280,10+25*A,
#FFFFFFh);
WAIT(0.1);
IF A==8 THEN
A:=0; END;

END;
END;
I realize this is more a picture one would see when running an Atari 2600 game.  I guess the point is how to layer graphics so that the static elements are drawn first, then the animated elements.

Eddie


This blog is property of Edward Shore. 2014

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...