Post Reply 
Numworks: Python Graphics
06-28-2020, 04:10 PM (This post was last modified: 06-28-2020 04:12 PM by Eddie W. Shore.)
Post: #1
Numworks: Python Graphics
Numworks Python Scripts: Basic Graphics

Script: atari.py

[Image: numworks-python-scripts-basic-graphics.html]

Draws the basic-eight color palette of the classic 1977 Atari 2600.

Code:
from math import *
from kandinsky import *
# 2020-05-28 atari 2600 colors
# kandinsky module

fill_rect(0,0,320,240,color(245,245,245))

fill_rect(15,15,55,55,color(0,0,0))
fill_rect(85,15,55,55,color(255,0,0))
fill_rect(155,15,55,55,color(255,255,0))
fill_rect(15,85,55,55,color(255,0,255))
fill_rect(155,85,55,55,color(0,255,0))
fill_rect(15,155,55,55,color(0,255,255))
fill_rect(85,155,55,55,color(0,0,255))
fill_rect(155,155,55,55,color(255,255,255))

draw_string("8",107,107)


Script: firstdigit.py

[Image: numworks-python-scripts-basic-graphics.html]

The tenths digit from n random numbers is extracted and a bar chart is generated based on the results. I recommend a sample size of at least 20.

Code:
from math import *
from random import *
from matplotlib.pyplot import *

# set up lists
x=[0,1,2,3,4,5,6,7,8,9]
y=[0,0,0,0,0,0,0,0,0,0]

# user iput
print("EWS 2020-05-29")
print("Bar Chart: First Digit")
print("Recommended at least 20")
n=int(input("n? "))

# generate list
for i in range(n):
  s=int(random()*10)
  y[s]=y[s]+1

# bar plot
h=int(n/2)
d=-int(h/4)
axis([-0.5,9.5,d,h])
bar(x,y)

# turn axis off
axis("off")

# labels at the bottom
# results at top
m=max(y)
for i in range(10):
  text(i-0.25,d+1,str(i))
  text(i-0.25,m+2,str(y[i]))
  
show()

Script: colorfulrings.py

[Image: numworks-python-scripts-basic-graphics.html]

The script cycles through a set of nine colors, four times. The Kandinsky module is used to generate the flowery circles as well as cycle through the colors. This module works with integer pixels.

Code:
from math import *
from kandinsky import *
from time import *

# color lists
r=[255,255,255,0,0,0,51,128,255]
g=[0,102,255,128,255,0,102,128,255]
b=[0,0,0,0,0,255,255,128,255]

# angles
a=list(range(128))
for i in range(128):
  a[i]=i/128*2*pi

# draw circles
for k in range(36):
  n=int(fmod(k,9))
  for j in range(50):
    for i in range(128):
      x=int(160+(20+j)*cos(a[i]))
      y=int(120+(20+j)*sin(a[i]))
      set_pixel(x,y,color(r[n],g[n],b[n]))
  sleep(0.1)

Script: modulusplot.py

[Image: numworks-python-scripts-basic-graphics.html]

Generate a pixel plot of the equation (x^n + y^n) mod m

Code:
from math import *
from kandinsky import *
print("EWS 2020-05-28")
print("x**n + y**n mod m")
n=float(input("power? "))
m=float(input("modulus? "))

for x in range(320):
  for y in range(240):
    t=fmod(pow(x,n)+pow(y,n),m)  
    c=floor(t/m*255)
    set_pixel(x+1,y+1,color(c,c,c))

Blog link: http://edspi31415.blogspot.com/2020/06/n...phics.html
Visit this user's website Find all posts by this user
Quote this message in a reply
07-02-2020, 03:22 AM
Post: #2
RE: Numworks: Python Graphics
Hi eddie

Texas Instruments and Numworks bet on Python as a computational language to teach and learn algorithmic logic.

In the TIplanet forum I see a great document of examples in Python, running on the TI83-PREMIUM-CE calculator.
Frn doc: https://education.ti.com/html/fr/livretT...index.html

I ask you if the Numworks and TI83 calculators have simulation or PC software and if Python programs can be sent to these "simulators"

Thanks
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)