Showing posts with label turtle. Show all posts
Showing posts with label turtle. Show all posts

Sunday, February 16, 2025

A Comparison of Algorithmique vs. Python Turtle (Casio fx-92 Collège vs. Numworks)

A Comparison of Algorithmique vs. Python Turtle (Casio fx-92 Collège vs. Numworks)


The Casio fx-92 Collège from France has an algorithm mode, which is essentially a program mode. The language is designed to be an easy-to-use program and can be viewed online as Scratch program code. I would love to see Casio sell this calculator world wide instead on just France, I think this calculator would give an excellent introduction to coding (at any age).


On today’s blog, I’m going to compare the Algorithmique programming language to Python’s Turtle module in drawing three simple shapes. The calculator I’m using for Python is Numworks. I’m forever grateful to Google Translate, as I am not fluent in French.


The Commands


Casio fx-92 Collège Algorithmique French

Casio fx-92 Collège Algorithmique French

Python Turtle Command (Numworks)

Python Built-In Command

Avancer de n

Move forward n

forward(n)


Tourner de ⟲ Θ

Turn from ⟲ Θ

Θ > 0: left(Θ)

Θ < 0: right(Θ)


S’ orienter à Θ

Orient yourself to Θ

setheading(Θ)


Aller à x; y

Go to x; y

goto(x,y)


Stylo écrit

Pen writes

pendown()


Stylo relevè

Pen raised

penup()


Metire var á

(Shown as expression → var)

Set var to

(Shown as expression → var)


var = expression

Demander valeur

(Shown as ? → var)

Ask for a value

(Shown as ? → var)


var = input(“optional prompt string)

[float, eval, int, default is a string]

Commenataire

(shown as one of four comments)

Comment out of four per-programmed strings


print(almost anything you want”)

Afficher résult var

Show result var


print(var)

Style

Style (Style of Cursor)

Turtle has a turtle character. Show or hide by showturtle()/hideturtle()


Attendre

Pause

N/A

N/A (though we can use an artificial for loop that does nothing)

Répéter n ( ↑ )

Repeat n ( ↑ )


For i in range(n):

Répéter jusqúa cond

Repeat until cond


While (not cond):

Si Alors (Fin)

If Then (End)


If: structure

Si Alors Sinon (Fin)

If Then Else (End)


If: Else: structure


The four per-programmed strings are:

“Oui” Yes

“Non” No

“Nombre?” Number?

“Résultat :” Result :


Using a per-programmed string pauses the algorithm and requires a press of either [ OK ] or [ EXE ] to continue.



The fx-92 Collège offers to styles of cursors: Arrows (Fléche) or Cross (Criox)


The pixel screen of the fx-92 Collège is 191 x 48 pixels, with the x coordinates ranging from -95 to 96 and the y coordinates raging from -24 to 48.


The pixel screen (Turtle) for the Numworks is 320 x 222 pixels, with the x coordinates ranging from -160 to 160 and the y coordinates ranging from -111 to 111.


Drawing a Square




fx-92 Collège:

? →A

Stylo relevé

Avancer de A÷2 pixels

Stylo écrit

Tourner de ⟲ 90 degrés

Avancer de A÷2 pixels

Répéter 3

  Tourner de ⟲ 90 degrés

  Avancer de A pixels

Tourner de ⟲ 90 degrés

Avancer de A pixels


Numworks:

from math import *
from turtle import *

print("Draw a Square")
s=eval(input("side length? "))

penup()
forward(s/2)
pendown()
left(90)
forward(s/2)

for i in range(3):
  left(90)
  forward(s)

left(90)
forward(s/2)


Drawing a Triangle



fx-92 Collège:


? →A

? →B

Stylo relevé

Aller à x= A÷2 ; y= B÷2

Stylo écrit

Aller à x= A÷2 ; y= B÷2

Aller à x= 0 ; y= B÷2

Aller à x= A÷2 ; y= B÷2



Numworks:

from math import *
from turtle import *

print("Draw a Triangle")
s=eval(input("base? "))
h=eval(input("height? "))

penup()
goto(-s/2,-h/2)

pendown()
goto(s/2,-h/2)
goto(0,h/2)
goto(-s/2,-h/2)



Drawing a Circle





fx-92 Collège:


? →A

Stylo relevé

Aller à x= A ; y= 0

Stylo écrit

0 →z

Répéter 120

  z3 →z

  Aller à x= A×cos(z°) ; y= A×sin(z°)


Numworks:

from math import *

from turtle import *

print("Draw a Circle")
r=eval(input("radius? "))

penup()
right(90)
forward(r)
left(90)
pendown()
circle(r)


The Algorithmique (similar to Scratch) and Turtle language is comparable and these examples demonstrates similarities and differences of both languages.  


Source


Casio. “Algorithmque/Programmation” (French)

https://www.casio-education.fr/algorithmique-programmation/ Retrieved January 26, 2025



Eddie


All original content copyright, © 2011-2025. 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, April 22, 2023

Python: Drawing Regular Polygons (TI-84 CE Python, Numworks)

Python:  Drawing Regular Polygons (TI-84 CE Python, Numworks)



Introduction



The following scripts uses the Turtle module to draw regular polygons.   It turns out that every set of commands is slightly different in every calculator.  


For instance, there are no color names in the TI-84 Plus CE Python but they are present in Numworks.  


Also, the turtle module needs a t. (t-point) suffix of all turtle commands for the TI-84 Plus CE Python.  The Numworks turtle module does not need a suffix. 



TI-84 Plus CE Python:  dpolygon.py


from turtle import *

t=Turtle()


# initialization

s=60

n=int(input("# of sides? "))


# angle

a=180*(n-2)/n


# set turtle for TI-84

# color

k=-1

while k<0  or  k>4:

  print("Choose Color")

  print("0. blue")

  print("1. red")

  print("2. green")

  print("3. orange")

  print("4. indigo")

  k=int(input())

if k==0:

  t.pencolor(0,0,255)

if k==1:

  t.pencolor(255,0,0)

if k==2:

  t.pencolor(0,192,0)

if k==3:

  t.pencolor(255,165,0)

if k==4:

  t.pencolor(75,0,130)


t.clear()


# setup

t.penup()

t.left(180)

t.forward(60)

t.left(90)

t.forward(60)

t.left(90)


# draw the polygon

t.pendown()

for i in range(n):

  if n>6:

    t.forward(s/2)

  else:

    t.forward(s)

  t.left(180-a)

t.done()




Numworks Python:  dpythonnw.py


from math import *

from turtle import *


# initialization

s=60

n=int(input("# of sides? "))


# angle

a=180*(n-2)/n


# set color numworks

k=-1

l=['blue','red','green','orange','purple']

while k<0 or k>4:

  print("Choose Color")

  print("0. blue")

  print("1. red")

  print("2. green")

  print("3. orange")

  print("4. purple")

  k=int(input())

col=l[k]


# setup

penup()

left(180)

forward(60)

left(90)

forward(60)

left(90)


# draw the polygon

pendown()

color(col)

for i in range(n):

  if n>6:

    forward(s/2)

  else:

    forward(s)

  left(180-a)




Until next time,


Eddie 


All original content copyright, © 2011-2023.  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, June 5, 2022

TI-84 Plus CE Python: Polygon Path (ppath.py)

TI-84 Plus CE Python:  Polygon Path (ppath.py)


Introduction


The program PPATH:


Between two points:  


1.  Calculates the required leftward, counter-clockwise angle.


2.  Calculates the distance to be traveled. 


The path starts at the origin (0,0).  You can create open paths or closed polygons.  For polygons, add another point and include (0,0) as the last point.  


TI-84 Plus CE Python Program:  PPATH - Python (ppath)


Download the TI-84 Plus CE Python file here:  https://drive.google.com/file/d/1QnPP9ikx45i7gAH22fTkFAmE-pBFQwTD/view?usp=sharing


Copy the code for a text file.  


print("Poly Path \nEdward Shore")

# 2022-04-27

from math import *

from turtle import *

t=Turtle()

# t is required for turtle

from ti_system import *


# hide the grid

t.hidegrid()


# obtain the points

x=[0]

y=[0]

# angles

g=[0]

# degree difference

q=[0]

# distance

d=[0]


print("Point 0: (0,0)")

print("#_0 to #_n-1")

n=eval(input("# points? "))


for i in range(1,n):  

  a=eval(input("x"+str(i)+"? "))

  b=eval(input("y"+str(i)+"? "))

  x.append(a)

  y.append(b)

  r=sqrt((a-x[i-1])**2+(b-y[i-1])**2)

  d.append(r)

  m=degrees(atan2(b-y[i-1],a-x[i-1]))

  v=m-g[i-1]

  if v<0:

    v+=360

  g.append(m)

  q.append(v)

  r6=round(r,6)

  m6=round(v,6)

  print("Distance: "+str(r6))

  print("Left Turn: "+str(m6)+"\u00b0")


print("\nPress [clear] to continue.")

disp_wait()


t.home()

t.pencolor(0,128,0)

# set speed

t.speed(4)

for i in range:

  t.left(q[i])

  t.forward(d[i])

t.done()


Notes:


1.  Turtle is a add-in module for the TI-84 Plus CE Python, which must be downloaded. Download the Turtle module here:  https://education.ti.com/en/product-resources/turtle-module/ti84ce-python


2.  Calling the Turtle module automatically assigns the variable t to a drawing turtle by the line t=Turtle().


3.  The ti_system module is exclusive to the TI-84 Plus CE.  This allows the program to pause with the disp_wait command.  


4.  The underscore character ( _ ) can be typed by the [ 2nd ] [ (-) ] (ans) sequence.  


5.  The hashtag character ( # ) can be typed by the [ 2nd ] [ 3 ] (L3) sequence.  


6.  The line for i in range(1,n) starts a for loop with i taking the values from 1 to n-1. This is good for lists when the initial point (point 0) does not need further processing. 


7.  The default operating angle measurement in Python is Radians.  


8.  The angle difference, which tells us how many degrees to turn left, is normalized to the 0°-360° range.   This is optional.   


9.  The line t.home() sets the turtle to point (0,0) and sets the turtle's orientation to 0° (facing right, forward on the x-axis).


10.  The line t.done() shows the results of the turtle commands. 


Examples


Example 1: Quadrilateral




Example 2:  An Open Path




Enjoy!  


Eddie 



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


Basic vs. Python: Circle Inscribed in Circle [HP 71B, Casio fx-CG 100]

Basic vs. Python: Circle Inscribed in Circle Calculators Used: Basic: HP 71B Python: Casio fx-CG 100 Introduction ...