circ.ml
· 881 B · OCaml
Исходник
Playground
let circ ~x ~y ~radius ?(r=0) ?(g=0) ?(b=0) screen =
let t1 = ref (radius / 16) in
let t2 = ref !t1 in
let cx, cy = ref radius, ref 0 in
while !cx >= !cy do
set_pixel screen ( !cx + x) ( !cy + y) ~r ~g ~b ;
set_pixel screen ( !cx + x) (-1 * !cy + y) ~r ~g ~b ;
set_pixel screen (-1 * !cx + x) ( !cy + y) ~r ~g ~b ;
set_pixel screen (-1 * !cx + x) (-1 * !cy + y) ~r ~g ~b ;
set_pixel screen ( !cy + x) ( !cx + y) ~r ~g ~b ;
set_pixel screen ( !cy + x) (-1 * !cx + y) ~r ~g ~b ;
set_pixel screen (-1 * !cy + x) ( !cx + y) ~r ~g ~b ;
set_pixel screen (-1 * !cy + x) (-1 * !cx + y) ~r ~g ~b ;
cy := !cy + 1 ;
t1 := !t1 + !cy ;
t2 := !t1 - !cx ;
if !t2 >= 0 then begin
t1 := !t2 ;
cx := !cx - 1 ;
end
done
| 1 | let circ ~x ~y ~radius ?(r=0) ?(g=0) ?(b=0) screen = |
| 2 | let t1 = ref (radius / 16) in |
| 3 | let t2 = ref !t1 in |
| 4 | let cx, cy = ref radius, ref 0 in |
| 5 | while !cx >= !cy do |
| 6 | set_pixel screen ( !cx + x) ( !cy + y) ~r ~g ~b ; |
| 7 | set_pixel screen ( !cx + x) (-1 * !cy + y) ~r ~g ~b ; |
| 8 | set_pixel screen (-1 * !cx + x) ( !cy + y) ~r ~g ~b ; |
| 9 | set_pixel screen (-1 * !cx + x) (-1 * !cy + y) ~r ~g ~b ; |
| 10 | set_pixel screen ( !cy + x) ( !cx + y) ~r ~g ~b ; |
| 11 | set_pixel screen ( !cy + x) (-1 * !cx + y) ~r ~g ~b ; |
| 12 | set_pixel screen (-1 * !cy + x) ( !cx + y) ~r ~g ~b ; |
| 13 | set_pixel screen (-1 * !cy + x) (-1 * !cx + y) ~r ~g ~b ; |
| 14 | |
| 15 | cy := !cy + 1 ; |
| 16 | t1 := !t1 + !cy ; |
| 17 | t2 := !t1 - !cx ; |
| 18 | if !t2 >= 0 then begin |
| 19 | t1 := !t2 ; |
| 20 | cx := !cx - 1 ; |
| 21 | end |
| 22 | done |