Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions examples/hyperbolic/hypertree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -583,47 +583,21 @@ let from_screen canvas x y =

let pi = 4. *. atan 1.

let ellipse_arc c cx cy rx ry start fin clock_wise =
c##save;
c##translate (Js.float cx) (Js.float cy);
c##scale (Js.float rx) (Js.float ry);
c##arc
(Js.float 0.)
(Js.float 0.)
(Js.float 1.)
(Js.float start)
(Js.float fin)
clock_wise;
c##restore

let arc c (rx, ry, dx, dy) z0 z1 z2 =
let rd = norm (sub z1 z0) in
let start = atan2 (z1.y -. z0.y) (z1.x -. z0.x) in
let fin = atan2 (z2.y -. z0.y) (z2.x -. z0.x) in
c##beginPath;
let alpha = mod_float (fin -. start +. (2. *. pi)) (2. *. pi) in
(*
Firebug.console##log_4(start, fin, alpha, (alpha > pi));
*)
if rx = ry
then
c##arc
(Js.float ((z0.x *. rx) +. dx))
(Js.float ((z0.y *. rx) +. dy))
(Js.float (rd *. rx))
(Js.float start)
(Js.float fin)
(Js.bool (alpha > pi))
else
ellipse_arc
c
((z0.x *. rx) +. dx)
((z0.y *. ry) +. dy)
(rd *. rx)
(rd *. ry)
start
fin
(Js.bool (alpha > pi));
c##ellipse
(Js.float ((z0.x *. rx) +. dx))
(Js.float ((z0.y *. ry) +. dy))
(Js.float (rd *. rx))
(Js.float (rd *. ry))
(Js.float 0.)
(Js.float start)
(Js.float fin)
(Js.bool (alpha > pi));
c##stroke

let line c (rx, ry, dx, dy) z1 z2 =
Expand Down Expand Up @@ -671,7 +645,15 @@ let draw canvas vertices edges nodes boxes =
(Js.float (float canvas##.height));
let padding = Js.to_float (opt_style style##.padding (Js.float 0.)) in
c##beginPath;
ellipse_arc c dx dy (rx +. padding) (ry +. padding) 0. 7. Js._false;
c##ellipse
(Js.float dx)
(Js.float dy)
(Js.float (rx +. padding))
(Js.float (ry +. padding))
(Js.float 0.)
(Js.float 0.)
(Js.float 7.)
Js._false;
Js.Optdef.iter style##.backgroundColor (fun color ->
c##.fillStyle := color;
c##fill);
Expand Down
11 changes: 11 additions & 0 deletions lib/js_of_ocaml/dom_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,17 @@ and canvasRenderingContext2D = object
method arc :
number_t -> number_t -> number_t -> number_t -> number_t -> bool t -> unit meth

method ellipse :
number_t
-> number_t
-> number_t
-> number_t
-> number_t
-> number_t
-> number_t
-> bool t
-> unit meth

method fill : unit meth

method stroke : unit meth
Expand Down
11 changes: 11 additions & 0 deletions lib/js_of_ocaml/dom_html.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,17 @@ and canvasRenderingContext2D = object
method arc :
number_t -> number_t -> number_t -> number_t -> number_t -> bool t -> unit meth

method ellipse :
number_t
-> number_t
-> number_t
-> number_t
-> number_t
-> number_t
-> number_t
-> bool t
-> unit meth

method fill : unit meth

method stroke : unit meth
Expand Down