p5-python 0.5.4__tar.gz → 0.6.12__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p5-python
3
- Version: 0.5.4
3
+ Version: 0.6.12
4
4
  Summary: A package wrapping pygame functionality in p5.js calling conventions.
5
5
  Home-page: https://github.com/gromko/p5-python
6
6
  Author: Grygoriy Gromko
@@ -1,9 +1,9 @@
1
1
  import os
2
2
  os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
3
3
 
4
- from p5.corefunctions import (run, createCanvas, saveCanvas, angleMode,
5
- line, ellipse, circle, rect, quad, arc, triangle,
6
- point, beginShape, vertex, curveVertex,
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
7
  endShape, cursor, strokeWeight, noStroke,
8
8
  loadImage, image, keyIsDown, frameRate, loop, noLoop,
9
9
  background,text,textFont, textSize, textStyle, textAlign)
@@ -24,8 +24,6 @@ from p5.color import (fill,noFill, stroke, red, green, blue, brightness, hue, li
24
24
 
25
25
  from p5.timedata import (hour, minute, second, day, month, year, milli_sec, millis)
26
26
 
27
- from p5.drawcurve import (bezier,spline)
28
-
29
27
  from p5.transform import (scale, rotate, translate, push, pop, resetMatrix)
30
28
 
31
29
  __all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "line", "ellipse", "circle", "rect", "triangle", "quad", "arc",
@@ -33,17 +31,17 @@ __all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "
33
31
  "CURSOR_TRI_RIGHT", "BOLD", "ITALIC", "BOLDITALIC", "NORMAL", "strokeWeight", "stroke", "noStroke", "loadImage", "image", "point", "CORNER", "CORNERS", "RADIUS",
34
32
  "frameRate", "random", "constrain", "floor", "ceil", "dist", "exp", "lerp", "log", "log10", "log2", "logb", "mag", "textAlign", "CHORD", "PIE", "OPEN", "ARC",
35
33
  "rerange", "norm", "sq", "sqrt", "frac", "sin", "cos", "tan", "asin", "acos", "atan", "atan2", "degrees", "radians", "loop", "noLoop", "integral",
36
- "text","textFont", "textSize", "textStyle","beginShape", "vertex", "endShape", "keyIsDown", "saveCanvas", "scale", "rotate", "translate",
34
+ "text","textFont", "textSize", "textStyle","beginShape", "vertex", "endShape", "keyIsDown", "saveCanvas", "scale", "rotate", "translate", "rectMode", "ellipseMode",
37
35
  "BACKSPACE","TAB","RETURN","ENTER","PAUSE","ESCAPE","SPACE","DELETE","EXCLAIM","QUOTEDBL","HASH","DOLLAR","AMPERSAND","QUOTE","LEFTPAREN","RIGHTPAREN",
38
36
  "ASTERISK","PLUS","COMMA","MINUS","PERIOD","SLASH","COLON","SEMICOLON","LESS","EQUALS","GREATER","QUESTION","AT","LEFTBRACKET","RIGHTBRACKET","CARET",
39
37
  "UNDERSCORE","BACKQUOTE","UP","DOWN","RIGHT","LEFT","UP_ARROW","DOWN_ARROW","LEFT_ARROW","RIGHT_ARROW","INSERT","HOME","END","PAGEUP","PAGEDOWN","PGUP",
40
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",
41
39
  "F6","F7","F8","F9","F10","F11","F12","NUMLOCK","CAPSLOCK","SCROLLOCK","RSHIFT","LSHIFT","RCTRL","LCTRL","RALT","LALT","RMETA","LMETA","CONTEXTMENU",
42
40
  "PRINT","SYSREQ","BREAK","MENU","CENTER","CLOSE", "pow", "map", "angleMode", "curveVertex", "randomSeed", "resetMatrix",
43
- "hour", "minute", "second", "day", "month", "year", "milli_sec", "millis", "bezier", "spline"
41
+ "hour", "minute", "second", "day", "month", "year", "milli_sec", "millis", "curve", "bezierVertex", "bezier"
44
42
  ]
45
43
 
46
- __version__ = "0.5.04"
44
+ __version__ = "0.6.12"
47
45
 
48
46
  print("Thank you for using p5\n")
49
47
 
@@ -10,6 +10,8 @@ def get_Color(c, a=255):
10
10
  color = Color(int(c), int(c), int(c))
11
11
  elif (type(c) == str):
12
12
  color = Color(c)
13
+ if c=="green":
14
+ color = Color(int(0), int(128), int(0)) # p5.js green color
13
15
  elif (type(c) == tuple):
14
16
  color = Color(c)
15
17
  else:
@@ -35,9 +37,6 @@ def fill(*args): # set fill color
35
37
 
36
38
  def noFill():
37
39
  settings["no_fill"] = True
38
- fill_color = settings["fill_color"]
39
- fill_color[3] = 0
40
- settings["fill_color"] = fill_color
41
40
  settings["text_color"] = settings["fill_color"]
42
41
  pass
43
42
 
@@ -9,7 +9,6 @@ import builtins
9
9
  from typing import Callable, Optional
10
10
  from p5.constants import *
11
11
  from p5.timedata import *
12
- from p5.drawcurve import *
13
12
  from p5.settings import *
14
13
  from p5.color import *
15
14
  from p5.transform import *
@@ -156,20 +155,6 @@ def ctxy(c): # transform tuple x,y coordinate
156
155
  return tmp
157
156
 
158
157
 
159
- def ellipse_array(x, y, width, height,thickness,scale):
160
- rx = (width/2 + thickness)*scale
161
- ry = (height/2 + thickness) * scale
162
-
163
- cx = x * scale
164
- cy = y * scale
165
-
166
- pts =[]
167
- # Get points on ellipse
168
- for n in range(0,360):
169
- xx = cx + int(rx*math.cos(n*math.pi/180))
170
- yy = cy + int(ry*math.sin(n*math.pi/180))
171
- pts.append((xx, yy))
172
- return pts
173
158
 
174
159
  # ---- 2D PRIMITIVES ----
175
160
  def arc(x, y, w, h, start, stop, mode = ARC):
@@ -208,12 +193,20 @@ def ellipse(x, y, w, h=None):
208
193
 
209
194
  def circle(x, y, d):
210
195
  emode = builtins.ellipse_mode
196
+ w = d
211
197
  if emode == RADIUS:
212
198
  d = 2 * d
213
199
  if emode == CORNER:
214
200
  x = x + d/2
215
- y = y + d/2
216
- draw_circle(CAIRO_SURFACE, x, y, d/2)
201
+ y = y + d/2
202
+ if emode == CORNERS:
203
+ x1 = d
204
+ y1 = d
205
+ w = abs(x - x1)
206
+ h = abs(y - y1)
207
+ x = x1 + w/2
208
+ y = y1 + h/2
209
+ draw_circle(CAIRO_SURFACE, x, y, w/2)
217
210
  pass
218
211
 
219
212
  def line(x1, y1, x2, y2):
@@ -275,6 +268,14 @@ def curveVertex(x,y):
275
268
  if shape:
276
269
  curvevertices.append((x,y))
277
270
  pass
271
+
272
+ def bezierVertex(*args):
273
+ global shape, beziervertices
274
+ if shape:
275
+ if len(args) == 6:
276
+ beziervertices.append(args)
277
+ pass
278
+
278
279
 
279
280
  def endShape(*args): # draw polygon/lines or spline curve
280
281
  global shape, vertices,curvevertices
@@ -283,16 +284,44 @@ def endShape(*args): # draw polygon/lines or spline curve
283
284
  if len(vertices) > 0:
284
285
  draw_polygon(CAIRO_SURFACE, vertices)
285
286
  if len(curvevertices) > 0:
286
- spline(CAIRO_SURFACE, settings["stroke_color"], True, curvevertices,100, 0,0,0, settings["stroke_weight"])
287
+ draw_spline(CAIRO_SURFACE, curvevertices,True)
288
+ if len(beziervertices) > 0:
289
+ if len(vertices) == 1:
290
+ draw_bezier(CAIRO_SURFACE, vertices[0], beziervertices, True)
287
291
  else:
288
292
  if len(vertices) > 0:
289
293
  draw_lines(CAIRO_SURFACE, vertices)
290
294
  if len(curvevertices) > 0:
291
- spline(CAIRO_SURFACE, settings["stroke_color"], False, curvevertices,100, 0,0,0, settings["stroke_weight"])
295
+ draw_spline(CAIRO_SURFACE, curvevertices,False)
296
+ if len(beziervertices) > 0:
297
+ if len(vertices) == 1:
298
+ draw_bezier(CAIRO_SURFACE, vertices[0][0], vertices[0][1], beziervertices, False)
292
299
  shape = None
293
300
  vertices.clear()
294
301
  curvevertices.clear()
302
+ beziervertices.clear()
295
303
  pass
304
+
305
+ def curve(*args):
306
+ curvvert =[]
307
+ if len(args) > 0:
308
+ for i in range(0,len(args)-1,2):
309
+ curvvert.append((args[i],args[i+1]))
310
+ curvevertices.append(curvvert[0])
311
+ for i in range(len(curvvert)):
312
+ curvevertices.append(curvvert[i])
313
+ curvevertices.append(curvvert[len(curvvert)-1])
314
+ if len(curvevertices) > 0:
315
+ draw_spline(CAIRO_SURFACE, curvevertices,False)
316
+ curvevertices.clear()
317
+
318
+ def bezier(*args):
319
+ bz = []
320
+ if len(args) == 8:
321
+ for i in range(2,8):
322
+ bz.append(args[i])
323
+ draw_bezier(CAIRO_SURFACE, args[0], args[1], [bz], False)
324
+
296
325
 
297
326
  # ---- TYPOGRAPHY ---
298
327
 
@@ -374,18 +403,10 @@ def background(*args): # clear and set background color
374
403
  def strokeWeight(weight):
375
404
  settings["stroke_weight"] = weight
376
405
  settings["no_stroke"] = False
377
- stroke_color = settings["stroke_color"]
378
- stroke_color[3] = 255
379
- settings["stroke_color"] = stroke_color
380
- settings["text_outline"] = stroke_color
381
406
  pass
382
407
 
383
408
  def noStroke():
384
409
  settings["no_stroke"] = True
385
- stroke_color = settings["stroke_color"]
386
- stroke_color[3] = 0
387
- settings["stroke_color"] = stroke_color
388
- settings["text_outline"] = stroke_color
389
410
  pass
390
411
 
391
412
  def ellipseMode(mode):
@@ -40,8 +40,9 @@ def draw_line(surface, x1, y1, x2, y2):
40
40
  ctx.set_line_width(thickness)
41
41
  ctx.move_to(x1, y1)
42
42
  ctx.line_to(x2, y2)
43
- ctx.set_source_rgba(*bgra(stroke_color))
44
- ctx.stroke()
43
+ if not(settings["no_stroke"]):
44
+ ctx.set_source_rgba(*bgra(stroke_color))
45
+ ctx.stroke()
45
46
 
46
47
  def draw_rect(surface, x, y, width, height):
47
48
  rotate_angle = a_radians(settings["rotate_amnt"])
@@ -56,10 +57,12 @@ def draw_rect(surface, x, y, width, height):
56
57
  ctx.rotate(rotate_angle)
57
58
  ctx.rectangle(x, y, width, height)
58
59
  ctx.set_line_width(thickness)
59
- ctx.set_source_rgba(*bgra(fill_color))
60
- ctx.fill_preserve()
61
- ctx.set_source_rgba(*bgra(stroke_color))
62
- ctx.stroke()
60
+ if not(settings["no_fill"]):
61
+ ctx.set_source_rgba(*bgra(fill_color))
62
+ ctx.fill_preserve()
63
+ if not(settings["no_stroke"]):
64
+ ctx.set_source_rgba(*bgra(stroke_color))
65
+ ctx.stroke()
63
66
 
64
67
  def draw_polygon(surface, vertices):
65
68
  rotate_angle = a_radians(settings["rotate_amnt"])
@@ -77,10 +80,12 @@ def draw_polygon(surface, vertices):
77
80
  ctx.line_to(*vertices[n])
78
81
  ctx.close_path()
79
82
  ctx.set_line_width(thickness)
80
- ctx.set_source_rgba(*bgra(fill_color))
81
- ctx.fill_preserve()
82
- ctx.set_source_rgba(*bgra(stroke_color))
83
- ctx.stroke()
83
+ if not(settings["no_fill"]):
84
+ ctx.set_source_rgba(*bgra(fill_color))
85
+ ctx.fill_preserve()
86
+ if not(settings["no_stroke"]):
87
+ ctx.set_source_rgba(*bgra(stroke_color))
88
+ ctx.stroke()
84
89
 
85
90
  def draw_lines(surface, vertices):
86
91
  rotate_angle = a_radians(settings["rotate_amnt"])
@@ -96,8 +101,9 @@ def draw_lines(surface, vertices):
96
101
  for n in range(1,len(vertices)):
97
102
  ctx.line_to(*vertices[n])
98
103
  ctx.set_line_width(thickness)
99
- ctx.set_source_rgba(*bgra(stroke_color))
100
- ctx.stroke()
104
+ if not(settings["no_stroke"]):
105
+ ctx.set_source_rgba(*bgra(stroke_color))
106
+ ctx.stroke()
101
107
 
102
108
  def draw_circle(surface, x, y, radius):
103
109
  rotate_angle = a_radians(settings["rotate_amnt"])
@@ -112,10 +118,12 @@ def draw_circle(surface, x, y, radius):
112
118
  ctx.rotate(rotate_angle)
113
119
  ctx.arc(x, y, radius, 0, 2.0 * math.pi)
114
120
  ctx.set_line_width(thickness)
115
- ctx.set_source_rgba(*bgra(fill_color))
116
- ctx.fill_preserve()
117
- ctx.set_source_rgba(*bgra(stroke_color))
118
- ctx.stroke()
121
+ if not(settings["no_fill"]):
122
+ ctx.set_source_rgba(*bgra(fill_color))
123
+ ctx.fill_preserve()
124
+ if not(settings["no_stroke"]):
125
+ ctx.set_source_rgba(*bgra(stroke_color))
126
+ ctx.stroke()
119
127
 
120
128
  def draw_ellipse(surface, x, y, width, height):
121
129
  rotate_angle = a_radians(settings["rotate_amnt"])
@@ -131,13 +139,17 @@ def draw_ellipse(surface, x, y, width, height):
131
139
  radius = width/2
132
140
  scale_x = 1.0
133
141
  scale_y = height / width
142
+ ctx.save()
134
143
  ctx.scale(scale_x, scale_y)
135
144
  ctx.arc(x, y/scale_y, radius, 0, 2.0 * math.pi)
136
145
  ctx.set_line_width(thickness)
137
- ctx.set_source_rgba(*bgra(fill_color))
138
- ctx.fill_preserve()
139
- ctx.set_source_rgba(*bgra(stroke_color))
140
- ctx.stroke()
146
+ if not(settings["no_fill"]):
147
+ ctx.set_source_rgba(*bgra(fill_color))
148
+ ctx.fill_preserve()
149
+ if not(settings["no_stroke"]):
150
+ ctx.set_source_rgba(*bgra(stroke_color))
151
+ ctx.stroke()
152
+ ctx.restore()
141
153
 
142
154
  def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
143
155
  rotate_angle = a_radians(settings["rotate_amnt"])
@@ -155,16 +167,20 @@ def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
155
167
  radius = width/2
156
168
  scale_x = 1.0
157
169
  scale_y = height / width
170
+ ctx.save()
158
171
  ctx.scale(scale_x, scale_y)
159
172
  ctx.arc(x, y/scale_y, radius, angle1, angle2)
160
173
  if (mode == "chord") or (mode == "pie"):
161
174
  ctx.close_path()
162
175
  if (mode == "chord") or (mode == "pie") or (mode == "open"):
163
- ctx.set_source_rgba(*bgra(fill_color))
164
- ctx.fill_preserve()
165
- ctx.set_source_rgba(*bgra(stroke_color))
166
- ctx.stroke()
167
-
176
+ if not(settings["no_fill"]):
177
+ ctx.set_source_rgba(*bgra(fill_color))
178
+ ctx.fill_preserve()
179
+ if not(settings["no_stroke"]):
180
+ ctx.set_source_rgba(*bgra(stroke_color))
181
+ ctx.stroke()
182
+ ctx.restore()
183
+
168
184
  def draw_text(surface, txt, x, y, style):
169
185
  rotate_angle = a_radians(settings["rotate_amnt"])
170
186
  scale_xy = settings["scale_amnt"]
@@ -196,26 +212,109 @@ def draw_text(surface, txt, x, y, style):
196
212
  if settings["text_align"] == CENTER:
197
213
  x = x - width/2
198
214
  # Render outline
199
- ctx.set_source_rgba(*bgra(stroke_color))
200
- for i in range(-thickness, thickness+1):
201
- for j in range(-thickness, thickness+1):
202
- ctx.move_to(x + i, y + j)
203
- ctx.show_text(txt)
204
-
205
- ctx.set_source_rgba(*bgra(fill_color))
215
+ if not(settings["no_stroke"]):
216
+ ctx.set_source_rgba(*bgra(stroke_color))
217
+ i = -thickness
218
+ while i < thickness-0.3 :
219
+ j =-thickness
220
+ while j < thickness-0.3 :
221
+ ctx.move_to(x + i, y + j)
222
+ ctx.show_text(txt)
223
+ j = j + 0.2
224
+ i = i + 0.2
225
+ if not(settings["no_fill"]):
226
+ ctx.set_source_rgba(*bgra(fill_color))
227
+ ctx.fill_preserve()
206
228
  ctx.move_to(x, y)
207
229
  ctx.show_text(txt)
208
- ctx.stroke()
209
- '''
210
- def draw_curve(surface,color):
211
- x, y = 100, 50
212
- x1, y1 = 140, 50
213
- x2, y2 = 60, 100
214
- x3, y3 = 190, 150
230
+ if not(settings["no_stroke"]):
231
+ ctx.set_source_rgba(*bgra(stroke_color))
232
+ ctx.stroke()
233
+
234
+ def draw_spline(surface, curvevertices, mode):
235
+ vertices =[]
236
+ rotate_angle = a_radians(settings["rotate_amnt"])
237
+ scale_xy = settings["scale_amnt"]
238
+ origin_x = settings["real_ox"]
239
+ origin_y = settings["real_oy"]
240
+ stroke_color = settings["text_outline"]
241
+ thickness = settings["stroke_weight"]
242
+ fill_color = settings["text_color"]
243
+ font_name = settings["text_font"]
244
+ font_size = settings["text_size"]
215
245
  ctx = cairo.Context(surface)
216
- ctx.move_to(x, y)
217
- ctx.curve_to(x1, y1, x2, y2, x3, y3)
218
- ctx.set_source_rgba(*bgra(color))
246
+ ctx.translate(origin_x, origin_y)
247
+ ctx.rotate(rotate_angle)
248
+ ctx.set_line_width(thickness)
249
+ vertices = list(curvevertices)
250
+ ctx.move_to(vertices[0][0],vertices[0][1] )
251
+ vertices_length = len(vertices)
252
+ cached_vertices = []
253
+ curTightness = 0
254
+ if vertices_length > 0:
255
+ # closeShape = mode
256
+ # if the shape is closed, the first element is also the last element
257
+ if mode:
258
+ vertices.append(vertices[0])
259
+ # curveVertex -> bezierVertex
260
+ if vertices_length > 3 :
261
+ b = [None,None,None,None]
262
+ s = 1 - curTightness;
263
+ '''
264
+ Matrix to convert from Catmull-Rom to cubic Bezier
265
+ where t = curTightness
266
+ |0 1 0 0 |
267
+ |(t-1)/6 1 (1-t)/6 0 |
268
+ |0 (1-t)/6 1 (t-1)/6 |
269
+ |0 0 0 0 |
270
+ '''
271
+ i = 1
272
+ while (i+2 < vertices_length):
273
+ cached_vertices = vertices[i]
274
+ b[0] = [cached_vertices[0], cached_vertices[1]]
275
+ b[1] = [cached_vertices[0] + (s * vertices[i+1][0] - s * vertices[i-1][0]) / 6, \
276
+ cached_vertices[1] + (s * vertices[i+1][1] - s * vertices[i-1][1]) / 6]
277
+ b[2] = [vertices[i+1][0] + (s * vertices[i][0] - s * vertices[i+2][0]) / 6, \
278
+ vertices[i+1][1] + (s * vertices[i][1] - s * vertices[i+2][1]) / 6]
279
+ b[3] = [vertices[i+1][0], vertices[i+1][1]]
280
+ i = i + 1
281
+ ctx.curve_to(b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1]) # draw bezier curve
282
+ if mode:
283
+ ctx.line_to(vertices[0][0],vertices[0][1])
284
+
285
+ if not(settings["no_fill"]):
286
+ ctx.set_source_rgba(*bgra(fill_color))
287
+ #ctx.fill_preserve()
288
+ if not(settings["no_stroke"]):
289
+ ctx.set_source_rgba(*bgra(stroke_color))
219
290
  ctx.stroke()
220
- '''
221
291
 
292
+ pass
293
+ # end of draw_spline
294
+
295
+ def draw_bezier(surface, x, y, bezier_vertices, mode):
296
+
297
+ rotate_angle = a_radians(settings["rotate_amnt"])
298
+ scale_xy = settings["scale_amnt"]
299
+ origin_x = settings["real_ox"]
300
+ origin_y = settings["real_oy"]
301
+ stroke_color = settings["stroke_color"]
302
+ thickness = settings["stroke_weight"]
303
+ fill_color = settings["fill_color"]
304
+ ctx = cairo.Context(surface)
305
+ ctx.translate(origin_x, origin_y)
306
+ ctx.rotate(rotate_angle)
307
+ ctx.set_line_width(thickness)
308
+ ctx.move_to(x, y)
309
+ for i in range(len(bezier_vertices)):
310
+ b = bezier_vertices[i]
311
+ ctx.curve_to(*b) # draw bezier curve
312
+
313
+ if mode:
314
+ ctx.line_to(x, y)
315
+ if not(settings["no_fill"]):
316
+ ctx.set_source_rgba(*bgra(fill_color))
317
+ ctx.fill_preserve()
318
+ if not(settings["no_stroke"]):
319
+ ctx.set_source_rgba(*bgra(stroke_color))
320
+ ctx.stroke()
@@ -54,5 +54,6 @@ settings = {
54
54
 
55
55
  vertices = []
56
56
  curvevertices = []
57
+ beziervertices= []
57
58
  shape = None
58
59
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p5-python
3
- Version: 0.5.4
3
+ Version: 0.6.12
4
4
  Summary: A package wrapping pygame functionality in p5.js calling conventions.
5
5
  Home-page: https://github.com/gromko/p5-python
6
6
  Author: Grygoriy Gromko
@@ -6,7 +6,6 @@ p5/__main__.py
6
6
  p5/color.py
7
7
  p5/constants.py
8
8
  p5/corefunctions.py
9
- p5/drawcurve.py
10
9
  p5/mathfunctions.py
11
10
  p5/p5-python.png
12
11
  p5/renderer.py
@@ -0,0 +1,2 @@
1
+ pycairo>=1.20.0
2
+ pygame<3.0.0,>=2.1.2
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "p5"
3
- version = "0.5.4"
3
+ version = "0.6.12"
4
4
  readme = "README.md"
5
5
  license = "MIT"
6
6
  homepage = "https://github.com/gromko/p5-python"
@@ -14,6 +14,7 @@ include = [
14
14
  [tool.poetry.dependencies]
15
15
  python = ">=3.8.0"
16
16
  pygame = "^2.1.2"
17
+ pycairo = "^1.20.0"
17
18
 
18
19
  [tool.poetry.dev-dependencies]
19
20
 
@@ -8,13 +8,11 @@ package_data = \
8
8
  {'': ['*']}
9
9
 
10
10
  install_requires = \
11
- ['multipledispatch>=0.6.0,<0.7.0',
12
- 'numpy>=1.22.2,<2.0.0',
13
- 'pygame>=2.1.2,<3.0.0']
11
+ ['pygame>=2.1.2,<3.0.0','pycairo>=1.20.0']
14
12
 
15
13
  setup_kwargs = {
16
14
  'name': 'p5-python',
17
- 'version': '0.5.4',
15
+ 'version': '0.6.12',
18
16
  'description': 'A package wrapping pygame functionality in p5.js calling conventions.',
19
17
  'long_description': '#p5 is a friendly tool for learning to code and make art. It is a free and open-source Python library built by an inclusive, nurturing community. p5 is a Python library that provides high level drawing functionality to help you quickly create simulations and interactive art using Python.',
20
18
  'author': 'Grygoriy Gromko',
@@ -1,146 +0,0 @@
1
- # Splines/Curves from PAdLib - Ian Mallett - 2013
2
-
3
- from math import *
4
- import pygame
5
- from p5.renderer import *
6
-
7
- # math helper
8
- def rndint(num): return int(num+0.5)
9
- def clamp(num, low,high):
10
- if num < low: return low
11
- if num > high: return high
12
- return num
13
-
14
- def vec_add(v1,v2):
15
- return [v1[i]+v2[i] for i in range(len(v1))]
16
- def vec_sub(v1,v2):
17
- return [v1[i]-v2[i] for i in range(len(v1))]
18
- def vec_dot(v1,v2):
19
- return sum([v1[i]*v2[i] for i in range(len(v1))])
20
- def vec_scale(sc,v):
21
- return [sc*v[i] for i in range(len(v))]
22
- def vec_negate(v):
23
- return [-v[i] for i in range(len(v))]
24
-
25
- def vec_length_sq(vec):
26
- return vec_dot(vec,vec)
27
- def vec_length(vec):
28
- return vec_dot(vec,vec) ** 0.5
29
- def vec_norm(vec):
30
- return vec_scale(1.0/vec_length(vec),vec)
31
-
32
- def vec_reflect(vec, norm):
33
- v_dot_n = vec_dot(vec,norm)
34
- sc = 2 * v_dot_n
35
- return [sc*norm[i]-vec[i] for i in range(len(vec))]
36
-
37
- def point_project_line(p, l1,l2):
38
- #Adapted from http://www.gamedev.net/topic/444154-closest-point-on-a-line/
39
- p_l1 = vec_sub(p,l1)
40
- l2_l1 = vec_sub(l2,l1)
41
-
42
- t = vec_dot(p_l1,l2_l1) / vec_dot(l2_l1,l2_l1)
43
-
44
- return vec_add(l1,vec_scale(t,l2_l1))
45
-
46
- # draw bezier curve
47
- def _draw_bezier(surface, color, controlpointslist, steps, aa, width, blend):
48
- #Algorithm derived from geometric animations on
49
- #http://en.wikipedia.org/wiki/B[e]zier_curve
50
- #The "[e]" is actually an e with an inflection
51
- #over it; removed for this file's portability.
52
-
53
- points = []
54
-
55
- def draw_curve(controlpointslist):
56
- l = len(controlpointslist)
57
-
58
- def lerp(p1,p2):
59
- return vec_add(
60
- vec_scale(1.0-t,p1),
61
- vec_scale( t,p2)
62
- )
63
- if l == 2:
64
- points.append(lerp(*controlpointslist))
65
- else:
66
- controlpointslist2 = []
67
- for i in range(l-1):
68
- controlpointslist2.append(lerp(
69
- controlpointslist[i],
70
- controlpointslist[i+1]
71
- ))
72
- draw_curve(controlpointslist2)
73
-
74
- for i in range(steps):
75
- t = float(i) / float(steps-1)
76
- draw_curve(controlpointslist)
77
-
78
- points = [list(map(rndint,p)) for p in points]
79
- draw_lines(surface,points)
80
-
81
- #draw spline curve
82
- def _draw_spline(surface, color, closed, pointslist, steps, t,b,c, aa, width, blend):
83
- #Kochanek-Bartels spline implementation, written long ago and updated.
84
- t_inc = 1.0/float(steps)
85
-
86
- #This allows us to draw through all visible control points (normal Kochanek-Bartels
87
- #splines do not draw through their last endpoints).
88
- if closed:
89
- pointslist = [pointslist[-2],pointslist[-1]] + pointslist + [pointslist[0],pointslist[1]]
90
- else:
91
- pointslist = [pointslist[0]] + pointslist + [pointslist[-1]]
92
-
93
- cona = (1-t)*(1+b)*(1-c)*0.5
94
- conb = (1-t)*(1-b)*(1+c)*0.5
95
- conc = (1-t)*(1+b)*(1+c)*0.5
96
- cond = (1-t)*(1-b)*(1-c)*0.5
97
-
98
- tans = []
99
- tand = []
100
- for x in range(len(pointslist)-2):
101
- tans.append([])
102
- tand.append([])
103
- i = 1
104
- while i < len(pointslist)-1:
105
- pa = pointslist[i-1]
106
- pb = pointslist[i ]
107
- pc = pointslist[i+1]
108
- x1 = pb[0] - pa[0]
109
- y1 = pb[1] - pa[1]
110
- x2 = pc[0] - pb[0]
111
- y2 = pc[1] - pb[1]
112
- tans[i-1] = (cona*x1+conb*x2, cona*y1+conb*y2)
113
- tand[i-1] = (conc*x1+cond*x2, conc*y1+cond*y2)
114
- i += 1
115
-
116
- for i in range(1,len(pointslist)-2,1):
117
- p0 = pointslist[i ]
118
- p1 = pointslist[i+1]
119
- m0 = tand[i-1]
120
- m1 = tans[i ]
121
-
122
- #draw curve from p0 to p1
123
- points = [(p0[0],p0[1])]
124
- t_iter = t_inc
125
- while t_iter < 1.0:
126
- h00 = ( 2*(t_iter*t_iter*t_iter)) - ( 3*(t_iter*t_iter)) + 1
127
- h10 = ( 1*(t_iter*t_iter*t_iter)) - ( 2*(t_iter*t_iter)) + t_iter
128
- h01 = (-2*(t_iter*t_iter*t_iter)) + ( 3*(t_iter*t_iter))
129
- h11 = ( 1*(t_iter*t_iter*t_iter)) - ( 1*(t_iter*t_iter))
130
- px = h00*p0[0] + h10*m0[0] + h01*p1[0] + h11*m1[0]
131
- py = h00*p0[1] + h10*m0[1] + h01*p1[1] + h11*m1[1]
132
- points.append((px,py))
133
- t_iter += t_inc
134
- points.append((p1[0],p1[1]))
135
-
136
- points = [list(map(rndint,p)) for p in points]
137
- draw_lines(surface,points)
138
-
139
-
140
- def bezier(surface, color, controlpointslist, steps, width=1):
141
- _draw_bezier(surface, color, controlpointslist, steps, False, width, False)
142
-
143
-
144
- def spline(surface, color, closed, pointslist, steps, t=0.0,b=0.0,c=0.0, width=1):
145
- _draw_spline(surface, color, closed, pointslist, steps, t,b,c, False, width, False)
146
-
@@ -1,3 +0,0 @@
1
- multipledispatch<0.7.0,>=0.6.0
2
- numpy<2.0.0,>=1.22.2
3
- pygame<3.0.0,>=2.1.2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes