Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
berinhard committed Apr 17, 2021
2 parents ff2355e + 117fce1 commit 0ca1600
Show file tree
Hide file tree
Showing 13 changed files with 2,653 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ tests-sketchbook
venv
docs/examples/dev*
.theia
.envrc
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Development
-----------

0.5.2
-----
- Pyodide mode bugfix for missing `P3D` global definition
- Processing-like PVector class under transcrypt mode
- Processing-like PVector class under pyodide mode

0.5.1
-----
- Minor fix in view sketch HTML
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.1
0.5.2
2 changes: 2 additions & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
- [sketch_009](https://github.com/berinhard/pyp5js/tree/develop/docs/examples/sketch_009): [**Working with images**](sketch_009/index.html)

- [sketch_010](https://github.com/berinhard/pyp5js/tree/develop/docs/examples/sketch_010): [**Complex shapes**](sketch_010/index.html) by [Pedro Queiroga](https://github.com/pedroqueiroga/pqueiroga.github.io/blob/master/curveVertexExample/main.js)

- [sketch_011](https://github.com/berinhard/pyp5js/tree/develop/docs/examples/sketch_011): [**PVector**](sketch_011/index.html) processing-like implementation by [Alexandre Villares](sketch_011/index.html)
1 change: 1 addition & 0 deletions docs/examples/sketch_011/.properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"interpreter": "pyodide"}
240 changes: 240 additions & 0 deletions docs/examples/sketch_011/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
<!DOCTYPE html>

<!-- pyp5js index.html boilerplate -->
<html lang="">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>sketch_011 - pyp5js</title>
<style> body, html, canvas {padding: 0; margin: 0; overflow: hidden;} </style>

<script src="static/p5.js"></script>
<script src="target/target_sketch.js" type="module"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<style>
html {
overflow-y: scroll;
overflow-x: scroll;
}

.demoContainer {
display: flex;
align-items: top;
justify-content: center;
}

pre {
padding-left: 2em;
}
</style>
</head>

<body>
<p style="background-color: #f6f8fa">
Python code <a href="https://github.com/berinhard/pyp5js/blob/develop/docs/examples/sketch_011" target="_blank">here</a>.
</p>


<div class="demoContainer">
<div id="sketch-holder">
<!-- You sketch will go here! -->
</div>

<pre>
<code>
# Made for https://berinhard.github.io/pyp5js/pyodide/
# Tests to ensure a Processing-like PVector API under Pyodide

def setup():
size(500, 500)
test()

def test():
"""
Mostly from JDF py.processing tests
"""
a = PVector()
assert a.x == 0
assert a.y == 0
assert a.z == 0

a = PVector(5, 7, 11)
b = PVector(13, 17, 23)
assert a - b == PVector(-8.0, -10.0, -12.0)
assert b - a == PVector(8, 10, 12)
c = PVector(18, 24, 34)
assert b + a == c
assert a + b == c
assert PVector.add(a, b) == c
assert PVector.add(a, b) == c
a.add(b)
assert a == c
a.add(b)
assert a == PVector(31.0, 41.0, 57.0)

c = PVector(310.0, 410.0, 570.0)
assert a * 10 == c
assert a * 10 == c
assert PVector.mult(a, 10) == c

assert PVector.mult(a, 10) == c
a.mult(10)
assert a == c

assert int(1000 * PVector.dist(a, b)) == 736116
assert PVector.cross(a, b) == PVector(-260.0, 280.0, -60.0)
assert a.cross(b) == PVector(-260.0, 280.0, -60.0)
assert PVector.dot(a, b) == 0

d = a.get()
d += b
assert d == a + b
d = a.get()
d -= c
assert d == a - c
d = a.get()
d *= 5.0
assert d == a * 5.0
d = a.get()

d /= 5.0
assert d == a / 5.0

assert b * 5 == b * 5.0
assert b / 5 == b / 5.0
d = b.get()
d *= 391
assert d == b * 391.0
d = b.get()
d /= 10203
assert d == b / 10203.0

d = a.get()
d += a + a
assert d == a + a + a

assert a * 57.0 == 57.0 * a

assert (a / 5.0) == (1.0 / 5.0) * a

m, n = b, c
a += b * 5 - c / 2 + PVector(0, 1, 2)
assert (m, n) == (b, c)

import copy
x = [a, b]
y = copy.deepcopy(x)

assert x == y
x[0].sub(PVector(100, 100, 100))
assert x != y

a = PVector(1, 1)
b = PVector(-2, -2)
assert a < b
assert a <= b
assert b > a
assert b >= a
a = PVector(1, 2, 3)
b = PVector(3, 2, 1)
assert a != b
assert a >= b
assert b >= a
assert a.magSq() == b.magSq()

v1 = PVector(10, 20)
v2 = PVector(60, 80)
a = PVector.angleBetween(v1, v2)
# Java implementation gives slightly different value:
# assert a == 0.17985349893569946 # more or less
assert int(a * 1e8) == 17985349 # more or less

# Regression test for https://github.com/jdf/Processing.py-Bugs/issues/67
assert isinstance(PVector(1, 2), PVector)

# Regression test for https://github.com/jdf/Processing.py-Bugs/issues/101
v = PVector(10, 20, 0)
d = v.dot(60, 80, 0)
assert d == 2200.0
v2 = PVector(60, 80, 0)
d = v.dot(v2)
assert d == 2200.0

# PVector.add w/multiple arguments
v = PVector(40, 20, 0)
v.add(25, 50, 0)
assert (v.x, v.y, v.z) == (65, 70, 0)

# PVector.sub w/multiple arguments
v = PVector(40, 20, 0)
v.sub(25, 50, 0)
assert (v.x, v.y, v.z) == (15, -30, 0)

# Regression test for https://github.com/jdf/Processing.py-Bugs/issues/102
start = PVector(0.0, 0.0)
end = PVector(100.0, 100.0)
middle = PVector.lerp(start, end, 0.5)
assert middle == PVector(50.0, 50.0)
assert start == PVector(0, 0)
start.lerp(end, .75)
assert start == PVector(75, 75)
assert end == PVector(100.0, 100.0)
end.lerp(200, 200, 0, .5)
assert end == PVector(150.0, 150.0)

# test that instance op returns self
a = PVector(3, 5, 7)
b = a * 10
assert a.mult(10) == b

# test that a vector can do arithmetic with a tuple
assert PVector(1, 2, 3) == (1, 2, 3)
assert (PVector(1, 2, 3) + (3, 3, 3)) == (4, 5, 6)
assert (PVector(5, 5, 5) - (1, 2, 3)) == (4, 3, 2)

# Regression test for https://github.com/jdf/processing.py/issues/317
r = PVector.random2D() * 10
assert -10 <= r.x <= 10
assert -10 <= r.y <= 10
assert r.z == 0

PVector.random3D(r)
r += (1, 1, 1)
assert 0 <= r.x <= 2
assert 0 <= r.y <= 2
assert 0 <= r.z <= 2

# Regression test for https://github.com/jdf/processing.py/issues/334
r = PVector.fromAngle(0) * 10
assert r.x == 10
assert r.y == 0
assert r.z == 0

# Other p5js methods
text(r.toString(), 120, 120)
r.setMag(100)
assert r.mag() == 100
r.normalize()
assert r.mag() == 1
r.limit(10)
assert r.mag() == 1
r.limit(0.1)
assert r.mag() == 0.1

assert r.heading() == 0
r.rotate(PI)
assert r.heading() == PI

text('OK - ALL PASSED!', 100, 200)
</code>
</pre>

</div>

</body>
</html>
Loading

0 comments on commit 0ca1600

Please sign in to comment.