/
arcs.py
50 lines (45 loc) · 1.51 KB
/
arcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
ROTATION = {0 : 0,
BOTTOM : 0,
DOWN : 0,
1 : HALF_PI,
LEFT : HALF_PI,
2 : PI,
TOP : PI,
UP : PI,
3 : PI + HALF_PI,
RIGHT: PI + HALF_PI,
BOTTOM + RIGHT : 0,
DOWN + RIGHT : 0,
DOWN + LEFT : HALF_PI,
BOTTOM + LEFT : HALF_PI,
TOP + LEFT : PI,
UP + LEFT : PI,
TOP + RIGHT: PI + HALF_PI,
UP + RIGHT: PI + HALF_PI,
}
def quarter_circle(x, y, radius, quadrant):
circle_arc(x, y, radius, ROTATION[quadrant], HALF_PI)
def half_circle(x, y, radius, quadrant):
circle_arc(x, y, radius, ROTATION[quadrant], PI)
def circle_arc(x, y, radius, start_ang, sweep_ang):
arc(x, y, radius * 2, radius * 2, start_ang, start_ang + sweep_ang)
def bar(x1, y1, x2, y2, thickness=None, shorter=0, ends=(1,1)):
"""
O código para fazer as barras, dois pares (x, y),
um parâmetro de encurtamento: shorter
"""
L = dist(x1, y1, x2, y2)
if not thickness:
thickness = 10
with pushMatrix():
translate(x1, y1)
angle = atan2(x1 - x2, y2 - y1)
rotate(angle)
offset = shorter / 2
line(thickness/2, offset, thickness/2, L - offset)
line(-thickness/2, offset, -thickness/2, L - offset)
if ends[0]:
half_circle(0, offset, thickness/2, UP)
if ends[1]:
half_circle(0, L - offset, thickness/2, DOWN)