p5-python 0.5.5__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.
- {p5-python-0.5.5 → p5-python-0.6.29}/PKG-INFO +1 -1
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/__init__.py +10 -11
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/color.py +2 -3
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/corefunctions.py +83 -39
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/renderer.py +165 -46
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/settings.py +8 -6
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/transform.py +9 -7
- {p5-python-0.5.5 → p5-python-0.6.29}/p5_python.egg-info/PKG-INFO +1 -1
- {p5-python-0.5.5 → p5-python-0.6.29}/p5_python.egg-info/SOURCES.txt +0 -1
- {p5-python-0.5.5 → p5-python-0.6.29}/p5_python.egg-info/requires.txt +1 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/pyproject.toml +2 -1
- {p5-python-0.5.5 → p5-python-0.6.29}/setup.py +2 -2
- p5-python-0.5.5/p5/drawcurve.py +0 -146
- {p5-python-0.5.5 → p5-python-0.6.29}/README.md +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/__main__.py +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/constants.py +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/mathfunctions.py +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/p5-python.png +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5/timedata.py +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5_python.egg-info/dependency_links.txt +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/p5_python.egg-info/top_level.txt +0 -0
- {p5-python-0.5.5 → p5-python-0.6.29}/setup.cfg +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
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,
|
|
7
|
-
endShape, cursor, strokeWeight, noStroke,
|
|
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, loadPixels, updatePixels,
|
|
8
8
|
loadImage, image, keyIsDown, frameRate, loop, noLoop,
|
|
9
9
|
background,text,textFont, textSize, textStyle, textAlign)
|
|
10
10
|
|
|
@@ -24,26 +24,25 @@ 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
|
+
|
|
30
|
+
__all__ = ["run", "createCanvas", "translate", "background", "fill", "noFill", "line", "ellipse", "circle", "rect", "triangle", "quad", "arc",
|
|
32
31
|
"push", "pop", "cursor", "TWO_PI", "HALF_PI", "PI", "QUARTER_PI", "TAU", "CURSOR_ARROW", "CURSOR_DIAMOND", "CURSOR_BROKEN_X", "CURSOR_TRI_LEFT",
|
|
33
32
|
"CURSOR_TRI_RIGHT", "BOLD", "ITALIC", "BOLDITALIC", "NORMAL", "strokeWeight", "stroke", "noStroke", "loadImage", "image", "point", "CORNER", "CORNERS", "RADIUS",
|
|
34
33
|
"frameRate", "random", "constrain", "floor", "ceil", "dist", "exp", "lerp", "log", "log10", "log2", "logb", "mag", "textAlign", "CHORD", "PIE", "OPEN", "ARC",
|
|
35
34
|
"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",
|
|
35
|
+
"text","textFont", "textSize", "textStyle","beginShape", "vertex", "endShape", "keyIsDown", "saveCanvas", "scale", "rotate", "translate", "rectMode", "ellipseMode",
|
|
37
36
|
"BACKSPACE","TAB","RETURN","ENTER","PAUSE","ESCAPE","SPACE","DELETE","EXCLAIM","QUOTEDBL","HASH","DOLLAR","AMPERSAND","QUOTE","LEFTPAREN","RIGHTPAREN",
|
|
38
37
|
"ASTERISK","PLUS","COMMA","MINUS","PERIOD","SLASH","COLON","SEMICOLON","LESS","EQUALS","GREATER","QUESTION","AT","LEFTBRACKET","RIGHTBRACKET","CARET",
|
|
39
38
|
"UNDERSCORE","BACKQUOTE","UP","DOWN","RIGHT","LEFT","UP_ARROW","DOWN_ARROW","LEFT_ARROW","RIGHT_ARROW","INSERT","HOME","END","PAGEUP","PAGEDOWN","PGUP",
|
|
40
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",
|
|
41
40
|
"F6","F7","F8","F9","F10","F11","F12","NUMLOCK","CAPSLOCK","SCROLLOCK","RSHIFT","LSHIFT","RCTRL","LCTRL","RALT","LALT","RMETA","LMETA","CONTEXTMENU",
|
|
42
|
-
"PRINT","SYSREQ","BREAK","MENU","CENTER","CLOSE", "pow", "map", "angleMode", "curveVertex", "randomSeed", "resetMatrix",
|
|
43
|
-
"hour", "minute", "second", "day", "month", "year", "milli_sec", "millis", "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"
|
|
44
43
|
]
|
|
45
44
|
|
|
46
|
-
__version__ = "0.5.
|
|
45
|
+
__version__ = "0.5.84"
|
|
47
46
|
|
|
48
47
|
print("Thank you for using p5\n")
|
|
49
48
|
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -335,21 +364,44 @@ def textAlign(align):
|
|
|
335
364
|
raise ValueError("textAlign() was expecting LEFT|CENTER|RIGHT")
|
|
336
365
|
|
|
337
366
|
# ---- IMAGE AND PIXEL ----
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
+
|
|
345
385
|
def saveCanvas(filename):
|
|
346
386
|
pygame.image.save(pg_Screen, filename)
|
|
347
387
|
|
|
348
|
-
def loadPixels(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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()
|
|
353
405
|
|
|
354
406
|
# ---- ----
|
|
355
407
|
def createCanvas(w=100, h=100):
|
|
@@ -374,18 +426,10 @@ def background(*args): # clear and set background color
|
|
|
374
426
|
def strokeWeight(weight):
|
|
375
427
|
settings["stroke_weight"] = weight
|
|
376
428
|
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
429
|
pass
|
|
382
430
|
|
|
383
431
|
def noStroke():
|
|
384
432
|
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
433
|
pass
|
|
390
434
|
|
|
391
435
|
def ellipseMode(mode):
|
|
@@ -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
|
-
|
|
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,16 +37,19 @@ 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)
|
|
42
44
|
ctx.line_to(x2, y2)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
if not(settings["no_stroke"]):
|
|
46
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
47
|
+
ctx.stroke()
|
|
45
48
|
|
|
46
49
|
def draw_rect(surface, x, y, width, height):
|
|
47
50
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
48
51
|
scale_xy = settings["scale_amnt"]
|
|
52
|
+
if scale_xy == 0: scale_xy = 1
|
|
49
53
|
origin_x = settings["real_ox"]
|
|
50
54
|
origin_y = settings["real_oy"]
|
|
51
55
|
stroke_color = settings["stroke_color"]
|
|
@@ -53,17 +57,21 @@ def draw_rect(surface, x, y, width, height):
|
|
|
53
57
|
fill_color = settings["fill_color"]
|
|
54
58
|
ctx = cairo.Context(surface)
|
|
55
59
|
ctx.translate(origin_x, origin_y)
|
|
60
|
+
ctx.scale(scale_xy, scale_xy)
|
|
56
61
|
ctx.rotate(rotate_angle)
|
|
57
62
|
ctx.rectangle(x, y, width, height)
|
|
58
63
|
ctx.set_line_width(thickness)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
if not(settings["no_fill"]):
|
|
65
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
66
|
+
ctx.fill_preserve()
|
|
67
|
+
if not(settings["no_stroke"]):
|
|
68
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
69
|
+
ctx.stroke()
|
|
63
70
|
|
|
64
71
|
def draw_polygon(surface, vertices):
|
|
65
72
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
66
73
|
scale_xy = settings["scale_amnt"]
|
|
74
|
+
if scale_xy == 0: scale_xy = 1
|
|
67
75
|
origin_x = settings["real_ox"]
|
|
68
76
|
origin_y = settings["real_oy"]
|
|
69
77
|
stroke_color = settings["stroke_color"]
|
|
@@ -71,37 +79,44 @@ def draw_polygon(surface, vertices):
|
|
|
71
79
|
fill_color = settings["fill_color"]
|
|
72
80
|
ctx = cairo.Context(surface)
|
|
73
81
|
ctx.translate(origin_x, origin_y)
|
|
82
|
+
ctx.scale(scale_xy, scale_xy)
|
|
74
83
|
ctx.rotate(rotate_angle)
|
|
75
84
|
ctx.move_to(*vertices[0])
|
|
76
85
|
for n in range(1,len(vertices)):
|
|
77
86
|
ctx.line_to(*vertices[n])
|
|
78
87
|
ctx.close_path()
|
|
79
88
|
ctx.set_line_width(thickness)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
if not(settings["no_fill"]):
|
|
90
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
91
|
+
ctx.fill_preserve()
|
|
92
|
+
if not(settings["no_stroke"]):
|
|
93
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
94
|
+
ctx.stroke()
|
|
84
95
|
|
|
85
96
|
def draw_lines(surface, vertices):
|
|
86
97
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
87
98
|
scale_xy = settings["scale_amnt"]
|
|
99
|
+
if scale_xy == 0: scale_xy = 1
|
|
88
100
|
origin_x = settings["real_ox"]
|
|
89
101
|
origin_y = settings["real_oy"]
|
|
90
102
|
stroke_color = settings["stroke_color"]
|
|
91
103
|
thickness = settings["stroke_weight"]
|
|
92
104
|
ctx = cairo.Context(surface)
|
|
93
105
|
ctx.translate(origin_x, origin_y)
|
|
106
|
+
ctx.scale(scale_xy, scale_xy)
|
|
94
107
|
ctx.rotate(rotate_angle)
|
|
95
108
|
ctx.move_to(*vertices[0])
|
|
96
109
|
for n in range(1,len(vertices)):
|
|
97
110
|
ctx.line_to(*vertices[n])
|
|
98
111
|
ctx.set_line_width(thickness)
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
if not(settings["no_stroke"]):
|
|
113
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
114
|
+
ctx.stroke()
|
|
101
115
|
|
|
102
116
|
def draw_circle(surface, x, y, radius):
|
|
103
117
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
104
118
|
scale_xy = settings["scale_amnt"]
|
|
119
|
+
if scale_xy == 0: scale_xy = 1
|
|
105
120
|
origin_x = settings["real_ox"]
|
|
106
121
|
origin_y = settings["real_oy"]
|
|
107
122
|
stroke_color = settings["stroke_color"]
|
|
@@ -110,16 +125,20 @@ def draw_circle(surface, x, y, radius):
|
|
|
110
125
|
ctx = cairo.Context(surface)
|
|
111
126
|
ctx.translate(origin_x, origin_y)
|
|
112
127
|
ctx.rotate(rotate_angle)
|
|
128
|
+
ctx.scale(scale_xy, scale_xy)
|
|
113
129
|
ctx.arc(x, y, radius, 0, 2.0 * math.pi)
|
|
114
130
|
ctx.set_line_width(thickness)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
if not(settings["no_fill"]):
|
|
132
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
133
|
+
ctx.fill_preserve()
|
|
134
|
+
if not(settings["no_stroke"]):
|
|
135
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
136
|
+
ctx.stroke()
|
|
119
137
|
|
|
120
138
|
def draw_ellipse(surface, x, y, width, height):
|
|
121
139
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
122
140
|
scale_xy = settings["scale_amnt"]
|
|
141
|
+
if scale_xy == 0: scale_xy = 1
|
|
123
142
|
origin_x = settings["real_ox"]
|
|
124
143
|
origin_y = settings["real_oy"]
|
|
125
144
|
stroke_color = settings["stroke_color"]
|
|
@@ -127,21 +146,27 @@ def draw_ellipse(surface, x, y, width, height):
|
|
|
127
146
|
fill_color = settings["fill_color"]
|
|
128
147
|
ctx = cairo.Context(surface)
|
|
129
148
|
ctx.translate(origin_x, origin_y)
|
|
149
|
+
ctx.scale(scale_xy, scale_xy)
|
|
130
150
|
ctx.rotate(rotate_angle)
|
|
131
151
|
radius = width/2
|
|
132
152
|
scale_x = 1.0
|
|
133
153
|
scale_y = height / width
|
|
154
|
+
ctx.save()
|
|
134
155
|
ctx.scale(scale_x, scale_y)
|
|
135
156
|
ctx.arc(x, y/scale_y, radius, 0, 2.0 * math.pi)
|
|
136
157
|
ctx.set_line_width(thickness)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
158
|
+
if not(settings["no_fill"]):
|
|
159
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
160
|
+
ctx.fill_preserve()
|
|
161
|
+
if not(settings["no_stroke"]):
|
|
162
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
163
|
+
ctx.stroke()
|
|
164
|
+
ctx.restore()
|
|
141
165
|
|
|
142
166
|
def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
|
|
143
167
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
144
168
|
scale_xy = settings["scale_amnt"]
|
|
169
|
+
if scale_xy == 0: scale_xy = 1
|
|
145
170
|
origin_x = settings["real_ox"]
|
|
146
171
|
origin_y = settings["real_oy"]
|
|
147
172
|
stroke_color = settings["stroke_color"]
|
|
@@ -149,25 +174,31 @@ def draw_arc(surface, x, y, width, height, angle1, angle2, mode):
|
|
|
149
174
|
fill_color = settings["fill_color"]
|
|
150
175
|
ctx = cairo.Context(surface)
|
|
151
176
|
ctx.translate(origin_x, origin_y)
|
|
177
|
+
ctx.scale(scale_xy, scale_xy)
|
|
152
178
|
ctx.rotate(rotate_angle)
|
|
153
179
|
if mode == "pie":
|
|
154
180
|
ctx.move_to(x, y)
|
|
155
181
|
radius = width/2
|
|
156
182
|
scale_x = 1.0
|
|
157
183
|
scale_y = height / width
|
|
184
|
+
ctx.save()
|
|
158
185
|
ctx.scale(scale_x, scale_y)
|
|
159
186
|
ctx.arc(x, y/scale_y, radius, angle1, angle2)
|
|
160
187
|
if (mode == "chord") or (mode == "pie"):
|
|
161
188
|
ctx.close_path()
|
|
162
189
|
if (mode == "chord") or (mode == "pie") or (mode == "open"):
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
190
|
+
if not(settings["no_fill"]):
|
|
191
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
192
|
+
ctx.fill_preserve()
|
|
193
|
+
if not(settings["no_stroke"]):
|
|
194
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
195
|
+
ctx.stroke()
|
|
196
|
+
ctx.restore()
|
|
197
|
+
|
|
168
198
|
def draw_text(surface, txt, x, y, style):
|
|
169
199
|
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
170
200
|
scale_xy = settings["scale_amnt"]
|
|
201
|
+
if scale_xy == 0: scale_xy = 1
|
|
171
202
|
origin_x = settings["real_ox"]
|
|
172
203
|
origin_y = settings["real_oy"]
|
|
173
204
|
stroke_color = settings["text_outline"]
|
|
@@ -177,6 +208,7 @@ def draw_text(surface, txt, x, y, style):
|
|
|
177
208
|
font_size = settings["text_size"]
|
|
178
209
|
ctx = cairo.Context(surface)
|
|
179
210
|
ctx.translate(origin_x, origin_y)
|
|
211
|
+
ctx.scale(scale_xy, scale_xy)
|
|
180
212
|
ctx.rotate(rotate_angle)
|
|
181
213
|
font_options = cairo.FontOptions()
|
|
182
214
|
font_options.set_antialias(cairo.ANTIALIAS_DEFAULT)
|
|
@@ -196,26 +228,113 @@ def draw_text(surface, txt, x, y, style):
|
|
|
196
228
|
if settings["text_align"] == CENTER:
|
|
197
229
|
x = x - width/2
|
|
198
230
|
# Render outline
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
231
|
+
if not(settings["no_stroke"]):
|
|
232
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
233
|
+
i = -thickness
|
|
234
|
+
while i < thickness-0.3 :
|
|
235
|
+
j =-thickness
|
|
236
|
+
while j < thickness-0.3 :
|
|
237
|
+
ctx.move_to(x + i, y + j)
|
|
238
|
+
ctx.show_text(txt)
|
|
239
|
+
j = j + 0.2
|
|
240
|
+
i = i + 0.2
|
|
241
|
+
if not(settings["no_fill"]):
|
|
242
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
243
|
+
ctx.fill_preserve()
|
|
206
244
|
ctx.move_to(x, y)
|
|
207
245
|
ctx.show_text(txt)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
246
|
+
if not(settings["no_stroke"]):
|
|
247
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
248
|
+
ctx.stroke()
|
|
249
|
+
|
|
250
|
+
def draw_spline(surface, curvevertices, mode):
|
|
251
|
+
vertices =[]
|
|
252
|
+
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
253
|
+
scale_xy = settings["scale_amnt"]
|
|
254
|
+
if scale_xy == 0: scale_xy = 1
|
|
255
|
+
origin_x = settings["real_ox"]
|
|
256
|
+
origin_y = settings["real_oy"]
|
|
257
|
+
stroke_color = settings["text_outline"]
|
|
258
|
+
thickness = settings["stroke_weight"]
|
|
259
|
+
fill_color = settings["text_color"]
|
|
260
|
+
font_name = settings["text_font"]
|
|
261
|
+
font_size = settings["text_size"]
|
|
215
262
|
ctx = cairo.Context(surface)
|
|
216
|
-
ctx.
|
|
217
|
-
ctx.
|
|
218
|
-
ctx.
|
|
263
|
+
ctx.translate(origin_x, origin_y)
|
|
264
|
+
ctx.scale(scale_xy, scale_xy)
|
|
265
|
+
ctx.rotate(rotate_angle)
|
|
266
|
+
ctx.set_line_width(thickness)
|
|
267
|
+
vertices = list(curvevertices)
|
|
268
|
+
ctx.move_to(vertices[0][0],vertices[0][1] )
|
|
269
|
+
vertices_length = len(vertices)
|
|
270
|
+
cached_vertices = []
|
|
271
|
+
curTightness = 0
|
|
272
|
+
if vertices_length > 0:
|
|
273
|
+
# closeShape = mode
|
|
274
|
+
# if the shape is closed, the first element is also the last element
|
|
275
|
+
if mode:
|
|
276
|
+
vertices.append(vertices[0])
|
|
277
|
+
# curveVertex -> bezierVertex
|
|
278
|
+
if vertices_length > 3 :
|
|
279
|
+
b = [None,None,None,None]
|
|
280
|
+
s = 1 - curTightness;
|
|
281
|
+
'''
|
|
282
|
+
Matrix to convert from Catmull-Rom to cubic Bezier
|
|
283
|
+
where t = curTightness
|
|
284
|
+
|0 1 0 0 |
|
|
285
|
+
|(t-1)/6 1 (1-t)/6 0 |
|
|
286
|
+
|0 (1-t)/6 1 (t-1)/6 |
|
|
287
|
+
|0 0 0 0 |
|
|
288
|
+
'''
|
|
289
|
+
i = 1
|
|
290
|
+
while (i+2 < vertices_length):
|
|
291
|
+
cached_vertices = vertices[i]
|
|
292
|
+
b[0] = [cached_vertices[0], cached_vertices[1]]
|
|
293
|
+
b[1] = [cached_vertices[0] + (s * vertices[i+1][0] - s * vertices[i-1][0]) / 6, \
|
|
294
|
+
cached_vertices[1] + (s * vertices[i+1][1] - s * vertices[i-1][1]) / 6]
|
|
295
|
+
b[2] = [vertices[i+1][0] + (s * vertices[i][0] - s * vertices[i+2][0]) / 6, \
|
|
296
|
+
vertices[i+1][1] + (s * vertices[i][1] - s * vertices[i+2][1]) / 6]
|
|
297
|
+
b[3] = [vertices[i+1][0], vertices[i+1][1]]
|
|
298
|
+
i = i + 1
|
|
299
|
+
ctx.curve_to(b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1]) # draw bezier curve
|
|
300
|
+
if mode:
|
|
301
|
+
ctx.line_to(vertices[0][0],vertices[0][1])
|
|
302
|
+
|
|
303
|
+
if not(settings["no_fill"]):
|
|
304
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
305
|
+
#ctx.fill_preserve()
|
|
306
|
+
if not(settings["no_stroke"]):
|
|
307
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
219
308
|
ctx.stroke()
|
|
220
|
-
'''
|
|
221
309
|
|
|
310
|
+
pass
|
|
311
|
+
# end of draw_spline
|
|
312
|
+
|
|
313
|
+
def draw_bezier(surface, x, y, bezier_vertices, mode):
|
|
314
|
+
|
|
315
|
+
rotate_angle = a_radians(settings["rotate_amnt"])
|
|
316
|
+
scale_xy = settings["scale_amnt"]
|
|
317
|
+
if scale_xy == 0: scale_xy = 1
|
|
318
|
+
origin_x = settings["real_ox"]
|
|
319
|
+
origin_y = settings["real_oy"]
|
|
320
|
+
stroke_color = settings["stroke_color"]
|
|
321
|
+
thickness = settings["stroke_weight"]
|
|
322
|
+
fill_color = settings["fill_color"]
|
|
323
|
+
ctx = cairo.Context(surface)
|
|
324
|
+
ctx.translate(origin_x, origin_y)
|
|
325
|
+
ctx.scale(scale_xy, scale_xy)
|
|
326
|
+
ctx.rotate(rotate_angle)
|
|
327
|
+
ctx.set_line_width(thickness)
|
|
328
|
+
ctx.move_to(x, y)
|
|
329
|
+
for i in range(len(bezier_vertices)):
|
|
330
|
+
b = bezier_vertices[i]
|
|
331
|
+
ctx.curve_to(*b) # draw bezier curve
|
|
332
|
+
|
|
333
|
+
if mode:
|
|
334
|
+
ctx.line_to(x, y)
|
|
335
|
+
if not(settings["no_fill"]):
|
|
336
|
+
ctx.set_source_rgba(*bgra(fill_color))
|
|
337
|
+
ctx.fill_preserve()
|
|
338
|
+
if not(settings["no_stroke"]):
|
|
339
|
+
ctx.set_source_rgba(*bgra(stroke_color))
|
|
340
|
+
ctx.stroke()
|
|
@@ -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" :
|
|
41
|
+
"scale_amnt" : 0,
|
|
41
42
|
"text_size" : 12,
|
|
42
43
|
"text_font" : "Arial",
|
|
43
44
|
"text_bold" : False,
|
|
@@ -54,5 +55,6 @@ settings = {
|
|
|
54
55
|
|
|
55
56
|
vertices = []
|
|
56
57
|
curvevertices = []
|
|
58
|
+
beziervertices= []
|
|
57
59
|
shape = None
|
|
58
60
|
|
|
@@ -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"] =
|
|
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
|
|
22
|
-
current_angle
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
[tool.poetry]
|
|
2
2
|
name = "p5"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.29"
|
|
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,11 +8,11 @@ package_data = \
|
|
|
8
8
|
{'': ['*']}
|
|
9
9
|
|
|
10
10
|
install_requires = \
|
|
11
|
-
['pygame>=2.1.2,<3.0.0']
|
|
11
|
+
['pygame>=2.1.2,<3.0.0','pycairo>=1.20.0']
|
|
12
12
|
|
|
13
13
|
setup_kwargs = {
|
|
14
14
|
'name': 'p5-python',
|
|
15
|
-
'version': '0.
|
|
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',
|
p5-python-0.5.5/p5/drawcurve.py
DELETED
|
@@ -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
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|