Just some guys
Just some guys
Rather happy with how well this worked
let fill_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
for py = -(!cy) to !cy do
set_pixel screen (!cx + x) (py + y) ~r ~g ~b ;
set_pixel screen (-1 * !cx + x) (py + y) ~r ~g ~b ;
done ;
for py = -(!cx) to !cx do
set_pixel screen (!cy + x) (py + y) ~r ~g ~b ;
set_pixel screen (-1 * !cy + x) (py + y) ~r ~g ~b ;
done ;
cy := !cy + 1 ;
t1 := !t1 + !cy ;
t2 := !t1 - !cx ;
if !t2 >= 0 then begin
t1 := !t2 ;
cx := !cx - 1 ;
end
done
@atax1a I am so thankful OCaml respects the need for mutable state. Having to contort everything into recursive iteration can be such a pain in the fuckin ass. Especially, when you are standing directly on the FFI boundary.
This whole little project has been "purely procedural" OCaml and it's extremely nice to use. There is very much a good reason to use OCaml even if you aren't leveraging it's functional origins.
downto instead of some clumsy "iterate with a negative step" bullshit that like... literally every procedural language asks you to do...downto is the, like, one Pascal feature we don't find to be arrant european puffery, so, yeah