p5-python 0.6.12__py3-none-any.whl → 0.9.1__py3-none-any.whl

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.
p5/__init__.py CHANGED
@@ -1,47 +1,294 @@
1
+ """p5-python: a friendly Python drawing library using p5.js conventions.
2
+
3
+ A minimal sketch looks like this::
4
+
5
+ from p5 import *
6
+
7
+ def setup():
8
+ createCanvas(400, 400)
9
+
10
+ def draw():
11
+ background(220)
12
+ circle(width / 2, height / 2, 100)
13
+
14
+ run()
15
+
16
+ The module intentionally exports the most commonly used p5 functions. Live
17
+ values such as ``mouseX``, ``width`` or ``frameCount`` are available as bare
18
+ names inside a sketch (they are backed by :mod:`builtins`), and can also be
19
+ read as ``p5.mouseX`` etc.
20
+ """
21
+
22
+ import builtins
1
23
  import os
2
- os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
3
-
4
- from p5.corefunctions import (run, createCanvas, saveCanvas, angleMode, rectMode, ellipseMode,
5
- line, ellipse, circle, rect, quad, arc, triangle, bezier,
6
- point, beginShape, vertex, curveVertex, curve, bezierVertex,
7
- endShape, cursor, strokeWeight, noStroke,
8
- loadImage, image, keyIsDown, frameRate, loop, noLoop,
9
- background,text,textFont, textSize, textStyle, textAlign)
10
-
11
- from p5.constants import (TWO_PI, HALF_PI, PI, QUARTER_PI, TAU, CURSOR_ARROW, CURSOR_DIAMOND,
12
- CURSOR_BROKEN_X, CURSOR_TRI_LEFT, CURSOR_TRI_RIGHT, BOLD, ITALIC, BOLDITALIC, NORMAL,
13
- BACKSPACE,TAB,RETURN,ENTER,PAUSE,ESCAPE,SPACE,DELETE,EXCLAIM,QUOTEDBL,HASH,DOLLAR,AMPERSAND,QUOTE,LEFTPAREN,RIGHTPAREN,
14
- ASTERISK,PLUS,COMMA,MINUS,PERIOD,SLASH,COLON,SEMICOLON,LESS,EQUALS,GREATER,QUESTION,AT,LEFTBRACKET,RIGHTBRACKET,CARET,
15
- UNDERSCORE,BACKQUOTE,UP,DOWN,RIGHT,LEFT,UP_ARROW,DOWN_ARROW,LEFT_ARROW,RIGHT_ARROW,INSERT,HOME,END,PAGEUP,PAGEDOWN,PGUP,
16
- PGDN,KP0,KP1,KP2,KP3,KP4,KP5,KP6,KP7,KP8,KP9,KP_PERIOD,KP_DIVIDE,KP_MULTIPLY,KP_MINUS,KP_PLUS,F1,F2,F3,F4,F5,
17
- F6,F7,F8,F9,F10,F11,F12,NUMLOCK,CAPSLOCK,SCROLLOCK,RSHIFT,LSHIFT,RCTRL,LCTRL,RALT,LALT,RMETA,LMETA,CONTEXTMENU,
18
- PRINT,SYSREQ,BREAK,MENU,CENTER,CLOSE,RADIANS,DEGREES, CORNER, CORNERS, RADIUS,CHORD, PIE, OPEN, ARC)
19
-
20
- from p5.mathfunctions import (pow, map, randomSeed, random, constrain, floor, ceil, dist, exp, lerp, log, log10, log2, logb, mag,
21
- rerange, norm, sq, sqrt, frac, sin, cos, tan, asin, acos, atan, atan2, degrees, radians, integral)
22
-
23
- from p5.color import (fill,noFill, stroke, red, green, blue, brightness, hue, lightness, saturation, lerpColor, color, alpha)
24
-
25
- from p5.timedata import (hour, minute, second, day, month, year, milli_sec, millis)
26
-
27
- from p5.transform import (scale, rotate, translate, push, pop, resetMatrix)
28
-
29
- __all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "line", "ellipse", "circle", "rect", "triangle", "quad", "arc",
30
- "push", "pop", "cursor", "TWO_PI", "HALF_PI", "PI", "QUARTER_PI", "TAU", "CURSOR_ARROW", "CURSOR_DIAMOND", "CURSOR_BROKEN_X", "CURSOR_TRI_LEFT",
31
- "CURSOR_TRI_RIGHT", "BOLD", "ITALIC", "BOLDITALIC", "NORMAL", "strokeWeight", "stroke", "noStroke", "loadImage", "image", "point", "CORNER", "CORNERS", "RADIUS",
32
- "frameRate", "random", "constrain", "floor", "ceil", "dist", "exp", "lerp", "log", "log10", "log2", "logb", "mag", "textAlign", "CHORD", "PIE", "OPEN", "ARC",
33
- "rerange", "norm", "sq", "sqrt", "frac", "sin", "cos", "tan", "asin", "acos", "atan", "atan2", "degrees", "radians", "loop", "noLoop", "integral",
34
- "text","textFont", "textSize", "textStyle","beginShape", "vertex", "endShape", "keyIsDown", "saveCanvas", "scale", "rotate", "translate", "rectMode", "ellipseMode",
35
- "BACKSPACE","TAB","RETURN","ENTER","PAUSE","ESCAPE","SPACE","DELETE","EXCLAIM","QUOTEDBL","HASH","DOLLAR","AMPERSAND","QUOTE","LEFTPAREN","RIGHTPAREN",
36
- "ASTERISK","PLUS","COMMA","MINUS","PERIOD","SLASH","COLON","SEMICOLON","LESS","EQUALS","GREATER","QUESTION","AT","LEFTBRACKET","RIGHTBRACKET","CARET",
37
- "UNDERSCORE","BACKQUOTE","UP","DOWN","RIGHT","LEFT","UP_ARROW","DOWN_ARROW","LEFT_ARROW","RIGHT_ARROW","INSERT","HOME","END","PAGEUP","PAGEDOWN","PGUP",
38
- "PGDN","KP0","KP1","KP2","KP3","KP4","KP5","KP6","KP7","KP8","KP9","KP_PERIOD","KP_DIVIDE","KP_MULTIPLY","KP_MINUS","KP_PLUS","F1","F2","F3","F4","F5",
39
- "F6","F7","F8","F9","F10","F11","F12","NUMLOCK","CAPSLOCK","SCROLLOCK","RSHIFT","LSHIFT","RCTRL","LCTRL","RALT","LALT","RMETA","LMETA","CONTEXTMENU",
40
- "PRINT","SYSREQ","BREAK","MENU","CENTER","CLOSE", "pow", "map", "angleMode", "curveVertex", "randomSeed", "resetMatrix",
41
- "hour", "minute", "second", "day", "month", "year", "milli_sec", "millis", "curve", "bezierVertex", "bezier"
42
- ]
43
24
 
44
- __version__ = "0.6.12"
25
+ os.environ.setdefault("PYGAME_HIDE_SUPPORT_PROMPT", "hide")
26
+
27
+ import p5.constants as _constants
28
+
29
+ from p5.constants import * # noqa: F401,F403
30
+ from p5.constants import __all__ as _constant_names
31
+
32
+ from p5.corefunctions import ( # noqa: F401
33
+ angleMode,
34
+ arc,
35
+ background,
36
+ beginShape,
37
+ bezier,
38
+ bezierVertex,
39
+ blendMode,
40
+ circle,
41
+ clear,
42
+ createCanvas,
43
+ curve,
44
+ curveVertex,
45
+ cursor,
46
+ doubleClicked,
47
+ ellipse,
48
+ ellipseMode,
49
+ endShape,
50
+ eventsManager,
51
+ frameRate,
52
+ get,
53
+ getFrameRate,
54
+ image,
55
+ imageMode,
56
+ isLooping,
57
+ keyIsDown,
58
+ line,
59
+ loadFont,
60
+ loadImage,
61
+ loadPixels,
62
+ loop,
63
+ mouseClicked,
64
+ mouseDragged,
65
+ mouseMoved,
66
+ mousePressed,
67
+ mouseReleased,
68
+ mouseWheel,
69
+ mouse,
70
+ noCursor,
71
+ noLoop,
72
+ noSmooth,
73
+ noTint,
74
+ pixelDensity,
75
+ point,
76
+ quad,
77
+ rect,
78
+ rectMode,
79
+ redraw,
80
+ resizeCanvas,
81
+ run,
82
+ saveCanvas,
83
+ saveFrame,
84
+ screen,
85
+ set,
86
+ smooth,
87
+ square,
88
+ stop,
89
+ strokeCap,
90
+ strokeJoin,
91
+ strokeWeight,
92
+ text,
93
+ textAlign,
94
+ textFont,
95
+ textLeading,
96
+ textSize,
97
+ textStyle,
98
+ textWidth,
99
+ textWrap,
100
+ tint,
101
+ triangle,
102
+ updatePixels,
103
+ vertex,
104
+ print,
105
+ println,
106
+ )
107
+
108
+ from p5.image import PImage, createImage # noqa: F401
109
+
110
+ from p5.color import ( # noqa: F401
111
+ alpha,
112
+ blue,
113
+ brightness,
114
+ color,
115
+ colorMode,
116
+ fill,
117
+ green,
118
+ hue,
119
+ lerpColor,
120
+ lightness,
121
+ noFill,
122
+ noStroke,
123
+ red,
124
+ saturation,
125
+ stroke,
126
+ )
45
127
 
46
- print("Thank you for using p5\n")
128
+ from p5.mathfunctions import ( # noqa: F401
129
+ abs,
130
+ acos,
131
+ asin,
132
+ atan,
133
+ atan2,
134
+ ceil,
135
+ constrain,
136
+ cos,
137
+ degrees,
138
+ dist,
139
+ exp,
140
+ floor,
141
+ frac,
142
+ fract,
143
+ integral,
144
+ lerp,
145
+ log,
146
+ log10,
147
+ log2,
148
+ logb,
149
+ mag,
150
+ map,
151
+ max,
152
+ min,
153
+ noise,
154
+ noiseDetail,
155
+ noiseSeed,
156
+ norm,
157
+ nf,
158
+ pow,
159
+ radians,
160
+ random,
161
+ randomGaussian,
162
+ randomSeed,
163
+ rerange,
164
+ round,
165
+ shuffle,
166
+ sign,
167
+ sin,
168
+ sq,
169
+ sqrt,
170
+ tan,
171
+ )
172
+
173
+ from p5.timedata import ( # noqa: F401
174
+ day,
175
+ hour,
176
+ milli_sec,
177
+ millis,
178
+ minute,
179
+ month,
180
+ second,
181
+ year,
182
+ )
183
+
184
+ from p5.transform import ( # noqa: F401
185
+ applyMatrix,
186
+ pop,
187
+ push,
188
+ resetMatrix,
189
+ rotate,
190
+ scale,
191
+ shearX,
192
+ shearY,
193
+ translate,
194
+ )
195
+
196
+ from p5.corefunctions import ( # noqa: F401
197
+ ambientLight,
198
+ box,
199
+ camera,
200
+ cone,
201
+ cylinder,
202
+ directionalLight,
203
+ environment,
204
+ frustum,
205
+ keyboard,
206
+ noLights,
207
+ ortho,
208
+ perspective,
209
+ pointLight,
210
+ rotateX,
211
+ rotateY,
212
+ rotateZ,
213
+ sphere,
214
+ spotLight,
215
+ textAscent,
216
+ textDescent,
217
+ torus,
218
+ )
219
+
220
+ from p5.vector import Vector, createVector # noqa: F401
221
+
222
+ PVector = Vector # Processing-style alias
223
+
224
+ __version__ = "0.9.1"
225
+
226
+
227
+ # Names that are live values rather than functions. They are stored in
228
+ # builtins so sketches can use ``width``, ``mouseX``, ... directly; __getattr__
229
+ # makes ``p5.width`` work as well.
230
+ _LIVE_VALUES = {
231
+ "width", "height", "displayWidth", "displayHeight", "windowWidth",
232
+ "windowHeight", "mouseX", "mouseY", "pmouseX", "pmouseY", "movedX",
233
+ "movedY", "mouseButton", "mouseIsPressed", "mouseWheelDelta", "key",
234
+ "keyCode", "keyIsPressed", "frameCount", "deltaTime", "pixels",
235
+ "is_Looping", "focused",
236
+ }
237
+
238
+
239
+ def __getattr__(name):
240
+ if name in _LIVE_VALUES:
241
+ return getattr(builtins, name)
242
+ raise AttributeError("module {!r} has no attribute {!r}".format(__name__, name))
243
+
244
+
245
+ __all__ = list(_constant_names) + [
246
+ # canvas / environment
247
+ "run", "createCanvas", "resizeCanvas", "saveCanvas", "saveFrame",
248
+ "background", "clear", "frameRate", "getFrameRate", "loop", "noLoop",
249
+ "redraw", "isLooping", "cursor", "noCursor", "pixelDensity", "smooth",
250
+ "noSmooth", "angleMode", "stop",
251
+ # shapes
252
+ "arc", "ellipse", "circle", "line", "point", "quad", "rect", "square",
253
+ "triangle", "bezier", "curve", "beginShape", "vertex", "curveVertex",
254
+ "bezierVertex", "endShape",
255
+ # drawing settings
256
+ "ellipseMode", "rectMode", "imageMode", "strokeWeight", "strokeCap",
257
+ "strokeJoin", "blendMode",
258
+ # typography
259
+ "text", "textFont", "textSize", "textStyle", "textAlign", "textWidth",
260
+ "textLeading", "textWrap", "loadFont", "textAscent", "textDescent",
261
+ # images / pixels
262
+ "loadImage", "image", "PImage", "createImage", "tint", "noTint",
263
+ "loadPixels", "updatePixels", "get", "set", "screen",
264
+ # utilities
265
+ "print", "println",
266
+ # colour
267
+ "fill", "noFill", "stroke", "noStroke", "color", "colorMode", "alpha",
268
+ "red", "green", "blue", "brightness", "hue", "lightness", "saturation",
269
+ "lerpColor",
270
+ # math
271
+ "abs", "ceil", "constrain", "cos", "degrees", "dist", "exp", "floor",
272
+ "frac", "fract", "integral", "lerp", "log", "log10", "log2", "logb",
273
+ "mag", "map", "max", "min", "noise", "noiseDetail", "noiseSeed", "norm",
274
+ "pow", "radians", "random", "randomGaussian", "randomSeed", "rerange",
275
+ "round", "sign", "sin", "sq", "sqrt", "tan", "atan", "atan2", "acos",
276
+ "asin", "shuffle", "nf",
277
+ # transform
278
+ "applyMatrix", "pop", "push", "resetMatrix", "rotate", "scale", "shearX",
279
+ "shearY", "translate",
280
+ # vectors
281
+ "Vector", "createVector", "PVector",
282
+ # time
283
+ "day", "hour", "milli_sec", "millis", "minute", "month", "second", "year",
284
+ # input
285
+ "keyIsDown", "mouse", "keyboard", "environment", "doubleClicked",
286
+ "focused",
287
+ # 3d (compatibility stubs)
288
+ "ambientLight", "directionalLight", "pointLight", "spotLight", "noLights",
289
+ "box", "sphere", "torus", "cone", "cylinder", "camera", "perspective",
290
+ "ortho", "frustum", "rotateX", "rotateY", "rotateZ",
291
+ ]
47
292
 
293
+ # Remove duplicates while keeping a deterministic order.
294
+ __all__ = list(dict.fromkeys(__all__))
p5/__main__.py CHANGED
@@ -1,50 +1,35 @@
1
- #
2
- # Part of p5: A Python package based on Processing
3
- # Copyright (C) 2017-2019 Abhik Pal
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful, but
11
- # WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #
18
-
19
- from . import p5
20
-
21
- # we should be parsing sys args here and expose a series of commands
22
- # similar to processing-java.
23
- #
24
- # relevant output from `processing-java --help`:
25
- #
26
- # --help Show this help text. Congratulations.
27
- #
28
- # --sketch=<name> Specify the sketch folder (required)
29
- #
30
- # --output=<name> Specify the output folder (optional and
31
- # cannot be the same as the sketch folder.)
32
- #
33
- # --force The sketch will not build if the output
34
- # folder already exists, because the contents
35
- # will be replaced. This option erases the
36
- # folder first. Use with extreme caution!
37
- #
38
- # --build Preprocess and compile a sketch into .class files.
39
- #
40
- # --run Preprocess, compile, and run a sketch.
41
- #
42
- # --present Preprocess, compile, and run a sketch in presentation mode.
43
- #
44
- # --export Export an application.
45
- #
46
- # --no-java Do not embed Java. Use at your own risk!
47
- #
48
- # --platform Specify the platform (export to application only).
49
- # Should be one of 'windows', 'macosx', or 'linux'.
50
- #
1
+ """Command line helper: ``python -m p5 sketch.py``.
2
+
3
+ The sketch itself is expected to call :func:`p5.run` (the usual p5 style).
4
+ """
5
+
6
+ import argparse
7
+ import runpy
8
+ import sys
9
+
10
+ from p5 import __version__
11
+
12
+
13
+ def main(argv=None):
14
+ parser = argparse.ArgumentParser(
15
+ prog="p5",
16
+ description="Run a p5-python sketch.",
17
+ )
18
+ parser.add_argument("sketch", nargs="?", help="path to a Python sketch file")
19
+ parser.add_argument("--version", action="version", version="p5-python " + __version__)
20
+ args = parser.parse_args(argv)
21
+
22
+ if not args.sketch:
23
+ parser.print_help()
24
+ return 1
25
+
26
+ try:
27
+ runpy.run_path(args.sketch, run_name="__main__")
28
+ except FileNotFoundError:
29
+ print("p5: sketch not found: {}".format(args.sketch), file=sys.stderr)
30
+ return 1
31
+ return 0
32
+
33
+
34
+ if __name__ == "__main__":
35
+ sys.exit(main())