Showing posts with label fx-CG 50. Show all posts
Showing posts with label fx-CG 50. Show all posts

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.

Saturday, January 4, 2025

Casio fx-CG 50: Pseudorandom Number Generator (PRNG) Stat Plot

Casio fx-CG 50: Pseudorandom Number Generator (PRNG) Stat Plot


Introduction


This program is an inspiration from a HHC 2024 talk given by Kuba Tatarkiewicz. Tatarkiewicz’s talk is about testing RNG (random number generators). You can see it here: https://www.youtube.com/watch?v=vSDfqCK-ENk



Premise of RANDGRPH: Generate a recursive sequence


r_n = frac( (A * r_n-1 + B) ^ C)


The program builds two lists and develops a scatter plot. I have the program set up to plot 60 points, but we can up to 999 points. The list starts with the initial point (0, seed). The program asks you whether to have the calculator provide the seed or you provide a seed (between 0 and 1).



Casio fx-CG 50 Code: RANDGRPH (252 bytes)


“RAN # GRAPH”

“(A×R+B)^C” ◢

“A”? → A

“B”? → B

“C”? → C

Menu “SEED?”, “RANDOM”, 1, “YOUR OWN”, 2

Lbl 1

Ran# → R

Goto 0

Lbl 2

“0≤R<1, SEED”? → R

Lbl 0

{0} → List 1

{R} → List 2

For 1 → I To 75

Augment(List 1, {R}) → List 1

Frac((A×R+B)^C) → R

Augment(List 2,{R}) → List 2

Next

S-Gph1 DrawOn, Scatter, List 1, List 2, 1, Dot, ColorLinkOff, Black, AxesOn

DrawStat



Examples


Example 1: r_n = frac(991 * r_n-1)


r_n = frac(991 * r_n-1)


Example 2: r_n = frac( (0.3 * r_n-1 + 1)^2 )


r_n = frac( (0.3 * r_n-1 + 1)^2 )


Example 3: r_n = frac( (r_n-1 + π)^5 )


r_n = frac( (r_n-1 + π)^5 )


Enjoy! Happy New Year, be safe, sane, strong, and take care. Forever grateful,


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, October 12, 2024

Casio fx-CG 50: Centroid of a 2D spaces

Casio fx-CG 50: Centroid of a 2D spaces





The program CENTROID calculates the center point for an area covered by:


y(x) ≥ 0, x ≥ lower limit, x ≤ upper limit


The center point is calculated by:


x-center = ∫( x * y(x) dx, x = lower limit, x = upper limit) / A

y-center = ∫(1 / 2 * y(x)^2 dx, x = lower limit, x = upper limit) / A

where A = ∫( y(x) dx, x = lower limit, x = upper limit)



Casio fx-CG 50 Program Code: CENTROID


Here is the code, which includes a graphic representation of y(x) and the location of the centroid. In this code, the Y is bold and it comes from the VARS menu. Do not merely use ALPHA+Y. For calculators with monochrome screens, such as the fx-9750G/fx-9860G series, leave out the color commands (Black, Blue, Red). The program assumes that there no preset plots or more than one function to be plotted.


This program works best for functions y(x) ≥ 0 for x ∈ [lower limit, upper limit].




Here is a text-only version:






Examples


Example 1: y = x^2 , lower limit = 0, upper limit = 1

X-Center = 3 / 4 = 0.75

Y-Center = 3 / 10 = 0.3




Example 2: y = 2 * cos( x / 2 ), lower limit = 0, upper limit = π

X-Center ≈ 1.141592654

Y-Center ≈ 0.7853981634




Example 3: y = 3, lower limit = 1, upper limit = 5

X-Center = 3

Y-Center = 1.5




Example 4: y = -4 * x^2 + 2 * x + 6, lower limit = -0.5, upper limit = 1

X-Center = 1 / 4

Y-Center = 307 / 110




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.

Sunday, March 24, 2024

 

Casio fx-7000G vs Casio fx-CG 50: A Comparison of Generating Statistical Graphs



Today’s blog entry is a comparison of how a histogram, normal distribution graphs based on statistical data, scatter plots, and linear regression plot are generated on Casio’s first graphing calculator, the fx-7000G (1985) and the most recent (as of this blog post), the fx-CG 50 (2016). For the curious, the SD2 and LR2 modes are the statistical plot modes of the fx-7000G.


The procedures for the fx-7000G are the same for the fx-6500G, fx-7500G, fx-8000G (and equivalents) and fx-6300G.


The procedures for the fx-CG 50 are the same for the fx-CG 10/20, the fx-9860G series, and fx-9750G series.





Single Variable: Histogram Graphs and Normal Distribution Graphs


The screen shots for this section uses the example data:


Rank #

Rank (List 1)

Frequency (List 2)

1

10

11

2

20

19

3

30

36

4

40

39

5

50

33

6

60

13


Histogram: fx-7000G


1. Enter SD2 mode by pressing [ SHIFT ] [ MODE ] [ × ]. Execute Cls to clear the graph screen and Scl to clear the statistical data registers.

2. There is no automatic zoom adjustment for statistical data on the fx-7000G. Observe the data and set the range accordingly.

3. Count the number of ranks. We have to set aside additional memory registers for the bars. Do this by pressing [ SHIFT ] [ MODE ] [ . ] (Defm mode) and entering the number of ranks. For the data set above, we will need 6 additional registers (Defm 6).

4. Enter the data by using the [x^y] key, which acts as the data entry (DT) key for this mode. The format for each point is: rank ; frequency.

5. Draw the bar graphing by pressing [Graph] [ EXE ]. In other words, run the Graph Y= command without any other arguments. The bar graph can be traced.


(Note: The range I used is: Xmin: 10, Xmax: 70, Xscl: 10, Ymin: 0, Ymin: 40, Yscl: 10)





Normal Distribution Graph: fx-7000G


1. Clear the graph screen by executing Cls.

2. Redo the range. The y-values will have a probability of 1 or less. I like to set Ymin to a very small negative value so that the graph won’t be at the bottom of the screen.

3. Draw the normal graph by pressing [Graph] [SHIFT] [ ↑ ] {Line} 1 [ EXE ]. The command line is Graph Y=Line 1. The normal distribution curve can be traced.


Don’t forget to reset the memory to Defm 0 (or the setting you had) when you are done. Allocating for extra memory registers reduces the amount of program steps available.





Histogram: fx-CG 50


On the fx-CG 50, everything is done through the Statistics Mode. We can use any list from List 1 to List 26, generate multiple data sets and graphs, and on the fx-CG 10/20 and fx-CG 50, the graphs are in color.


1. For this graph, listed the ranks in List 1 and frequencies in List 2. From the main menu, press [ F1 ] {GRAPH}, [ F6 ] { SET }, and either [ F1 ], [ F2 ], or [ F3 ] to choose the graph slot Graph1, Graph2, or Graph3, respectively. Set the Graph Type to Hist.

2. Exit the setup by pressing [ EXIT ], and next press the corresponding graph slot. We will be prompted for the start value (Xmin) and the width (size of the rank). Press [ EXE ]. On the fx-CG 50, we do not have to worry about the window ranges because the Statistics mode automatically zooms the window to fit the data. Nice! The histogram can be traced.





Normal Distribution Graph: fx-CG 50


1. From the main menu, press [ F1 ] {GRAPH}, [ F6 ] { SET }. Change the Graph Type to N-Dist.

2. Exit the set up and press the graph slot. Again, the window zooms to fit the curve. The normal curve can be traced.




Linear Regression: Scatter Plot and Linear Regression Plot


X: (List 1)

Y: (List 2)

-8

-10

-4

-6

-1

0

2

3

5

6

8

8


Scatter Plot: fx-7000G


1. Enter LR2 mode by pressing [ SHIFT ] [ MODE ] [ ÷ ]. Execute Cls to clear the graph screen and Scl to clear the statistical data registers.

2. Adjust the Range (viewing window) to fit the data.

3. Enter the data by using the [x^y] key, which acts as the data entry (DT) key for this mode. The format for each point is: x, y.


If the point occurs more than once, use the format x, y; frequency.


The scatter plot dynamically updates and is shown each time a point is added.





Linear Regression Plot: fx-7000G


The line fits to the equation y = A + Bx (A is the y-intercept, B is the slope).


1. Execute the command Graph Y=Line 1 by pressing by pressing [Graph] [SHIFT] [ ↑ ] {Line} 1 [ EXE ]. The line is then plotted and can be traced. Easy as that.





Scatter Plot: fx-CG 50


Execute the statistics mode and enter the data. Like the histogram and normal distribution plots, the fx-CG 50 automatically adjusts the window to fit the statistical data for the scatter plot and linear regression line.


1. For this graph, List 1 has the x data and List 2 has the y data. From the main menu, press [ F1 ] {GRAPH}, [ F6 ] { SET }, and either [ F1 ], [ F2 ], or [ F3 ] to choose the graph slot Graph1, Graph2, or Graph3, respectively. Set the Graph Type to Scatter. You have an option of selecting the shape of the markers of the point.

2. Exit the setup by pressing [ EXIT ], and next press the corresponding graph slot. The scatter plot will be shown and you can trace the points.





Linear Regression Plot: fx-CG 50


1. While we are on the scatter plot screen, press [ F1 ] {CALC}, then [ F2 ] { X }. We have a choice of two forms: ax+b (default) or a+bx. I chose a+bx to match the fx-7000G.

2. The regression equation, along with the intercept, slope, and correlation are shown. When ready, press [ F6 ] {DRAW}.

3. The regression line is drawn, and the line can be traced.





I hope you enjoyed the comparisons between the classic fx-7000G and modern fx-CG 50.


Until next time,


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.

Sunday, March 17, 2024

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode






The Probability Simulation add-in has six types of probability simulations:

* Coin Toss

* Dice Roll

* Spinner

* Marble Grab

* Card Draw

* Random Numbers


The add-in application is available for the following calculators:

* Casio fx-9750GIII and fx-9860GIII (and Graph 75/85/95 series, Graph 35+ E II)

* Casio fx-CG 10/20 and fx-CG 50 (and Graph 90+E)

* Casio fx-9860G


I believe on the fx-9750GIII and fx-9860GIII, the Probability Simulation Add-In is available out of the box. For others, the add-in can be downloaded through Casio’s Worldwide Education Website: https://edu.casio.com/download/index.php.


Let’s look at three ways we can use the Probability Simulation add-in in games of chance. This is a great app when you don’t have a pair of dice, playing cards, or a bag of marbles around.


In the Set Up menu, there is an option for seed from 1 to 99999.


Screen shots are from the fx-CG 50.


Interaction with Other Modes


* Data can be stored into global lists 1-26. Lists in these Casio calculators contain only numerical information. Numerical codes are used for card suits and face cards.


* There are no commands from the Add-In that can be used in programming. The simulation is mean to be a stand-alone app.




Drawing a Poker Hand






From the main screen, press F5 for Card Draw. To simulate poker, go into set up by pressing [SHIFT] {SET UP}. We can set either a 52 playing card deck, which is the standard deck without Jokers, or a reduced deck of 32 cards (sevens through Aces only). We don’t want Replacement, so turn that off. Press [ EXIT ] to go back to the simulation.


To draw a single card, press [ F1 ]. To draw multiple cards, press [ F2 ] for { +n }. At the prompt, press [AC/ON] and enter the number of cards.


We will have to memorize the cards or note the down on paper or another writing device.


To save the cards drawn, select [ F3 ] (STORE). There are three lists:


Draw: Draw number

Value: Card value. 1 = Ace, 11 = Jack, 12 = Queen, 13 = King

Suit: 1 = Heart, 2 = Club, 3 = Spade, 4 = Diamond


Lists can be allocated to the global list variables List 1 to List 26. Press [ F6 ] { EXE } to store the cards. Storing results works similarly in other applications.



Rolling Dice in Adventure Games





In adventure and fantasy games such as Dungeon and Dragons, sometimes dice beyond the standard six-sided die is needed. The Dice Roll (F2 from the Main Menu) has dice that are four-sided, six-sided, eight-sided, twelve-sided, and twenty-sided. Up to three dice can be thrown at once.


A Simple Lottery





Random integers from 0 to 99 can be drawn with the Random Numbers. Again, the set up menu is the key. For the lottery, turn the Repeat option off. Above are four draws from a simple lottery from 63 numbers.



This has been a look at Casio’s Probability Simulation Add-In. Until next time,


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.


RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric) The Stopping Sight Distance Formula – Derivation The stopping sight di...