Module Cnv

module Cnv: sig .. end

A small module, to create html5-canvas documents


type doc 
val new_document : width:int -> height:int -> unit -> doc

creates a new .html document, with a canvas of size (width, height)

val finish : doc -> unit

closes the html document

val add_comment : doc -> s:string -> unit -> unit

adds a javascript comment in the script part of the html-document

val add_newline : doc -> unit

adds a newline in the script part of the html document

val get_document : doc -> string

return the result .html document as a string

val write_file : doc -> filename:string -> unit

write the result .html document to a file

val print_document : doc -> unit

prints the result .html document to stdout

Shapes

val add_rect : doc ->
x:int ->
y:int ->
width:int ->
height:int ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_circle : doc ->
c:float * float ->
r:float ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_triangle : doc ->
p1:int * int ->
p2:int * int ->
p3:int * int ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_line : doc ->
p1:int * int ->
p2:int * int -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_polyline : doc ->
points:(int * int) list ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_polygon : doc ->
points:(int * int) list ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_ellipse : doc ->
c:float * float ->
rs:float * float ->
?angle:float ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_text : doc ->
x:int ->
y:int ->
text:string ->
font:string ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val add_path : doc ->
d:string ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit

Paths

type path 
val add_path2 : doc ->
f:(path -> path) ->
?fill:string -> ?stroke:string -> ?stroke_width:float -> unit -> unit
val move_to : path -> x:float -> y:float -> path
val line_to : path -> x:float -> y:float -> path
val arc_to : path ->
x1:float -> y1:float -> x2:float -> y2:float -> radius:float -> path
val quad_curve : path -> x1:float -> y1:float -> x:float -> y:float -> path
val cubic_curve : path ->
x1:float ->
y1:float -> x2:float -> y2:float -> x:float -> y:float -> path
val close_path : path -> path

SVG inclusion

val add_svg_document : doc -> frag:string -> x:int -> y:int -> unit -> unit

Transformations

val begin_group : doc ->
?translate:float * float ->
?rotate:float -> ?scale:float * float -> unit -> unit
val end_group : doc -> unit
val to_radian : float -> float

converts angles from degrees to radians

Gradients

type def 

defines additional elements, that can be used in conjunction with other shapes elements

val linear_gradient : p1:int * int ->
p2:int * int ->
stops:(float * string) list ->
?translate:int * int -> unit -> def * string

a stop should be a tuple with a float between 0.0 and 1.0, and a color

returns a def that should be added to the document with add_def,

and a string that should be provided to the fill parameter of shape functions

val radial_gradient : c1:int * int ->
c2:int * int ->
rs:int * int ->
stops:(float * string) list ->
?translate:int * int -> unit -> def * string
val conic_gradient : c:int * int ->
start_angle:float ->
stops:(float * string) list ->
?translate:int * int -> unit -> def * string
val add_def : doc -> def -> unit

add a definition to the html document

val add_defs : doc -> def list -> unit

add some definitions to the html document