open Garland_jsoo (* Hello! You can click the RUN button on the top middle to see the results. The simplest garland is a single static color: *) let my_red_garland = red let () = print_endline "My red garland:" let () = run ~nb_leds:60 my_red_garland ;; (* There are more colors available! You can chain garlands together with the ( --- ) operator. They will render side by side. *) let my_rainbow_garland = red --- yellow --- green --- cyan --- blue --- pink let () = print_endline "My rainbow garland:" let () = run ~nb_leds:60 my_rainbow_garland ;; (* You can also create gradients with the ( --> ) operator. *) let my_gradient = white --> yellow --> red --> black let () = print_endline "My gradient from white to yellow to red to black:" let () = run ~nb_leds:60 my_gradient ;; (* But a static garland is fairly boring! Let's add a rotation: *) let my_rotating_rainbow = rotate my_gradient (* The default rotation performs a full cycle in 1s. It's a bit fast, let's slow it down: *) let my_rotating_rainbow = speed 0.25 my_rotating_rainbow let () = print_endline "My rotating rainbow garland:" let () = run ~nb_leds:60 my_rotating_rainbow ;; (* The (---) operator can display two animated garlands side by side: *) let my_mirrored_rainbow = my_rotating_rainbow --- flip my_rotating_rainbow (* [flip] is doing a horizontal mirror. Try using [rev] to reverse the flow of time! *) let () = print_endline "My mirrored rainbow" let () = run ~nb_leds:60 my_mirrored_rainbow ;; let () = run ~nb_leds:60 (my_mirrored_rainbow --- my_mirrored_rainbow) ;; (* We can schedule animations in a sequence with the ( === ) operator *) let my_sequence_rainbow = red === yellow === green === cyan === blue === pink let () = print_endline "My sequence rainbow:" let () = run ~nb_leds:60 (speed 3.0 my_sequence_rainbow) ;; (* You can also create gradient in time with ( ==> ) *) let my_time_gradient = white ==> yellow ==> red ==> black ==> duration 0.0 white let my_time_gradient = speed 2.0 my_time_gradient let () = print_endline "My gradient in time:" let () = run ~nb_leds:60 my_time_gradient ;; (* And we can [offset] a garland to delay its animation: *) let my_offset = my_time_gradient --- offset 1.5 my_time_gradient --- offset 3.0 my_time_gradient --- offset 4.5 my_time_gradient --- offset 6.0 my_time_gradient let () = print_endline "My gradient offseted:" let () = run ~nb_leds:60 my_offset ;; (* You can vary the horizontal "weight" of an item *) let my_weight = (weight 0.0 red ==> weight 10.0 red ==> instant (weight 0.0 red)) --- green --- (weight 10.0 blue ==> weight 0.0 blue ==> instant (weight 10.0 blue)) let () = print_endline "Varying RGB weight:" let () = run ~nb_leds:60 my_weight ;; (* Let's use Random for a typical Christmas effect: *) let random_yellow _ = map_luminosity (fun _ -> Tween.square (Random.float 1.0)) yellow let random_garland _ = let t = Array.init 60 random_yellow in Array.fold_left ( --- ) (point t.(0)) t let blink = Array.fold_left ( === ) (random_garland 0) @@ Array.init 10 random_garland let blink = speed 8.0 (loop blink) ==> black let () = print_endline "Blink blink:" let () = run ~nb_leds:60 blink (* A last example because I'm running out of ideas: *) let disapear t = weight 1.0 t ==> instant (weight 0.0 t) let test blue = disapear transparent --- rev (disapear (blue --> white)) === disapear (blue --> yellow) --- rev (disapear transparent) let test' c = tween Tween.out_bounce (test c) let test c = flip (test' c) --- (test' c) let test = speed 1. (test red) +++ offset 2.25 (test pink) let () = print_endline "A last example:" let () = run ~nb_leds:60 test
Run
Stop
Don't forget to share your creations at
well-typed-lightbulbs/garland-combinator
!