added comments explaining the puzzle generation code
This commit is contained in:
parent
441d733935
commit
7d828f5fbf
|
@ -64,30 +64,32 @@ def svg_puzzle(p, size, angle):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def svg_line_puzzle(start, end, puzzle_scale=1.0, linewidth=0.50):
|
def svg_line_puzzle(start, end, puzzle_scale=1.0, linewidth=0.50):
|
||||||
v = end - start
|
# draws a line from start to end with a simple jigsaw puzzle style cutout in the middle
|
||||||
dist = np.linalg.norm(v)
|
# the size of the cutout can be controlled with the puzzle_scale parameter
|
||||||
size = dist / 10.0 * puzzle_scale
|
|
||||||
v = v / dist
|
|
||||||
angle = math.atan2(v[1], v[0])
|
|
||||||
|
|
||||||
p = np.mean([start, end], axis=0)
|
|
||||||
|
|
||||||
# compute points
|
# compute points
|
||||||
"""
|
"""
|
||||||
v1 and v2 are orthogonal vectors
|
v1 and v2 are orthogonal vectors
|
||||||
|
|
||||||
construction of points (starting at p):
|
construction of points (starting at p (middle between start and end)):
|
||||||
|
|
||||||
p3 <------ -2 v1 ------ p2
|
p2 ------- 2 v1 -----> p3
|
||||||
^
|
^
|
||||||
|
|
|
|
||||||
v2
|
v2
|
||||||
|
|
|
|
||||||
|
|
|
|
||||||
p4 <-- -v1 -- p -- v1 --> p1
|
start --- p1 <-- -v1 -- p -- v1 --> p4 --- end
|
||||||
|
|
||||||
then between points p2 and p3 with draw an arc
|
then between points p2 and p3 with draw an arc
|
||||||
"""
|
"""
|
||||||
|
v = end - start
|
||||||
|
dist = np.linalg.norm(v)
|
||||||
|
size = dist / 10.0 * puzzle_scale # size of the cutout
|
||||||
|
v = v / dist
|
||||||
|
angle = math.atan2(v[1], v[0]) # angle of v
|
||||||
|
|
||||||
|
# midpoint between start and end
|
||||||
|
p = np.mean([start, end], axis=0)
|
||||||
|
|
||||||
v1 = np.array([np.cos(angle), np.sin(angle)])
|
v1 = np.array([np.cos(angle), np.sin(angle)])
|
||||||
v2 = np.array([v1[1], -v1[0]])
|
v2 = np.array([v1[1], -v1[0]])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user