This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjauge.ml
56 lines (49 loc) · 1.92 KB
/
jauge.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
open OcsfmlGraphics
class jauge ?(t0=0.) ?(tmax=1.) ?(bg_color=Color.white) ?(begin_color=Color.yellow) ?(end_color=Color.red) ?position ?rotation ?scale ?origin size =
let t0 = max (min (t0/.tmax) 1.) 0. in
let addv (x,y) x' y' = (x+.x', y+.y') in
let h = snd size in
let w t = t *. (fst size) in
let interpolation col1 col2 t =
Color.({
r = int_of_float (t*.(float col2.r) +. (1.-.t)*.(float col1.r)) ;
g = int_of_float (t*.(float col2.g) +. (1.-.t)*.(float col1.g)) ;
b = int_of_float (t*.(float col2.b) +. (1.-.t)*.(float col1.b)) ;
a = 255
}) in
let content0 = [
mk_vertex ~position:(0.,0.) ~color:begin_color () ;
mk_vertex ~position:(0., h) ~color:begin_color () ;
mk_vertex ~position:(w t0, h) ~color:(interpolation begin_color end_color t0) () ;
mk_vertex ~position:(w t0, 0.) ~color:(interpolation begin_color end_color t0) ()
]
in
object (self)
inherit transformable ?position ?rotation ?scale ?origin ()
inherit drawable ~overloaded:`draw (Drawable.inherits ())
val content = new vertex_array ~primitive_type:Quads content0
val cadre = new rectangle_shape ~size ~fill_color:bg_color ~outline_color:Color.black ~outline_thickness:2.0 ()
val mutable tmax = tmax
method update t =
let t = min (t/.tmax) 1. in
let pos = (content#get_at_index 0).position in
content#set_at_index 2
(mk_vertex
~position:(addv pos (w t) h)
~color:(interpolation begin_color end_color t) ()) ;
content#set_at_index 3
(mk_vertex
~position:(addv pos (w t) 0.)
~color:(interpolation begin_color end_color t) ())
method draw app blend_mode transform0 texture shader =
let transform = self#get_transform#combine transform0 in
app#draw
~blend_mode
~transform
~texture ~shader cadre ;
app#draw
~blend_mode
~transform
~texture ~shader content
method set_max_val maxval = tmax <- maxval ; self#update 0.0
end