p5-python 0.6.12__tar.gz → 0.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,291 @@
1
+ Metadata-Version: 2.4
2
+ Name: p5-python
3
+ Version: 0.9.1
4
+ Summary: A package wrapping pygame functionality in p5.js calling conventions.
5
+ License: MIT
6
+ Author: Grygoriy Gromko
7
+ Author-email: gr.gromko@gmail.com
8
+ Requires-Python: >=3.8.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Requires-Dist: PyOpenGL (>=3.1.0,<4.0.0)
20
+ Requires-Dist: pycairo (>=1.20.0,<2.0.0)
21
+ Requires-Dist: pygame (>=2.1.2,<3.0.0)
22
+ Project-URL: Homepage, https://github.com/gromko/p5-python
23
+ Project-URL: Repository, https://github.com/gromko/p5-python
24
+ Description-Content-Type: text/markdown
25
+
26
+ # p5-python
27
+
28
+ `p5-python` brings the friendly [p5.js](https://p5js.org/) drawing API to
29
+ Python. It is a free and open-source library built by an inclusive, nurturing
30
+ community and welcomes artists, designers, beginners, educators, and anyone
31
+ else.
32
+
33
+ Sketches are written with familiar p5 conventions (`setup`, `draw`,
34
+ `createCanvas`, `background`, `fill`, ...) and rendered with
35
+ [pygame](https://www.pygame.org/) and [Cairo](https://cairographics.org/).
36
+
37
+ ## Installation
38
+
39
+ ```sh
40
+ pip install p5-python
41
+ ```
42
+
43
+ Requirements: Python 3.8+, `pygame >= 2.1.2`, `pycairo >= 1.20.0`.
44
+
45
+ ## Quick start
46
+
47
+ Create `sketch.py`:
48
+
49
+ ```python
50
+ from p5 import *
51
+
52
+
53
+ def setup():
54
+ createCanvas(640, 360)
55
+
56
+
57
+ def draw():
58
+ background(20)
59
+ fill(255, 120, 40)
60
+ noStroke()
61
+ circle(mouseX, mouseY, 60)
62
+
63
+
64
+ run()
65
+ ```
66
+
67
+ Run it either directly or through the module runner:
68
+
69
+ ```sh
70
+ python sketch.py
71
+ python -m p5 sketch.py
72
+ ```
73
+
74
+ ## What is supported
75
+
76
+ ### Canvas and program flow
77
+
78
+ `createCanvas`, `resizeCanvas`, `saveCanvas`, `saveFrame`, `background`,
79
+ `clear`, `run`, `stop`, `frameRate`, `getFrameRate`, `loop`, `noLoop`,
80
+ `redraw`, `isLooping`, `cursor`, `noCursor`, `pixelDensity`, `smooth`,
81
+ `noSmooth`, `angleMode`.
82
+
83
+ Angles are measured in **radians** by default, matching p5.js. Call
84
+ `angleMode(DEGREES)` if you prefer degrees.
85
+
86
+ ### Shapes
87
+
88
+ `point`, `line`, `rect`, `square`, `ellipse`, `circle`, `arc`, `triangle`,
89
+ `quad`, `bezier`, `curve`, plus the vertex API:
90
+
91
+ ```python
92
+ beginShape()
93
+ vertex(100, 100)
94
+ vertex(200, 40)
95
+ vertex(300, 100)
96
+ endShape(CLOSE)
97
+ ```
98
+
99
+ `beginShape()` accepts `POINTS`, `LINES`, `LINE_STRIP`, `TRIANGLES`,
100
+ `TRIANGLE_STRIP`, `TRIANGLE_FAN`, `QUADS`, and `QUAD_STRIP`. Vertices can be
101
+ mixed with `curveVertex()` and `bezierVertex()`; `endShape(CLOSE)` closes and
102
+ fills the outline.
103
+
104
+ Drawing modes: `rectMode`, `ellipseMode`, `imageMode` (`CORNER`, `CORNERS`,
105
+ `CENTER`, `RADIUS`).
106
+
107
+ ### Colour
108
+
109
+ `fill`, `stroke`, `noFill`, `noStroke`, `color`, `colorMode`, `lerpColor`,
110
+ and the channel accessors `red`, `green`, `blue`, `alpha`, `hue`,
111
+ `saturation`, `brightness`, `lightness`.
112
+
113
+ `colorMode()` supports `RGB` and `HSB` with custom ranges, plus an optional
114
+ alpha range.
115
+
116
+ ### Typography
117
+
118
+ `text`, `textFont`, `textSize`, `textStyle`, `textAlign`, `textWidth`,
119
+ `textLeading`, `textWrap`, `loadFont`.
120
+
121
+ ### Images and pixels
122
+
123
+ `loadImage`, `image`, `PImage`, `createImage`, `tint`, `noTint`,
124
+ `loadPixels`, `updatePixels`, `get`, `set`, `blendMode`. `get()`/`set()` work
125
+ on both the whole canvas and rectangular regions, and `pixels` is exposed as a
126
+ writable RGBA list. `saveCanvas` and `saveFrame` write PNG files (with a JPG
127
+ fallback).
128
+
129
+ `PImage` objects can be created in memory, edited pixel by pixel, and drawn:
130
+
131
+ ```python
132
+ img = createImage(64, 64)
133
+ img.loadPixels()
134
+ for i in range(0, len(img.pixels), 4):
135
+ img.pixels[i:i + 4] = [255, 128, 0, 255]
136
+ img.updatePixels()
137
+
138
+ tint(255, 150)
139
+ image(img, 20, 20)
140
+ noTint()
141
+ ```
142
+
143
+ `screen.pixels` is an alias for the global `pixels` array, and
144
+ `println(...)`/`print(...)` write to standard output.
145
+
146
+ ### Math and randomness
147
+
148
+ `abs`, `ceil`, `floor`, `round`, `sq`, `sqrt`, `pow`, `exp`, `log`, `log2`,
149
+ `log10`, `logb`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`,
150
+ `degrees`, `radians`, `dist`, `mag`, `map`, `norm`, `lerp`, `constrain`,
151
+ `sign`, `min`, `max`, `random`, `randomSeed`, `randomGaussian`, `noise`,
152
+ `noiseSeed`, `noiseDetail`, `shuffle`, `nf`.
153
+
154
+ ### Transforms
155
+
156
+ `push`, `pop`, `translate`, `rotate`, `scale`, `shearX`, `shearY`,
157
+ `applyMatrix`, `resetMatrix`. Transforms use a real affine matrix, so they
158
+ compose and nest correctly.
159
+
160
+ ### Vectors
161
+
162
+ ```python
163
+ v = createVector(3, 4)
164
+ v.add(createVector(1, 2))
165
+ print(v.mag()) # 6.324...
166
+ print(v.heading())
167
+ ```
168
+
169
+ `Vector` (also available as `PVector`) supports `add`, `sub`, `mult`, `div`,
170
+ `mag`, `magSq`, `normalize`, `limit`, `heading`, `rotate`, `lerp`, `dist`,
171
+ `dot`, `cross`, `copy`, `get`, `set`, `setMag`, and the usual operators.
172
+
173
+ ### Compatibility helpers
174
+
175
+ For sketches written in a Processing style the following are also available:
176
+
177
+ - `environment` (`frameCount`, `width`, `height`, `focused`, ...)
178
+ - `keyboard` (`key`, `keyCode`, `keyIsPressed`, `keys`)
179
+ - `mouse` (`x`, `y`, `px`, `py`, `pressed`, `button`, ...)
180
+ - `focused`
181
+ - `textAscent()`, `textDescent()`
182
+ - `WEBGL` mode renders real 3D geometry with PyOpenGL: `box`, `sphere`,
183
+ `torus`, `cone`, `cylinder`, `ambientLight`, `directionalLight`,
184
+ `rotateX/Y/Z`, and `translate(x, y, z)`.
185
+
186
+ ### Events and live values
187
+
188
+ Define any of these functions in your sketch and they are called
189
+ automatically:
190
+
191
+ `keyPressed`, `keyReleased`, `mousePressed`, `mouseReleased`,
192
+ `mouseClicked`, `doubleClicked`, `mouseMoved`, `mouseDragged`,
193
+ `mouseWheel`.
194
+
195
+ Mouse callbacks may either take no parameters or an `event` argument:
196
+
197
+ ```python
198
+ def mousePressed():
199
+ print(mouse.x, mouse.y)
200
+
201
+ def mouseWheel(event):
202
+ radius += event.delta
203
+ ```
204
+
205
+ Mouse events expose `x`, `y`, `button`, `delta`, `dx`, `dy`, and `pos`.
206
+ The live `mouse` object groups the same state:
207
+
208
+ ```python
209
+ mouse.x, mouse.y # current position
210
+ mouse.px, mouse.py # previous position
211
+ mouse.pressed # button held down
212
+ mouse.button # LEFT / RIGHT / CENTER
213
+ ```
214
+
215
+ Live values are available as bare names (and as attributes such as
216
+ `p5.mouseX`):
217
+
218
+ `width`, `height`, `displayWidth`, `displayHeight`, `windowWidth`,
219
+ `windowHeight`, `mouseX`, `mouseY`, `pmouseX`, `pmouseY`, `movedX`,
220
+ `movedY`, `mouseButton`, `mouseIsPressed`, `mouseWheelDelta`, `key`,
221
+ `keyCode`, `keyIsPressed`, `frameCount`, `deltaTime`, `pixels`,
222
+ `is_Looping`.
223
+
224
+ `mouseX` and `mouseY` can be used either as properties (`mouseX + 10`) or as
225
+ functions (`mouseX()`), so both p5.js-style and Processing-style sketches work.
226
+
227
+ `keyCode` compares equal to the matching constants (`SPACE`, `LEFT_ARROW`,
228
+ `A`, ...), while `key` holds the typed character where available. Use
229
+ `keyIsDown(...)` for continuous input:
230
+
231
+ ```python
232
+ if keyIsDown(LEFT_ARROW):
233
+ x -= 5
234
+ ```
235
+
236
+ ## Constants
237
+
238
+ Constants such as `PI`, `TWO_PI`, `HALF_PI`, `TAU`, `CENTER`, `CORNER`,
239
+ `CORNERS`, `RADIUS`, `CLOSE`, `OPEN`, `RGB`, `HSB`, `LEFT`, `RIGHT`, `TOP`,
240
+ `BOTTOM`, `BASELINE`, arrow keys, letter/number key codes, `BLEND`, `ADD`,
241
+ `MULTIPLY`, `SCREEN`, `OVERLAY`, `DARKEST`, `LIGHTEST`, `DIFFERENCE`,
242
+ `EXCLUSION`, `REPLACE`, and the shape-kind constants are all exported by
243
+ `from p5 import *`.
244
+
245
+ ## Differences from p5.js
246
+
247
+ - Rendering uses pygame/Cairo instead of an HTML canvas.
248
+ - `LEFT`/`RIGHT` are mouse- and text-alignment constants (`"left"`,
249
+ `"right"`). For the arrow keys use `LEFT_ARROW`/`RIGHT_ARROW`.
250
+ - `loadFont` accepts a path to a TrueType/OpenType font; system fonts can be
251
+ selected by family name.
252
+ - Web-specific APIs (DOM, WEBGL, sound, video) are not implemented.
253
+
254
+ ## Project layout
255
+
256
+ ```
257
+ p5/
258
+ color.py colour parsing, colour modes, fill/stroke
259
+ constants.py p5 constants, key codes, blend/shape modes
260
+ corefunctions.py sketch lifecycle, primitives, pixels, images, events
261
+ image.py PImage, createImage and image pixel helpers
262
+ mathfunctions.py math, random, noise
263
+ renderer.py Cairo drawing backend
264
+ settings.py live sketch state
265
+ timedata.py date/time helpers
266
+ transform.py affine transform stack
267
+ vector.py Vector and createVector
268
+ ```
269
+
270
+ ## Examples and tests
271
+
272
+ Runnable sketches live in `examples/`:
273
+
274
+ ```sh
275
+ pip install -e .
276
+ python examples/basic_shapes.py
277
+ python examples/interactive.py
278
+ python examples/animation.py
279
+ ```
280
+
281
+ The headless test suite runs without a display:
282
+
283
+ ```sh
284
+ python -m unittest discover -s tests
285
+ ```
286
+
287
+ ## License
288
+
289
+ MIT. See the project page for details and contributions:
290
+ <https://github.com/gromko/p5-python>.
291
+
@@ -0,0 +1,265 @@
1
+ # p5-python
2
+
3
+ `p5-python` brings the friendly [p5.js](https://p5js.org/) drawing API to
4
+ Python. It is a free and open-source library built by an inclusive, nurturing
5
+ community and welcomes artists, designers, beginners, educators, and anyone
6
+ else.
7
+
8
+ Sketches are written with familiar p5 conventions (`setup`, `draw`,
9
+ `createCanvas`, `background`, `fill`, ...) and rendered with
10
+ [pygame](https://www.pygame.org/) and [Cairo](https://cairographics.org/).
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pip install p5-python
16
+ ```
17
+
18
+ Requirements: Python 3.8+, `pygame >= 2.1.2`, `pycairo >= 1.20.0`.
19
+
20
+ ## Quick start
21
+
22
+ Create `sketch.py`:
23
+
24
+ ```python
25
+ from p5 import *
26
+
27
+
28
+ def setup():
29
+ createCanvas(640, 360)
30
+
31
+
32
+ def draw():
33
+ background(20)
34
+ fill(255, 120, 40)
35
+ noStroke()
36
+ circle(mouseX, mouseY, 60)
37
+
38
+
39
+ run()
40
+ ```
41
+
42
+ Run it either directly or through the module runner:
43
+
44
+ ```sh
45
+ python sketch.py
46
+ python -m p5 sketch.py
47
+ ```
48
+
49
+ ## What is supported
50
+
51
+ ### Canvas and program flow
52
+
53
+ `createCanvas`, `resizeCanvas`, `saveCanvas`, `saveFrame`, `background`,
54
+ `clear`, `run`, `stop`, `frameRate`, `getFrameRate`, `loop`, `noLoop`,
55
+ `redraw`, `isLooping`, `cursor`, `noCursor`, `pixelDensity`, `smooth`,
56
+ `noSmooth`, `angleMode`.
57
+
58
+ Angles are measured in **radians** by default, matching p5.js. Call
59
+ `angleMode(DEGREES)` if you prefer degrees.
60
+
61
+ ### Shapes
62
+
63
+ `point`, `line`, `rect`, `square`, `ellipse`, `circle`, `arc`, `triangle`,
64
+ `quad`, `bezier`, `curve`, plus the vertex API:
65
+
66
+ ```python
67
+ beginShape()
68
+ vertex(100, 100)
69
+ vertex(200, 40)
70
+ vertex(300, 100)
71
+ endShape(CLOSE)
72
+ ```
73
+
74
+ `beginShape()` accepts `POINTS`, `LINES`, `LINE_STRIP`, `TRIANGLES`,
75
+ `TRIANGLE_STRIP`, `TRIANGLE_FAN`, `QUADS`, and `QUAD_STRIP`. Vertices can be
76
+ mixed with `curveVertex()` and `bezierVertex()`; `endShape(CLOSE)` closes and
77
+ fills the outline.
78
+
79
+ Drawing modes: `rectMode`, `ellipseMode`, `imageMode` (`CORNER`, `CORNERS`,
80
+ `CENTER`, `RADIUS`).
81
+
82
+ ### Colour
83
+
84
+ `fill`, `stroke`, `noFill`, `noStroke`, `color`, `colorMode`, `lerpColor`,
85
+ and the channel accessors `red`, `green`, `blue`, `alpha`, `hue`,
86
+ `saturation`, `brightness`, `lightness`.
87
+
88
+ `colorMode()` supports `RGB` and `HSB` with custom ranges, plus an optional
89
+ alpha range.
90
+
91
+ ### Typography
92
+
93
+ `text`, `textFont`, `textSize`, `textStyle`, `textAlign`, `textWidth`,
94
+ `textLeading`, `textWrap`, `loadFont`.
95
+
96
+ ### Images and pixels
97
+
98
+ `loadImage`, `image`, `PImage`, `createImage`, `tint`, `noTint`,
99
+ `loadPixels`, `updatePixels`, `get`, `set`, `blendMode`. `get()`/`set()` work
100
+ on both the whole canvas and rectangular regions, and `pixels` is exposed as a
101
+ writable RGBA list. `saveCanvas` and `saveFrame` write PNG files (with a JPG
102
+ fallback).
103
+
104
+ `PImage` objects can be created in memory, edited pixel by pixel, and drawn:
105
+
106
+ ```python
107
+ img = createImage(64, 64)
108
+ img.loadPixels()
109
+ for i in range(0, len(img.pixels), 4):
110
+ img.pixels[i:i + 4] = [255, 128, 0, 255]
111
+ img.updatePixels()
112
+
113
+ tint(255, 150)
114
+ image(img, 20, 20)
115
+ noTint()
116
+ ```
117
+
118
+ `screen.pixels` is an alias for the global `pixels` array, and
119
+ `println(...)`/`print(...)` write to standard output.
120
+
121
+ ### Math and randomness
122
+
123
+ `abs`, `ceil`, `floor`, `round`, `sq`, `sqrt`, `pow`, `exp`, `log`, `log2`,
124
+ `log10`, `logb`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`,
125
+ `degrees`, `radians`, `dist`, `mag`, `map`, `norm`, `lerp`, `constrain`,
126
+ `sign`, `min`, `max`, `random`, `randomSeed`, `randomGaussian`, `noise`,
127
+ `noiseSeed`, `noiseDetail`, `shuffle`, `nf`.
128
+
129
+ ### Transforms
130
+
131
+ `push`, `pop`, `translate`, `rotate`, `scale`, `shearX`, `shearY`,
132
+ `applyMatrix`, `resetMatrix`. Transforms use a real affine matrix, so they
133
+ compose and nest correctly.
134
+
135
+ ### Vectors
136
+
137
+ ```python
138
+ v = createVector(3, 4)
139
+ v.add(createVector(1, 2))
140
+ print(v.mag()) # 6.324...
141
+ print(v.heading())
142
+ ```
143
+
144
+ `Vector` (also available as `PVector`) supports `add`, `sub`, `mult`, `div`,
145
+ `mag`, `magSq`, `normalize`, `limit`, `heading`, `rotate`, `lerp`, `dist`,
146
+ `dot`, `cross`, `copy`, `get`, `set`, `setMag`, and the usual operators.
147
+
148
+ ### Compatibility helpers
149
+
150
+ For sketches written in a Processing style the following are also available:
151
+
152
+ - `environment` (`frameCount`, `width`, `height`, `focused`, ...)
153
+ - `keyboard` (`key`, `keyCode`, `keyIsPressed`, `keys`)
154
+ - `mouse` (`x`, `y`, `px`, `py`, `pressed`, `button`, ...)
155
+ - `focused`
156
+ - `textAscent()`, `textDescent()`
157
+ - `WEBGL` mode renders real 3D geometry with PyOpenGL: `box`, `sphere`,
158
+ `torus`, `cone`, `cylinder`, `ambientLight`, `directionalLight`,
159
+ `rotateX/Y/Z`, and `translate(x, y, z)`.
160
+
161
+ ### Events and live values
162
+
163
+ Define any of these functions in your sketch and they are called
164
+ automatically:
165
+
166
+ `keyPressed`, `keyReleased`, `mousePressed`, `mouseReleased`,
167
+ `mouseClicked`, `doubleClicked`, `mouseMoved`, `mouseDragged`,
168
+ `mouseWheel`.
169
+
170
+ Mouse callbacks may either take no parameters or an `event` argument:
171
+
172
+ ```python
173
+ def mousePressed():
174
+ print(mouse.x, mouse.y)
175
+
176
+ def mouseWheel(event):
177
+ radius += event.delta
178
+ ```
179
+
180
+ Mouse events expose `x`, `y`, `button`, `delta`, `dx`, `dy`, and `pos`.
181
+ The live `mouse` object groups the same state:
182
+
183
+ ```python
184
+ mouse.x, mouse.y # current position
185
+ mouse.px, mouse.py # previous position
186
+ mouse.pressed # button held down
187
+ mouse.button # LEFT / RIGHT / CENTER
188
+ ```
189
+
190
+ Live values are available as bare names (and as attributes such as
191
+ `p5.mouseX`):
192
+
193
+ `width`, `height`, `displayWidth`, `displayHeight`, `windowWidth`,
194
+ `windowHeight`, `mouseX`, `mouseY`, `pmouseX`, `pmouseY`, `movedX`,
195
+ `movedY`, `mouseButton`, `mouseIsPressed`, `mouseWheelDelta`, `key`,
196
+ `keyCode`, `keyIsPressed`, `frameCount`, `deltaTime`, `pixels`,
197
+ `is_Looping`.
198
+
199
+ `mouseX` and `mouseY` can be used either as properties (`mouseX + 10`) or as
200
+ functions (`mouseX()`), so both p5.js-style and Processing-style sketches work.
201
+
202
+ `keyCode` compares equal to the matching constants (`SPACE`, `LEFT_ARROW`,
203
+ `A`, ...), while `key` holds the typed character where available. Use
204
+ `keyIsDown(...)` for continuous input:
205
+
206
+ ```python
207
+ if keyIsDown(LEFT_ARROW):
208
+ x -= 5
209
+ ```
210
+
211
+ ## Constants
212
+
213
+ Constants such as `PI`, `TWO_PI`, `HALF_PI`, `TAU`, `CENTER`, `CORNER`,
214
+ `CORNERS`, `RADIUS`, `CLOSE`, `OPEN`, `RGB`, `HSB`, `LEFT`, `RIGHT`, `TOP`,
215
+ `BOTTOM`, `BASELINE`, arrow keys, letter/number key codes, `BLEND`, `ADD`,
216
+ `MULTIPLY`, `SCREEN`, `OVERLAY`, `DARKEST`, `LIGHTEST`, `DIFFERENCE`,
217
+ `EXCLUSION`, `REPLACE`, and the shape-kind constants are all exported by
218
+ `from p5 import *`.
219
+
220
+ ## Differences from p5.js
221
+
222
+ - Rendering uses pygame/Cairo instead of an HTML canvas.
223
+ - `LEFT`/`RIGHT` are mouse- and text-alignment constants (`"left"`,
224
+ `"right"`). For the arrow keys use `LEFT_ARROW`/`RIGHT_ARROW`.
225
+ - `loadFont` accepts a path to a TrueType/OpenType font; system fonts can be
226
+ selected by family name.
227
+ - Web-specific APIs (DOM, WEBGL, sound, video) are not implemented.
228
+
229
+ ## Project layout
230
+
231
+ ```
232
+ p5/
233
+ color.py colour parsing, colour modes, fill/stroke
234
+ constants.py p5 constants, key codes, blend/shape modes
235
+ corefunctions.py sketch lifecycle, primitives, pixels, images, events
236
+ image.py PImage, createImage and image pixel helpers
237
+ mathfunctions.py math, random, noise
238
+ renderer.py Cairo drawing backend
239
+ settings.py live sketch state
240
+ timedata.py date/time helpers
241
+ transform.py affine transform stack
242
+ vector.py Vector and createVector
243
+ ```
244
+
245
+ ## Examples and tests
246
+
247
+ Runnable sketches live in `examples/`:
248
+
249
+ ```sh
250
+ pip install -e .
251
+ python examples/basic_shapes.py
252
+ python examples/interactive.py
253
+ python examples/animation.py
254
+ ```
255
+
256
+ The headless test suite runs without a display:
257
+
258
+ ```sh
259
+ python -m unittest discover -s tests
260
+ ```
261
+
262
+ ## License
263
+
264
+ MIT. See the project page for details and contributions:
265
+ <https://github.com/gromko/p5-python>.