46 |
method key () = read_key() |
method key () = read_key() |
47 |
end |
end |
48 |
|
|
49 |
type flag_object = DRAW | NO_DRAW |
type flag_object = DRAW | NO_DRAW | ANIMATION |
50 |
|
|
51 |
class point (x_init,y_init) (name: string) (flag: flag_object) = |
class point (x_init,y_init) (name: string) (flag: flag_object) = |
52 |
object(self) |
object(self) |
70 |
draw_string name; |
draw_string name; |
71 |
set_color black |
set_color black |
72 |
end |
end |
73 |
end |
method redraw () = |
74 |
|
begin |
75 |
|
set_color red; |
76 |
|
fill_circle x y 4; |
77 |
|
moveto (x+6) (y+6); |
78 |
|
draw_string name; |
79 |
|
set_color black |
80 |
|
end |
81 |
|
end |
82 |
|
|
83 |
class line (p1: point) (p2: point) (name: string) (flag: flag_object) = |
class line (p1: point) (p2: point) (name: string) (flag: flag_object) = |
84 |
object(self) |
object(self) |
107 |
a#draw(); |
a#draw(); |
108 |
b#draw() |
b#draw() |
109 |
end |
end |
110 |
end |
method redraw () = |
111 |
|
begin |
112 |
|
set_color black; |
113 |
|
let (x1,y1) = min (a#get_x (),a#get_y ()) (b#get_x (),b#get_y ()) in |
114 |
|
let (x2,y2) = max (a#get_x (),a#get_y ()) (b#get_x (),b#get_y ()) in |
115 |
|
let dx = x2 - x1 in |
116 |
|
let dy = y2 - y1 in |
117 |
|
draw_poly_line [|(x2 + dx , y2 + dy);(x1 - dx , y1 - dy)|]; |
118 |
|
a#draw(); |
119 |
|
b#draw() |
120 |
|
end |
121 |
|
end |
122 |
|
|
123 |
class segment (p1: point) (p2: point) (name: string) (flag: flag_object) = |
class segment (p1: point) (p2: point) (name: string) (flag: flag_object) = |
124 |
object |
object |
134 |
a#draw(); |
a#draw(); |
135 |
b#draw() |
b#draw() |
136 |
end |
end |
137 |
|
method redraw () = |
138 |
|
begin |
139 |
|
set_color black; |
140 |
|
let (x1,y1) = (a#get_x (),a#get_y ()) in |
141 |
|
let (x2,y2) = (b#get_x (),b#get_y ()) in |
142 |
|
draw_poly_line [|(x2,y2);(x1,y1)|]; |
143 |
|
a#draw(); |
144 |
|
b#draw() |
145 |
|
end |
146 |
end |
end |
147 |
|
|
148 |
class circle (p1: point) (p2: point) (name: string) (flag: flag_object) = |
class circle (p1: point) (p2: point) (name: string) (flag: flag_object) = |
159 |
method draw () = |
method draw () = |
160 |
if flag=NO_DRAW then () |
if flag=NO_DRAW then () |
161 |
else |
else |
162 |
begin |
if flag=ANIMATION then |
163 |
draw_circle (center#get_x ()) (center#get_y ()) radius; |
begin |
164 |
center#draw(); |
let teta = ref 0. in |
165 |
p2#draw() |
let rf = float_of_int radius in |
166 |
end |
let xf = float_of_int (center#get_x ()) and yf = float_of_int (center#get_y ()) in |
167 |
|
let x' = ref (int_of_float ((sin 0.) *. rf +. xf)) and y' = ref (int_of_float((cos 0.) *. rf +. yf)) in |
168 |
|
Graphics.plot !x' !y'; |
169 |
|
Graphics.moveto !x' !y'; |
170 |
|
while !teta <= 6.28319 do |
171 |
|
let new_x' = round ((sin !teta) *. rf +. xf) and new_y' = int_of_float((cos !teta) *. rf +. yf) in |
172 |
|
Graphics.lineto new_x' new_y'; |
173 |
|
teta := !teta +. 0.02; |
174 |
|
for i=0 to 400000 do () done |
175 |
|
done; |
176 |
|
end |
177 |
|
else |
178 |
|
begin |
179 |
|
draw_circle (center#get_x ()) (center#get_y ()) radius; |
180 |
|
center#draw(); |
181 |
|
p2#draw() |
182 |
|
end |
183 |
|
method redraw () = |
184 |
|
begin |
185 |
|
draw_circle (center#get_x ()) (center#get_y ()) radius; |
186 |
|
center#draw(); |
187 |
|
p2#draw() |
188 |
|
end |
189 |
end |
end |
190 |
|
|
191 |
class figure (x,y) = |
class figure (x,y) = |
192 |
object(self) |
object(self) |
193 |
inherit window (x,y) as w |
inherit window (x,y) as w |
270 |
method redraw () = |
method redraw () = |
271 |
begin |
begin |
272 |
w#clear(); |
w#clear(); |
273 |
List.iter (fun o -> o#draw()) point_list; |
List.iter (fun o -> o#redraw()) point_list; |
274 |
List.iter (fun o -> o#draw()) line_list; |
List.iter (fun o -> o#redraw()) line_list; |
275 |
List.iter (fun o -> o#draw()) circle_list; |
List.iter (fun o -> o#redraw()) circle_list |
276 |
end |
end |
277 |
|
|
278 |
|
|