Showing posts with label drawing. Show all posts
Showing posts with label drawing. Show all posts

Saturday, June 21, 2025

Numworks vs TI-83 Premium/TI-84 Plus CE Python: Drawing and Equals Sign Using Turtle

Numworks vs TI-83 Premium/TI-84 Plus CE Python: Drawing and Equals Sign Using Turtle


Even though many graphing calculators now have Python, and many of them have the same-named modules, the modules and commands can differ between calculators. It is very important to consult the calculator’s manual and the calculator’s help facilities to see what the particular calculator can and can not do.


The goal of halfequ.py is to draw an equals sign using the Turtle module.




Numworks: halfequ.py


from math import *
from turtle import *

# drawing equals sign
# Numworks

def hequ():
  for i in range(10):
    setheading(0)
    forward(120)
    right(90)
    forward(1)
    right(90)
    forward(120)
    left(90)
    forward(1)

# draw equals sign

speed(7)
penup()
goto(-60,-20)
pendown()
hequ()

penup()
goto(-60,40)
pendown()
hequ()

penup()
goto(0,0)
setheading(0)


TI-84 Plus CE Python/TI-83 Premium Python Edition: HALFEQU.py


from turtle import *
t=Turtle()

def hequ():
  for i in range(10):
    t.setheading(0)
    t.forward(120)
    t.right(90)
    t.forward(1)
    t.right(90)
    t.forward(120)
    t.left(90)
    t.forward(1)

t.speed(7)
t.penup()
t.goto(-60,-20)
t.pendown()
hequ()

t.penup()
t.goto(-60,40)
t.pendown()
hequ()

t.penup()
t.home()
t.done()


Notes


* The turtle module is an add-on module for the TI-84 Plus CE/TI-83 Premium Python Edition, which requires a separate download.

* The Numworks turtle does not require named object of turtle like TI does. The TI requiring a “named” turtle may open the possibility of having more than one turtle.

* The TI’s command, t.home(), puts the turtle at point (0,0) with an orientation of 0°.

* In TI’s turtle, t.done() must be at the end of the code in order for the drawing to commence.

* In Numworks, the turtle is represented as a turtle, while the TI’s turtle is represented as an arrow.

* In Numworks, the turtle can be displayed or hidden by the showturtle() or hideturtle() command, respectively.

* Numworks’ drawing range: x = [-160, 160], y = [-111, 111].

* TI’s turtle drawing range: x = [-160, 160], y = [-120, 120].


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 5, 2025

Casio fx-CG 50: Draw a Polygon of Vertices

Casio fx-CG 50: Draw a Polygon of Vertices 



Introduction


The program POLYPTS draws a polygon of vertices and calculates the area.



Casio fx-CG 50 Program: POLYPTS


ClrGraph

S-WindAuto

“# POINTS”? → N

(1 + N) → Dim List 1

(1 + N) → Dim List 2

For 1 → I to N

ClrText

Green Locate 1, 7, “POINT”

Red Locate 7, 7, I

“X”? → List 1[ I ]

“Y”? → List 2[ I ]

Next

List 1[ 1 ] → List 1[N + 1]

List 2[ 1 ] → List 2[N + 1]

0 → A

For 2 → I To N+1

A + (List 1[ I ] × List 2[I – 1] – List 1[I – 1] × List 2[ I ]) → A

Next

Abs A ÷ 2 → A

“AREA = “

A ◢

S-Gph 1 DrawOn, xyLine, List 1, List 2, 1, Square, ColorLinkOff, ColorAuto

DrawStat



Examples



Example 1: 4 Points


(0, 14)

(5, 5)

(18, 0)

(0, -4)


Area = 116




Example 2: 4 Points


(4, 10)

(15, 10)

(11, 2)

(2, 2)


Area = 80





Example 3: 5 Points


(1, 1)

(4, 2)

(3, 6)

(0, 4)

(0, 2)


Area = 13





Next time, an anniversary for the blog...  14 years!   Gratitude as always,



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, March 15, 2025

Casio Python with fx-CG 50: Drawing Shapes with Casioplot (draws.py)

Casio Python with fx-CG 50: Drawing Shapes with Casioplot (draws.py)


The Casio file draws.py is a file that use both the casioplot and math modules and contains four drawing functions.


The plot functions uses the pixel system.


Upper left hand corner: (0, 0)

Upper right hand corner: (383, 0)

Lower left hand corner: (0, 191)

Lower right hand corner: (383, 191)


The x axis increases going right and the y axis increases going down. This orientation is common for a pixel-orientated coordinate system.


Note that the pixels must be integers. A non-integer value for a pixel will cause an error.



Importing the draws module


After copying the file draws.py to your calculator, type: from draws import *


The casioplot and math modules will also be imported because the draws module is imported. This is the case of the fx-CG 50, and I’m pretty sure it will work with the other Casio calculators with Python (fx-9750GIII, fx-9860GIII, fx-CG 100, Graph Math+).


To clear the drawing screen, use the casioplot’s command clear_screen().


To show the picture, use the casioplot’s command show_screen().


The functions from the draws must be manually typed, as they will not appear in the catalog or VARS menu.



sline(x,sx,y,sy,l,c)


Draws a line from (x,y) of length l and color c. The color is a three-element tuple in the RGB format ((red, green, blue)).


The arguments sx and sy are direction/slope arguments which dictate the direction of the line.


To draw a line going left (←)

Set sx = -1 and sy = 0

To draw a line going right (→)

Set sx = 1 and sy = 0

To draw a line going up (↑)

Set sx = 0 and sy = -1

To draw a line going down (↓)

Set sx = 0 and sy = 1

To draw a line going right and up (↗)

Set sx = 1 and sy = -1

To draw a line going left and up (↖)

Set sx = -1 and sy = -1

To draw a line going right and down (↘)

Set sx = 1 and sy = 1

To draw a line going left and down (↙)

Set sx = -1 and sy = 1


Examples:

sline(1,1,1,0,140,(255,0,0)) draws a red line starting from (1,1) going right with length of 140 pixels


sline(180,0,100,-1,50,(0,255,0)) draws a green line starting from (180,100) going up with length of 50 pixels





The sample file draw1.py is a demonstration of the sline command.






box(x,xl,y,yl,c)


The box function draws a box with the upper left hand corner (x,y) with color c, horizontal length (width) xl, and vertical length (height) yl. The box draws to the right and down. The box is filled with the specified color. If xl = yl, the function will draw a square.


Example:

box(20,100,40,150,(128,128,128)) draws a gray rectangle with upper-left corner at (20,40) with horizontal length of100 and vertical length of 150.


box(300,60,0,60,(0,0,0)) draws a black square with upper-left corner at (300, 0) with the side length of 60.





The sample file draw2.py uses the box function to generate a random game map of land (green) and water (blue).






tri(x,xd,y,yd,l,c)


The tri function draws a 45-45-90 right triangle. The point (x,y) is the corner point that contains the right angle of 90°. The arguments xd and yd dictate the direction of the triangle (see table below).





The triangle is filled with color c. The sides of the triangle will be drawn with length l.


Example:


tri(80,1,80,-1,75,(0,128,128)) draws a teal 45-45-90 right triangle with the right angle located at (80, 80). The length is 75 pixels.





The sample file draw3.py uses the tri function to draw four triangles, one with each proper orientation.






circ(x,y,r,c)


The circ function draws a circle centered at (x, y) with radius r and color c. The circle is drawn as outline and not filled. To make the circle appear as smooth as possible, 720 points are plotted.


Example:

circ(190,100,85,(255,128,0)) draws an orange circle with radius 85, centered at (190, 100).





The file draw4.py demonstrates the circ function.






Casio fx-CG 50 Python: draws.py code


# drawing utilities

# 12-04-2024


from casioplot import *

from math import *


def sline(x,sx,y,sy,l,c):

  for i in range(l+1):

    set_pixel(x+sx*i,y+sy*i,c)


# upper left corner

def box(x,xl,y,yl,c):

  for i in range(xl+1):

    for j in range(yl+1):

      set_pixel(x+i,y+j,c)


# right triangle

# (x,y) point with right angle

# l=length

# xd=1 right, xd=-1 left

# yd=1 down, yd=-1 up

def tri(x,xd,y,yd,l,c):

  for i in range(l+1):

    k=l-i

    for j in range(k+1):

      set_pixel(x+xd*i,y+yd*j,c)


# hallow circle

def circ(x,y,r,c):

for i in range(721):

  t=2*pi*i/720

  xr=int(x+r*cos(t))

  yr=int(y+r*sin(t))

  set_pixel(xr,yr,c)



You can download the draws.py and the example Python files here:

https://drive.google.com/file/d/1rGQHa60V7ZCE9Vs0kYy0cfIe0pOXqVaZ/view?usp=sharing


I hope you enjoy this program as much as I have making it,



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.

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.


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...