Last active 1 day ago Unlisted

Revision 9bd8850fcb594fad04d58fb6604a95753c08e312

circ.ml Raw Playground
1let 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