Showing posts with label Numworks. Show all posts
Showing posts with label Numworks. Show all posts

Saturday, October 24, 2026

Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles


The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle is rotated counterclockwise. The angle of the rotation is determined by:


a = 360° ÷ n = (2 * π rad) ÷ n


Since the center of each circle is set at (0, 0), the center of each circle is located at (r * cos a, r * sin a) where r is the radius.



Python: Using Turtle (Numworks)




( radius = 50 pixels, n = 8 circles)



The script circring.py imports the Turtle module. The circle command draws a circle starting at the bottom of the circle going counter-clockwise. The bottom of the circle is located at the point (x, y – r) where (x, y) is the center and r is the radius.


Code:


from math import *

from turtle import *


# 2026-07-19 EWS

# turtle version


r=eval(input("radius? "))

n=int(input("# steps? "))


speed(7)


for i in range(n):

  # set angle

  a=i*2*pi/n

  # turtle circle starts at

  # bottom center point

  x=r*cos(a)

  y=r*(sin(a)-1)

  # move to starting point

  penup()

  goto(x,y)

  # draw circle

  pendown()

  circle(r)

  

# make turtle invisible

hideturtle()



Python: Using TI-Draw (TI-84 Evo)



( radius = 50 pixels, n = 8 circles)


The script CIRRNG84.py uses the TI Draw module. The TI-84 Evo (and I think the TI nSpire, not 100% sure) lacks the Turtle module and instead employs a calculator-specific drawing module. The draw_circle command calls for both the center point and the radius. No adjustments are necessary.


Code:

from ti_draw import *

from math import *


# 2026-07-19 EWS

# TI version non turtle


set_window(-160,160,-105,105)

print("grid -160,160,-105,105")

r=eval(input("radius? "))

n=int(input("# steps? "))

clear()


for i in range(n):

  # set angle

  a=i*2*pi/n

  # determine center

  x=r*cos(a)

  y=r*sin(a)

  # draw circle

  draw_circle(x,y,r)


# show picture

show_draw()


Source



Chartier, Tim and Langville, Amy. Nonstandard Notebook: Mathematically Rule Pages for Unruly Thoughts The University of Chicago Press: Chicago and London. 2024 ISBN-13 978-0-226-83090-2 <pg. 61-63>



If you get a chance, please get this book. It’s a journal of interesting curves involving polynomials, circles, lines, and waves. The authors uses these curves to illustrate what ruled paper would look like when it doesn’t consist of all straight lines. The concept of music, earthquakes, and heartbeats are illustrated, including equations for clovers, mandalas, and hearts. This book is an inspiration for me.


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, September 26, 2026

Python in Numworks: Duplicating and Grayscale

Python in Numworks: Duplicating and Grayscale




All three scripts presented today use the math, random, and the Numworks specific



Stage 1: Generating Boxes of Random Colors



The script generates 15 boxes of random colors of 30 pixels each. This the list of available colors:





red: (255, 0, 0)

orange: (255, 127,0)

lime green: (0, 255, 0)

teal: (0, 128, 128)

blue: (0, 0, 255)

yellow: (255, 255, 0)

dark green: (0, 128, 0)

purple: (128, 0, 128)



The kandinsky command fill_rect draws a filled rectangle and has the following syntax:

fill_rect( x, y, width, height, rbg tuple )

(x,y) is the upper left hand corner of the rectangle in pixels (size 320 x 220).


from math import *

from kandinsky import *

from random import *


'''

draw boxes of random colors


Edward Shore

6/7/2026

'''


# set up eight colors

# red,orange,lime,teal,

# blue,yellow,dark green,purple


colors=[(255,0,0),(255,127,0),(0,255,0),(0,128,128),(0,128,0),(128,0,128)]


# draw 15 squares of random colors

for i in range(3):

  for j in range(5):

    col=choice(colors)

    fill_rect(30+30*i,30+30*j,30,30,col)


(results will vary)



Stage 2: Duplicating the Boxes



This script generates 15 boxes and then copies them to another area. I wanted the script to determine the pixel color’s because in more complex programs, we may not always know the color tuple of a pixel in advance.



The command get_pixel returns a color’s tuple:

get_pixel(x, y) → (red, green, blue)



Although this script does not use the command, Kandinsky also has a set_pixel command which turns a pixel a certain color.

set_pixel(x, y, (red, green, blue))


from math import *

from kandinsky import *

from random import *


'''

draw boxes of random colors

and dupicate them

Edward Shore

6/7/2026

'''


# set up eight colors

# red,orange,lime,teal,

# blue,yellow,dark green,purple


colors=[(255,0,0),(255,127,0),(0,255,0),(0,128,128),(0,128,0),(128,0,128)]


# draw 15 squares of random colors

for i in range(3):

  for j in range(5):

    col=choice(colors)

    fill_rect(30+30*i,30+30*j,30,30,col)

    # get the color

    gcol=get_pixel(30+30*i,30+30*j)

    fill_rect(150+30*i,30+30*j,30,30,gcol)


(results will vary)



Stage 3: Grayscale



The third script converts the duplicated pixel to grayscale using this formula:

grayscale = red * 0.299 + green * 0.587 + blue * 0.114

and the resulting color tuple is (grayscale, grayscale, grayscle)



The weights are selected to accommodate the human eye’s sensitivity to red, green, and blue.


from math import *

from kandinsky import *

from random import *


'''

draw boxes of random colors

and dupicate them in grayscale

Edward Shore

6/7/2026

'''


colors=[(255,0,0),(255,127,0),(0,255,0),(0,128,128),(0,128,0),(128,0,128)]


# draw 15 squares of random colors

for i in range(3):

  for j in range(5):

    col=choice(colors)

    fill_rect(30+30*i,30+30*j,30,30,col)

    # get the color

    w=get_pixel(30+30*i,30+30*j)

    # convert to grayscale

    w=w[0]*0.299+w[1]*0.587+w[2]*0.114

    # create a tuple

    gcol=(w,w,w)

    fill_rect(150+30*i,30+30*j,30,30,gcol)


(results will vary)



Source



“Color Space Conversion & Binarization for Image Processing” Dynamsoft. May 24, 2019. https://www.dynamsoft.com/blog/insights/image-processing/image-processing-101-color-space-conversion/ Retrieved June 6, 2026.



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, June 13, 2026

Numworks (Python): Parallelograms Described by Vectors

Numworks (Python): Parallelograms Described by Vectors



Introduction



The script drawpgram.py draws a parallelogram constructed by a pair of two-dimensional vectors. Both vectors original from the origin of the Cartesian plane ([0, 0]). Let the two vectors be labeled as [x1, y1] and [x2, y2].



This script also calculates the area and perimeter of the constructed parallelogram consisting of the end points (0,0), (x1, y1), (x2, y2), and (x1+x2, y1+y2).







Then the perimeter of the parallelogram is calculated as:

perimeter = 2 * (norm([x1, y1] + norm[x2, y2]) = 2 * (√(x1 + y1) * √(x2, y2))



And the area is calculated as:

area = abs(det([[x1, y1] [x2, y2]])) = abs(x1 * y2 – x2 * y1)





Numworks Script: drawpgram.py

Modules used: Math, PyPlot



Script page: https://my.numworks.com/python/ews31415/drawpgram



# Draw a parallelogram with two vectors

# Edward Shore, 2/15/2026

# Numworks

# drawpgram.py



from math import *

from matplotlib.pyplot import *



print("Draw a parallelogram with 2 vectors")

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

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

x2=eval(input("x2? "))

y2=eval(input("y2? "))



# Area

area=abs(x1*y2-x2*y1)



# Perimeter

perim=2*((x1**2+y1**2)**(1/2)+(x2**2+y2**2)**(1/2))





minx=min([x1,x2,x1+x2,0])

maxx=max([x1,x2,x1+x2,0])

miny=min([y1,y2,y1+y2,0])

maxy=max([y1,y2,y1+y2,0])



axis((minx-1,maxx+1,miny-1,maxy+5))



plot([0,x1],[0,y1],'blue')

plot([0,x2],[0,y2],'purple')

plot([x1,x1+x2],[y1,y1+y2],'purple')

plot([x2,x1+x2],[y2,y1+y2],'blue')



str1="area = {0:.6f}".format(area)

text(minx-1,maxy+4.5,str1)



str2="perim = {0:.6f}".format(perim)

text((minx+maxx)/2,maxy+4.5,str2)



show()



Notes:

1. I use eval(input( “prompt” )) and importing the Math module to allow for expressions to be entered, such as expressions involving pi (π). If I use float(input( “prompt” )) instead, only numbers would be allowed.

2. For the purposes of display, the results are rounded off to six decimal places ({0:.6f}) and displayed in a line. The full precision results of area and perimeter are stored in the variables area and perim, respectively.



Examples



Example 1: [2, 4], [5, 2]



Example 2: [-3, 1], [5, 3]



Example 3: [-6, 0], [0, -4]



Source

Margalit, Dan and Joseph Rabinoff. 2025. “Determinants and Volumes” Interactive Linear Algebra LibreTexts. Accessed February 8, 2026. https://math.libretexts.org/Bookshelves/Linear_Algebra/Interactive_Linear_Algebra_(Margalit_and_Rabinoff)/04%3A_Determinants/4.03%3A_Determinants_and_Volumes



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, May 30, 2026

Numworks (Python): Determining Earth’s Acceleration of Gravity

Numworks (Python): Determining Earth’s Acceleration of Gravity



Introduction



Note: We will only be using SI units on this blog entry and program.



In general, the Earth’s acceleration constant, labeled with a lower case g, is conventionally defined to be 9.80665 m/s². Did you know that the gravitation acceleration on this planet actually varies (albeit slightly) depending on factors? For example, the gravity’s acceleration in Los Angeles, California, is about 9.796 m/s² (see Wikipedia article in the Source section).



On today’s blog, we will estimate the gravity of Earth based with two parameters: the latitude (North/South position on Earth’s grid) and elevation (in meters). This will give us a more accurate estimated on gravity, which in turn will give other physics calculations more accuracy.



For this program, I’m using a mix of formulas to estimate Earth’s gravitational acceleration:



Let Φ = latitude in radian measure:

Φ = (degrees + minutes ÷ 60 + seconds ÷ 3600) * π ÷ 180



For this calculation, consider the absolute value of the latitude. Gravity acceleration is the a given the northern latitude north and the corresponding southern latitude. (Example: gravity is about 9.79325 m/s² at 30° north and 30° south).



Gravity at the surface (0 m) is calculated as:

gs = (a * ga * (cos Φ)^2 + b * gb * (sin Φ)^2) ÷ √((a * cos(Φ))^2 + (b * sin(Φ))^2)

[Bilsin]



Where:

Φ = latitude in radians (see formula above)

a = 6378137 m (Earth’s radius at the equator)

ga = 9.70803253359 m/s² (gravity at the equator)

b = 6356752.3142 m (Earth’s radius at the poles)

gb = 9.8321849378 m/s² (gravity at the poles)

[Bilsin, Table 2]



Gravity at the selected elevation is estimated at:

ge = (100 * gs – 0.3086 * h ÷ 1000) ÷ 100

[Glover]



Where:

h = height in meters (m)



Note: The table on the Desk Ref list gravity as cm/s² and the original formula called for the height in kilometers (km).



To convert feet to meters, multiply by 0.3048.



Numworks Program: earthg.py


https://my.numworks.com/python/ews31415/earthg


Code:


from math import *

# Numworks, EWS, January 2026


# constants

# equator: radius, gravity

a=6378137

ga=9.7803253359

# poles: radius, gravity

b=6356721.3142

gb=9.8321849378


print("Latitude:","\nNorth or South")

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

m=eval(input("Minutes? "))

s=eval(input("Seconds? "))

phi=radians(d+m/60+s/3600)


print("Height (m)?")

h=eval(input("? "))


gs=a*ga*cos(phi)**2+b*gb*sin(phi)**2

gs/=sqrt((a*cos(phi))**2+(b*sin(phi))**2)


print("Gravity on the surface:")

print(str(gs)," m/s**2")


print("At altitude: ",str(h)," m")

ge=(100*gs-0.3086*h/1000)/100

print(str(ge)," m/s**2")




Examples


Latitude

Elevation

g_surface

g_elevation

30°0’0”

0

9.793247191840559

9.793247191840559

40°0’0”

304.8

9.801696762579571

9.800756149779572

45°0’0”

762

9.806197665936962

9.803846133936961

12°5’13”

1219.2

9.782589588493437

9.778827137293437

34°26’44”

500

9.796866770553882

9.795323770553882


g_surface: gravity at surface level (0 m)

g_elevation: gravity at the selected elevation



Sources


Bislin, Walter. “Earth Gravity Calculator” September 1, 2018. https://walter.bislins.ch/bloge/index.asp?page=Earth+Gravity+Calculator Retrieved January 15, 2026.


Glover, Thomas J. and Richard A. Young Desk Ref Sequoia Publishing, Inc. Anchorage, AK. 4th Edition, 2022. Soft Cover ISBN 978-1-885071-60-6. pg. 587


“Gravity of Earth” Wikipedia. Last edited January 31, 2026. https://en.wikipedia.org/wiki/Gravity_of_Earth Retrieved February 1, 2026.



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.


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, February 7, 2026

Numworks (Python): Control Charts

 Numworks (Python): Control Charts



The following Python script develops the x-bar and R control charts.


Formulas used:


mean_average = Σ(mean of each sample)

range_average = Σ(range of each sample)



x-Bar Chart:

low = mean_average - a2 * range_average

high = mean_average + a2 * range_average


R chart:

low = d3 * range_average

high = d4 * range_average



Python script (done with Numworks): ctrlchart.py


from math import *

# control chart function

# run as a defined function

# HP 65 Stat Pac 2, 1975



def ctrlchart():

  #elements

  a2=[0,0,1.88,1.02,.73,.58,.48,.42,.37,.34,.31,.29,.27,.25,.24,.22,.21,.20,.19,.19,.18]

  d3=[0,0,0,0,0,0,0,.08,.14,.18,.22,.26,.28,.31,.33,.35,.36,.38,.39,.4,.41]

  d4=[0,0,3.27,2.57,2.28,2.11,2,1.92,1.86,1.82,1.78,1.74,1.72,1.69,1.67,1.65,1.64,1.62,1.61,1.6,1.59]

  # calculation

  meansum=0

  rangesum=0

  n=int(input("number of samples? "))

  m=int(input("sample size (2-20)? "))

  for i in range(n):

    x=[]

    for j in range(m):

      # adjust to show proper numbering

      s="x("+str(i+1)+","+str(j+1)+")? "

      p=eval(input(s))

      x.append(p)

    rangesum+=max(x)-min(x)

    meansum+=sum(x)/m

  rangeavg=rangesum/n

  meanavg=meansum/n

  lowmean=meanavg-rangeavg*a2[m]

  highmean=meanavg+rangeavg*a2[m]

  lowrange=d3[m]*rangeavg

  highrange=d4[m]*rangeavg

  print("x-bar chart")

  print("L: "+str(lowmean))

  print("H: "+str(highmean))

  print("range chart")

  print("L: "+str(lowrange))

  print("H: "+str(highrange))


Example 1:

5 samples (n = 5)
Sample size: 4  (m = 4)

Sample 1:  4.3, 4.2, 4.3, 5.0
Sample 2:  4.1, 4.1, 4.6, 3.6
Sample 3:  4.0, 4.5, 4.3, 3.7
Sample 4:  3.9, 4.7, 4.4, 5.1
Sample 5:  4.2, 5.2, 4.9, 5.3

x-Bar chart:
Low:  3.7046
High:  5.1354

R chart:
Low:  0
High:  about 2.2345

Example 2:

2 samples (n = 2)
Sample Size: 7 (m = 7)

Sample 1:  48, 58, 53, 56, 57, 59, 55
Sample 2:  56, 46, 48, 49, 63, 52, 51

x-Bar chart:  
Low:  47.33428571428571
High:  59.09428571428571

R chart:
Low:  1.12
High: 26.88

Source


“x-bar and R Control Charts”. HP 65 Stat Pac 2. Hewlett Packard. 1975. pp. 98 – 101



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.


Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle i...