-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.rb
64 lines (52 loc) · 935 Bytes
/
tree.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
require_relative 'figure'
class Tree
attr_accessor :a, :b, :c
def initialize(a,b)
@a = a.to_f
@b = b.to_f
@c = 3.14 / 180
end
def cone
r=10
glColor3f(0.0,0.7,0.2)
glBegin(GL_TRIANGLE_FAN)
glVertex3f(0,0,20)
for i in(0..361).step(2) do
x= r*Math.cos(i*@c)
y= r*Math.sin(i*@c)
glVertex3f(x,y,0)
end
glEnd
end
def cone_tree
#Tree trunk
glColor3f(0.9,0.3,0)
glPushMatrix
glTranslatef(@a,@b,-1)
glRotatef(90,1,0,0)
f = Figure.new
f.cylinder(3,15)
glPopMatrix
#Cone shaped tree top
glPushMatrix
glTranslatef(@a,@b,8)
cone()
glPopMatrix
end
def sphere_tree
#Tree trunk
glColor3f(1,0.2,0)
glPushMatrix
glTranslatef(@a,@b,-1)
glRotatef(90,1,0,0)
f = Figure.new
f.cylinder(6,25)
glPopMatrix
#Sphere shaped tree top
glColor3f(0,1,0.3)
glPushMatrix
glTranslatef(@a,@b,45)
glutSolidSphere(30,10,10)
glPopMatrix
end
end