-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdraw_space.rb
69 lines (52 loc) · 1007 Bytes
/
draw_space.rb
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'matrix'
class Vector #TODO consider using PVector from Processing instead
def x
self[0]
end
def y
self[1]
end
end
module Visible
def vec2_line(v1, v2)
line v1.x, v1.y, v2.x, v2.y
end
def pos
Vector[body.p.x, body.p.y]
end
def body_translate
translate pos.x, pos.y
rotate body.angle
end
class Circle < CP::Shape::Circle
include Visible
def initialize(body, rad, offset_vec)
super(body, rad, offset_vec)
@rad = rad
end
def rad
@rad
end
def draw
body_translate
ellipse 0, 0, @rad, @rad
4.times{
rotate HALF_PI
vec2_line Vector[0, @rad*0.75], Vector[0, @rad]
}
end
end
class Segment < CP::Shape::Segment
include Visible
def initialize(body, v1, v2, r)
super(body, v1, v2, r)
@v1 = Vector[v1.x, v1.y]
@v2 = Vector[v2.x, v2.y]
@r = r
end
def draw
body_translate
vec2_line @v1, @v2
end
end
end