p5-python 0.6.12__tar.gz → 0.6.29__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.6.12
3
+ Version: 0.6.29
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
@@ -4,7 +4,7 @@ os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
4
4
  from p5.corefunctions import (run, createCanvas, saveCanvas, angleMode, rectMode, ellipseMode,
5
5
  line, ellipse, circle, rect, quad, arc, triangle, bezier,
6
6
  point, beginShape, vertex, curveVertex, curve, bezierVertex,
7
- endShape, cursor, strokeWeight, noStroke,
7
+ endShape, cursor, strokeWeight, noStroke, loadPixels, updatePixels,
8
8
  loadImage, image, keyIsDown, frameRate, loop, noLoop,
9
9
  background,text,textFont, textSize, textStyle, textAlign)
10
10
 
@@ -26,7 +26,8 @@ from p5.timedata import (hour, minute, second, day, month, year, milli_sec, mil
26
26
 
27
27
  from p5.transform import (scale, rotate, translate, push, pop, resetMatrix)
28
28
 
29
- __all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "line", "ellipse", "circle", "rect", "triangle", "quad", "arc",
29
+
30
+ __all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "line", "ellipse", "circle", "rect", "triangle", "quad", "arc",
30
31
  "push", "pop", "cursor", "TWO_PI", "HALF_PI", "PI", "QUARTER_PI", "TAU", "CURSOR_ARROW", "CURSOR_DIAMOND", "CURSOR_BROKEN_X", "CURSOR_TRI_LEFT",
31
32
  "CURSOR_TRI_RIGHT", "BOLD", "ITALIC", "BOLDITALIC", "NORMAL", "strokeWeight", "stroke", "noStroke", "loadImage", "image", "point", "CORNER", "CORNERS", "RADIUS",
32
33
  "frameRate", "random", "constrain", "floor", "ceil", "dist", "exp", "lerp", "log", "log10", "log2", "logb", "mag", "textAlign", "CHORD", "PIE", "OPEN", "ARC",
@@ -37,11 +38,11 @@ __all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "
37
38
  "UNDERSCORE","BACKQUOTE","UP","DOWN","RIGHT","LEFT","UP_ARROW","DOWN_ARROW","LEFT_ARROW","RIGHT_ARROW","INSERT","HOME","END","PAGEUP","PAGEDOWN","PGUP",
38
39
  "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
40
  "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"
41
+ "PRINT","SYSREQ","BREAK","MENU","CENTER","CLOSE", "RADIANS","DEGREES", "pow", "map", "angleMode", "curveVertex", "randomSeed", "resetMatrix",
42
+ "hour", "minute", "second", "day", "month", "year", "milli_sec", "millis", "curve", "bezierVertex", "bezier", "loadPixels", "updatePixels"
42
43
  ]
43
44
 
44
- __version__ = "0.6.12"
45
+ __version__ = "0.5.84"
45
46
 
46
47
  print("Thank you for using p5\n")
47
48
 
@@ -364,21 +364,44 @@ def textAlign(align):
364
364
  raise ValueError("textAlign() was expecting LEFT|CENTER|RIGHT")
365
365
 
366
366
  # ---- IMAGE AND PIXEL ----
367
-
368
- def loadImage(path):
369
- return pygame.image.load(path)
370
-
371
- def image(img, x, y):
372
- pg_Screen.blit(img, (x, y))
373
-
367
+ def bgra_surf_to_rgba_string(surface):
368
+ # convert raw data from BGRA to RGBA
369
+ img = surface.get_data()
370
+ rgba= img
371
+ for i in range(0,len(rgba),4):
372
+ rgba[i],rgba[i+2]=rgba[i+2],rgba[i]
373
+ return rgba
374
+
375
+ def loadImage(path): # load image to IMAGE_SURFACE
376
+ img_surface = cairo.ImageSurface.create_from_png(path)
377
+ rgba= bgra_surf_to_rgba_string(img_surface)
378
+ return img_surface
379
+
380
+ def image(image, x, y):
381
+ ctx = cairo.Context(CAIRO_SURFACE)
382
+ ctx.set_source_surface(image, x, y)
383
+ ctx.paint()
384
+
374
385
  def saveCanvas(filename):
375
386
  pygame.image.save(pg_Screen, filename)
376
387
 
377
- def loadPixels(image):
378
- return pygame.PixelArray(image)
379
-
380
- def updatePixels(pixels):
381
- pixels.close()
388
+ def loadPixels():
389
+ surface = CAIRO_SURFACE
390
+ img = surface.get_data()
391
+ rgba= img
392
+ for i in range(0,len(rgba),4):
393
+ rgba[i],rgba[i+2]=rgba[i+2],rgba[i]
394
+ builtins.pixels = list(rgba)
395
+
396
+ def updatePixels():
397
+ rgba= builtins.pixels
398
+ for i in range(0,len(rgba),4):
399
+ rgba[i],rgba[i+2]=rgba[i+2],rgba[i]
400
+ img = bytearray(rgba)
401
+ img_surface = cairo.ImageSurface.create_for_data(img, cairo.FORMAT_ARGB32, builtins.width, builtins.height)
402
+ ctx = cairo.Context(CAIRO_SURFACE)
403
+ ctx.set_source_surface(img_surface, 0, 0)
404
+ ctx.paint()
382
405
 
383
406
  # ---- ----
384
407
  def createCanvas(w=100, h=100):
@@ -18,9 +18,9 @@ def a_radians(a):
18
18
  if builtins.ANGLEMODE == DEGREES:
19
19
  return a * math.pi/180
20
20
  else:
21
- return a
22
- def clear_background(surface, width, height, color):
23
-
21
+ return a
22
+
23
+ def clear_background(surface, width, height, color):
24
24
  ctx = cairo.Context(surface)
25
25
  ctx.set_source_rgba(*bgra(color))
26
26
  ctx.rectangle(0, 0, width, height)
@@ -29,6 +29,7 @@ def clear_background(surface, width, height, color):
29
29
  def draw_line(surface, x1, y1, x2, y2):
30
30
  rotate_angle = a_radians(settings["rotate_amnt"])
31
31
  scale_xy = settings["scale_amnt"]
32
+ if scale_xy == 0: scale_xy = 1
32
33
  origin_x = settings["real_ox"]
33
34
  origin_y = settings["real_oy"]
34
35
  stroke_color = settings["stroke_color"]
@@ -36,6 +37,7 @@ def draw_line(surface, x1, y1, x2, y2):
36
37
  fill_color = settings["fill_color"]
37
38
  ctx = cairo.Context(surface)
38
39
  ctx.translate(origin_x, origin_y)
40
+ ctx.scale(scale_xy, scale_xy)
39
41
  ctx.rotate(rotate_angle)
40
42
  ctx.set_line_width(thickness)
41
43
  ctx.move_to(x1, y1)
@@ -47,6 +49,7 @@ def draw_line(surface, x1, y1, x2, y2):
47
49
  def draw_rect(surface, x, y, width, height):
48
50
  rotate_angle = a_radians(settings["rotate_amnt"])
49
51
  scale_xy = settings["scale_amnt"]
52
+ if scale_xy == 0: scale_xy = 1
50
53
  origin_x = settings["real_ox"]
51
54
  origin_y = settings["real_oy"]
52
55
  stroke_color = settings["stroke_color"]
@@ -54,6 +57,7 @@ def draw_rect(surface, x, y, width, height):
54
57
  fill_color = settings["fill_color"]
55
58
  ctx = cairo.Context(surface)
56
59
  ctx.translate(origin_x, origin_y)
60
+ ctx.scale(scale_xy, scale_xy)
57
61
  ctx.rotate(rotate_angle)
58
62
  ctx.rectangle(x, y, width, height)
59
63
  ctx.set_line_width(thickness)
@@ -67,6 +71,7 @@ def draw_rect(surface, x, y, width, height):
67
71
  def draw_polygon(surface, vertices):
68
72
  rotate_angle = a_radians(settings["rotate_amnt"])
69
73
  scale_xy = settings["scale_amnt"]
74
+ if scale_xy == 0: scale_xy = 1
70
75
  origin_x = settings["real_ox"]
71
76
  origin_y = settings["real_oy"]
72
77
  stroke_color = settings["stroke_color"]
@@ -74,6 +79,7 @@ def draw_polygon(surface, vertices):
74
79
  fill_color = settings["fill_color"]
75
80
  ctx = cairo.Context(surface)
76
81
  ctx.translate(origin_x, origin_y)
82
+ ctx.scale(scale_xy, scale_xy)
77
83
  ctx.rotate(rotate_angle)
78
84
  ctx.move_to(*vertices[0])
79
85
  for n in range(1,len(vertices)):
@@ -90,12 +96,14 @@ def draw_polygon(surface, vertices):
90
96
  def draw_lines(surface, vertices):
91
97
  rotate_angle = a_radians(settings["rotate_amnt"])
92
98
  scale_xy = settings["scale_amnt"]
99
+ if scale_xy == 0: scale_xy = 1
93
100
  origin_x = settings["real_ox"]
94
101
  origin_y = settings["real_oy"]
95
102
  stroke_color = settings["stroke_color"]
96
103
  thickness = settings["stroke_weight"]
97
104
  ctx = cairo.Context(surface)
98
105
  ctx.translate(origin_x, origin_y)
106
+ ctx.scale(scale_xy, scale_xy)
99
107
  ctx.rotate(rotate_angle)
100
108
  ctx.move_to(*vertices[0])
101
109
  for n in range(1,len(vertices)):
@@ -108,6 +116,7 @@ def draw_lines(surface, vertices):
108
116
  def draw_circle(surface, x, y, radius):
109
117
  rotate_angle = a_radians(settings["rotate_amnt"])
110
118
  scale_xy = settings["scale_amnt"]
119
+ if scale_xy == 0: scale_xy = 1
111
120
  origin_x = settings["real_ox"]
112
121
  origin_y = settings["real_oy"]
113
122
  stroke_color = settings["stroke_color"]
@@ -116,6 +125,7 @@ def draw_circle(surface, x, y, radius):
116
125
  ctx = cairo.Context(surface)
117
126
  ctx.translate(origin_x, origin_y)
118
127
  ctx.rotate(rotate_angle)
128
+ ctx.scale(scale_xy, scale_xy)
119
129
  ctx.arc(x, y, radius, 0, 2.0 * math.pi)
120
130
  ctx.set_line_width(thickness)
121
131
  if not(settings["no_fill"]):
@@ -128,6 +138,7 @@ def draw_circle(surface, x, y, radius):
128
138
  def draw_ellipse(surface, x, y, width, height):
129
139
  rotate_angle = a_radians(settings["rotate_amnt"])
130
140
  scale_xy = settings["scale_amnt"]
141
+ if scale_xy == 0: scale_xy = 1
131
142
  origin_x = settings["real_ox"]
132
143
  origin_y = settings["real_oy"]
133
144
  stroke_color = settings["stroke_color"]
@@ -135,6 +146,7 @@ def draw_ellipse(surface, x, y, width, height):
135
146
  fill_color = settings["fill_color"]
136
147
  ctx = cairo.Context(surface)
137
148
  ctx.translate(origin_x, origin_y)
149
+ ctx.scale(scale_xy, scale_xy)
138
150
  ctx.rotate(rotate_angle)
139
151
  radius = width/2
140
152
  scale_x = 1.0
@@ -154,6 +166,7 @@ def draw_ellipse(surface, x, y, width, height):
154
166
  def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
155
167
  rotate_angle = a_radians(settings["rotate_amnt"])
156
168
  scale_xy = settings["scale_amnt"]
169
+ if scale_xy == 0: scale_xy = 1
157
170
  origin_x = settings["real_ox"]
158
171
  origin_y = settings["real_oy"]
159
172
  stroke_color = settings["stroke_color"]
@@ -161,6 +174,7 @@ def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
161
174
  fill_color = settings["fill_color"]
162
175
  ctx = cairo.Context(surface)
163
176
  ctx.translate(origin_x, origin_y)
177
+ ctx.scale(scale_xy, scale_xy)
164
178
  ctx.rotate(rotate_angle)
165
179
  if mode == "pie":
166
180
  ctx.move_to(x, y)
@@ -184,6 +198,7 @@ def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
184
198
  def draw_text(surface, txt, x, y, style):
185
199
  rotate_angle = a_radians(settings["rotate_amnt"])
186
200
  scale_xy = settings["scale_amnt"]
201
+ if scale_xy == 0: scale_xy = 1
187
202
  origin_x = settings["real_ox"]
188
203
  origin_y = settings["real_oy"]
189
204
  stroke_color = settings["text_outline"]
@@ -193,6 +208,7 @@ def draw_text(surface, txt, x, y, style):
193
208
  font_size = settings["text_size"]
194
209
  ctx = cairo.Context(surface)
195
210
  ctx.translate(origin_x, origin_y)
211
+ ctx.scale(scale_xy, scale_xy)
196
212
  ctx.rotate(rotate_angle)
197
213
  font_options = cairo.FontOptions()
198
214
  font_options.set_antialias(cairo.ANTIALIAS_DEFAULT)
@@ -235,6 +251,7 @@ def draw_spline(surface, curvevertices, mode):
235
251
  vertices =[]
236
252
  rotate_angle = a_radians(settings["rotate_amnt"])
237
253
  scale_xy = settings["scale_amnt"]
254
+ if scale_xy == 0: scale_xy = 1
238
255
  origin_x = settings["real_ox"]
239
256
  origin_y = settings["real_oy"]
240
257
  stroke_color = settings["text_outline"]
@@ -244,6 +261,7 @@ def draw_spline(surface, curvevertices, mode):
244
261
  font_size = settings["text_size"]
245
262
  ctx = cairo.Context(surface)
246
263
  ctx.translate(origin_x, origin_y)
264
+ ctx.scale(scale_xy, scale_xy)
247
265
  ctx.rotate(rotate_angle)
248
266
  ctx.set_line_width(thickness)
249
267
  vertices = list(curvevertices)
@@ -296,6 +314,7 @@ def draw_bezier(surface, x, y, bezier_vertices, mode):
296
314
 
297
315
  rotate_angle = a_radians(settings["rotate_amnt"])
298
316
  scale_xy = settings["scale_amnt"]
317
+ if scale_xy == 0: scale_xy = 1
299
318
  origin_x = settings["real_ox"]
300
319
  origin_y = settings["real_oy"]
301
320
  stroke_color = settings["stroke_color"]
@@ -303,6 +322,7 @@ def draw_bezier(surface, x, y, bezier_vertices, mode):
303
322
  fill_color = settings["fill_color"]
304
323
  ctx = cairo.Context(surface)
305
324
  ctx.translate(origin_x, origin_y)
325
+ ctx.scale(scale_xy, scale_xy)
306
326
  ctx.rotate(rotate_angle)
307
327
  ctx.set_line_width(thickness)
308
328
  ctx.move_to(x, y)
@@ -1,9 +1,6 @@
1
1
  import builtins
2
2
  from p5.constants import *
3
3
 
4
- pg_Screen = None
5
- clock = None
6
-
7
4
  builtins.mouseX = 0
8
5
  builtins.mouseY = 0
9
6
  builtins.pmouseX = None
@@ -26,10 +23,14 @@ builtins.MILLIS = 0
26
23
  builtins.frameCount = 0
27
24
  builtins.ellipse_mode = CENTER
28
25
  builtins.rect_mode = CORNER
26
+ builtins.pixels = [] # store for pixels
27
+
28
+ pg_Screen = None
29
+ clock = None
30
+ # ----
29
31
 
32
+ stack = [] # store for settings
30
33
 
31
- # variables
32
- stack = [] # store for settings
33
34
  settings = {
34
35
  "fill_color" : [255,255,255,255],
35
36
  "no_fill" : False,
@@ -37,7 +38,7 @@ settings = {
37
38
  "stroke_weight" : 1,
38
39
  "stroke_color" : [0,0,0,255],
39
40
  "rotate_amnt" : 0,
40
- "scale_amnt" : 1,
41
+ "scale_amnt" : 0,
41
42
  "text_size" : 12,
42
43
  "text_font" : "Arial",
43
44
  "text_bold" : False,
@@ -1,11 +1,12 @@
1
1
  # TRANSFORM
2
2
  from p5.settings import *
3
3
  import math
4
+ import builtins
4
5
 
5
6
  def transform_canvas_reset(): # Transformations are reset at the beginning of the draw loop.
6
7
  global settings
7
8
  settings["rotate_amnt"] = 0
8
- settings["scale_amnt"] = 1
9
+ settings["scale_amnt"] = 0
9
10
  settings["origin_x"] = 0
10
11
  settings["origin_y"] = 0
11
12
  settings["real_ox"] = 0
@@ -18,15 +19,16 @@ def resetMatrix():
18
19
  def rotate(angle):
19
20
  current_angle = settings["rotate_amnt"]
20
21
  current_angle += angle
21
- if current_angle < 0:
22
- current_angle = 360 + current_angle
23
- if current_angle > 359:
24
- current_angle = current_angle % 360
25
- settings["rotate_amnt"] = current_angle
22
+ if builtins.ANGLEMODE == DEGREES:
23
+ if current_angle < 0:
24
+ current_angle = 360 + current_angle
25
+ if current_angle > 359:
26
+ current_angle = current_angle % 360
27
+ settings["rotate_amnt"] = current_angle
26
28
  pass
27
29
 
28
30
  def scale(amnt):
29
- settings["scale_amnt"] = amnt
31
+ settings["scale_amnt"] = settings["scale_amnt"] + amnt
30
32
  pass
31
33
 
32
34
  def real_oxy(xx,yy): # calulate real x,y coordinate
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p5-python
3
- Version: 0.6.12
3
+ Version: 0.6.29
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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "p5"
3
- version = "0.6.12"
3
+ version = "0.6.29"
4
4
  readme = "README.md"
5
5
  license = "MIT"
6
6
  homepage = "https://github.com/gromko/p5-python"
@@ -12,7 +12,7 @@ install_requires = \
12
12
 
13
13
  setup_kwargs = {
14
14
  'name': 'p5-python',
15
- 'version': '0.6.12',
15
+ 'version': '0.6.29',
16
16
  'description': 'A package wrapping pygame functionality in p5.js calling conventions.',
17
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.',
18
18
  'author': 'Grygoriy Gromko',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes