Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/processing_pyo3/examples/Demos/Graphics/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def rebirth(self, x, y):
a = random(TWO_PI)
speed = random(0.5, 4)
self.velocity = Vec2(cos(a), sin(a))
self.velocity.mult(speed)
self.velocity *= speed
self.lifespan = 255
self.x = x
self.y = y
Expand All @@ -58,7 +58,7 @@ def is_dead(self):

def update(self):
self.lifespan = self.lifespan - 1
self.velocity.add(self.gravity)
self.velocity += self.gravity

self.x += self.velocity.x
self.y += self.velocity.y
Expand Down
12 changes: 6 additions & 6 deletions crates/processing_pyo3/examples/Demos/Graphics/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def build():
for j in range(RESJ):
muj = j / (RESJ - 1)
out = Vec3()
uitang.set(0, 0, 0)
ujtang.set(0, 0, 0)
uitang = Vec3(0, 0, 0)
ujtang = Vec3(0, 0, 0)
for ki in range(ni + 1):
bi = bezier_blend(ki, mui, ni)
dbi = d_bezier_blend(ki, mui, ni)
Expand All @@ -85,12 +85,12 @@ def build():
ujtang.x += inp[ki][kj].x * bi * dbj
ujtang.y += inp[ki][kj].y * bi * dbj
ujtang.z += inp[ki][kj].z * bi * dbj
out.add(Vec3(-ni / 2, -nj / 2, 0))
out.mult(100)
out += Vec3(-ni / 2, -nj / 2, 0)
out *= 100
out_row.append(out)

uitang.normalize()
ujtang.normalize()
uitang = uitang.normalized()
ujtang = ujtang.normalized()
norm_row.append(uitang.cross(ujtang))
outp.append(out_row)
normp.append(norm_row)
Expand Down
42 changes: 25 additions & 17 deletions crates/processing_pyo3/examples/Demos/Graphics/ribbons.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, center_x, center_y, radius):

def mouse_pressed(self):
self.v_down = self.mouse_to_sphere(mouse_x, mouse_y)
self.q_down.set(self.q_now)
self.q_down = self.q_now.copy()
self.q_drag.reset()

def mouse_dragged(self):
Expand All @@ -110,15 +110,15 @@ def mouse_to_sphere(self, x, y):

m = v.x * v.x + v.y * v.y
if m > 1.0:
v.normalize()
v = v.normalized()
else:
v.z = sqrt(1.0 - m)

return v if self.axis == -1 else self.constrain_vector(v, self.axis_set[self.axis])

def constrain_vector(self, vector, axis):
res = vector - axis * axis.dot(vector)
res.normalize()
res = res.normalized()
return res

def apply_quat_2_matrix(self, q):
Expand Down Expand Up @@ -289,7 +289,9 @@ def set_c_point(self, n, p):

# Gets n-th control point.
def get_c_point(self, n, p):
p.set(self.bspline_c_points[n][0], self.bspline_c_points[n][1], self.bspline_c_points[n][2])
p.x = self.bspline_c_points[n][0]
p.y = self.bspline_c_points[n][1]
p.z = self.bspline_c_points[n][2]

# Replaces the current B-spline control points(0, 1, 2) with(1, 2, 3). This
# is used when a new spline is to be joined to the recently drawn.
Expand All @@ -315,11 +317,15 @@ def update_matrix3(self):

def feval(self, t, p):
self.eval_point(t)
p.set(self.pt[0], self.pt[1], self.pt[2])
p.x = self.pt[0]
p.y = self.pt[1]
p.z = self.pt[2]

def deval(self, t, d):
self.eval_tangent(t)
d.set(self.tg[0], self.tg[1], self.tg[2])
d.x = self.tg[0]
d.y = self.tg[1]
d.z = self.tg[2]

def feval_x(self, t):
self.eval_point(t)
Expand Down Expand Up @@ -652,17 +658,17 @@ def generate_flat_ribbon(vertices, normals):

# The normal is calculated.
normal1 = transversal.cross(tangent)
normal1.normalize()
normal1 = normal1.normalized()

for ui in range(1, 11):
if ui % uspacing == 0:
u = 0.1 * ui

# The geometry of the previous iteration is saved.
sid1_point0.set(sid1_point1)
cent_point0.set(cent_point1)
sid2_point0.set(sid2_point1)
normal0.set(normal1)
sid1_point0 = sid1_point1.copy()
cent_point0 = cent_point1.copy()
sid2_point0 = sid2_point1.copy()
normal0 = normal1.copy()

# The new geometry is generated.
spline_side1.feval(u, sid1_point1)
Expand All @@ -675,7 +681,7 @@ def generate_flat_ribbon(vertices, normals):
transversal = sid1_point1 - sid2_point1
# The normal is calculated.
normal1 = transversal.cross(tangent)
normal1.normalize()
normal1 = normal1.normalized()

# The (Sid1Point0, Sid1Point1, CentPoint1) triangle is added.
vertices.append(cent_point1.copy())
Expand Down Expand Up @@ -733,6 +739,7 @@ def shift_control_points():

# Adds a new control point to the arrays CPCenter, CPRight and CPLeft
def add_control_points(ca0, ox0, ca1, ss, handness):
global flip_test_v
a = ca1 - ca0
b = ox0 - ca0

Expand All @@ -744,13 +751,13 @@ def add_control_points(ca0, ox0, ca1, ss, handness):
d = c.cross(a)

# Normalizing vectors.
c.normalize()
d.normalize()
c = c.normalized()
d = d.normalized()

# Flipping test (to avoid self crossing in the strands).
if ss != HELIX and 90.0 < degrees(Vec3.angle_between(flip_test_v, d)):
# Flip detected. The plane vector is inverted.
d.mult(-1.0)
d *= -1.0

# The central control point is constructed.
cpt0 = linear_comb(0.5, ca0, 0.5, ca1)
Expand All @@ -772,17 +779,18 @@ def add_control_points(ca0, ox0, ca1, ss, handness):
spline_side2.set_c_point(3, cpt2)

# Saving the plane vector (for the flipping test in the next call).
flip_test_v.set(d)
flip_test_v = d.copy()


def construct_control_points(residues, res, ss, handness):
global flip_test_v
p1 = Vec3()
p2 = Vec3()
p3 = Vec3()

if res == 0:
# The control points 2 and 3 are created.
flip_test_v.set(0, 0, 0)
flip_test_v = Vec3(0, 0, 0)

res0 = residues[res]
res1 = residues[res + 1]
Expand Down
10 changes: 5 additions & 5 deletions crates/processing_pyo3/examples/Demos/Graphics/trefoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ def eval_normal(u, v):
p = eval_point(u, v)
tang_u = eval_point(u + 0.01, v)
tang_v = eval_point(u, v + 0.01)
tang_u.sub(p)
tang_v.sub(p)
tang_u -= p
tang_v -= p

norm_uv = tang_v.cross(tang_u)
norm_uv.normalize()
norm_uv = norm_uv.normalized()
return norm_uv


Expand All @@ -137,9 +137,9 @@ def eval_point(u, v):
dv.z = 1.5 * c * cos(1.5 * t)

q = dv
q.normalize()
q = q.normalized()
qvn = Vec3(q.y, -q.x, 0)
qvn.normalize()
qvn = qvn.normalized()
ww = q.cross(qvn)

pt = Vec3()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def p_mouse_y(self):

def mouse_pressed(self):
self.v_down = self.mouse_to_sphere(self.p_mouse_x(), self.p_mouse_y())
self.q_down.set(self.q_now)
self.q_down = self.q_now.copy()
self.q_drag.reset()

def mouse_dragged(self):
Expand Down Expand Up @@ -148,15 +148,15 @@ def mouse_to_sphere(self, x, y):

m = v.x * v.x + v.y * v.y
if m > 1.0:
v.normalize()
v = v.normalized()
else:
v.z = sqrt(1.0 - m)

return v if self.axis == -1 else self.constrain_vector(v, self.axis_set[self.axis])

def constrain_vector(self, vector, axis):
res = vector - axis * axis.dot(vector)
res.normalize()
res = res.normalized()
return res

def apply_quat_2_matrix(self, q):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def draw(self):
previous_pos = self.shape_path[index - 1]
a = atan2(previous_pos.y - pos.y, previous_pos.x - pos.x)
offset_pos = Vec2.from_angle(a)
offset_pos.add(0, i)
offset_pos = offset_pos.rotate(a)
offset_pos.add(pos)
offset_pos += Vec2(0, i)
offset_pos = offset_pos.rotated(a)
offset_pos += pos
curve_vertex(offset_pos.x, offset_pos.y)
end_shape()
i += density
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def draw():
if i % 2 == 1:
a = -a
next_pos = Vec2.from_angle(radians(a))
next_pos.set_mag((joints - i) / joints * line_length)
next_pos.add(pos)
next_pos = next_pos.with_mag((joints - i) / joints * line_length)
next_pos += pos

if show_pendulum:
no_stroke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def draw(self):

next_pos = Vec2.from_angle(radians(a))

next_pos.set_mag((self.line_length / self.joints) * (self.joints - i))
next_pos.add(pos)
next_pos = next_pos.with_mag((self.line_length / self.joints) * (self.joints - i))
next_pos += pos

if show_pendulum:
no_stroke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def draw(self):
self.iterator /
pow(-2, self.joints - i) * self.speed
)
offset_pos_b.set_mag((self.line_length / self.joints) * (self.joints - i))
offset_pos_b.add(offset_pos_a)
offset_pos_b = offset_pos_b.with_mag((self.line_length / self.joints) * (self.joints - i))
offset_pos_b += offset_pos_a

if show_pendulum:
fill(0.0, 0.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, size, hierarchy):
self.pendulum_arm = Pendulum(self.size / 1.5, self.hierarchy)

def update(self, heading):
self.end.set(self.origin.x + self.size * sin(self.angle), self.origin.y + self.size * cos(self.angle))
self.end = Vec2(self.origin.x + self.size * sin(self.angle), self.origin.y + self.size * cos(self.angle))

self.angular_acceleration = (-self.gravity / self.size) * sin(self.angle + heading)
self.angle += self.angular_velocity
Expand All @@ -131,15 +131,15 @@ def update(self, heading):
def get_trail(self, offset, end=None):
if self.pendulum_arm is not None:
if end is not None:
end.add(self.end)
end += self.end
else:
end = self.end.copy()
return self.pendulum_arm.get_trail(offset, end)
else:
trail = self.end.copy()
if end is not None:
trail.add(end)
trail.add(offset)
trail += end
trail += offset
return trail

def draw(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self, size, hierarchy):
i += 1

def update(self, heading):
self.end.set(self.origin.x + self.size * sin(self.angle), self.origin.y + self.size * cos(self.angle))
self.end = Vec2(self.origin.x + self.size * sin(self.angle), self.origin.y + self.size * cos(self.angle))

self.angular_acceleration = (-self.gravity / self.size) * sin(self.angle + heading)
self.angle += self.angular_velocity
Expand All @@ -147,14 +147,14 @@ def get_trail(self, offset, pendulum_trail_paths=None):
pendulum_trail_paths = []

offset = offset.copy()
offset.add(self.end)
offset += self.end

for pendulum_arm in self.pendulum_arms:
if len(pendulum_arm.pendulum_arms) > 0:
pendulum_arm.get_trail(offset, pendulum_trail_paths)
else:
trail = offset.copy()
trail.add(pendulum_arm.end)
trail += pendulum_arm.end
pendulum_trail_paths.append(trail)

return pendulum_trail_paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(self, size, hierarchy):
self.pendulum_arm = Pendulum(self.size / 1.5, self.hierarchy)

def update(self, heading):
self.end.set(self.origin.x + self.size * sin(self.angle), self.origin.y + self.size * cos(self.angle))
self.end = Vec2(self.origin.x + self.size * sin(self.angle), self.origin.y + self.size * cos(self.angle))

self.angular_acceleration = (-self.gravity / self.size) * sin(self.angle + heading)
self.angle += self.angular_velocity
Expand All @@ -155,15 +155,15 @@ def update(self, heading):
def get_trail(self, offset, end=None):
if self.pendulum_arm is not None:
if end is not None:
end.add(self.end)
end += self.end
else:
end = self.end.copy()
return self.pendulum_arm.get_trail(offset, end)
else:
trail = self.end.copy()
if end is not None:
trail.add(end)
trail.add(offset)
trail += end
trail += offset
return trail

def draw(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def draw(self):
p0 = Vec2(pos[0], pos[1])
p1 = Vec2(next_pos[0], next_pos[1])
v = p1 - p0
v = v.normalize()
v = v.rotate(HALF_PI)
v.mult(d)
v = v.normalized()
v = v.rotated(HALF_PI)
v *= d
pneu = p0 + v
curve_vertex(pneu.x, pneu.y)

Expand Down
Loading
Loading