summaryrefslogtreecommitdiff
path: root/testdata/editor-examples/Heartbeat.lc
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-02-22 15:01:02 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-02-22 15:01:02 +0100
commit7d0bf6578695466e6116566332072f5fcfa4a903 (patch)
tree0d977864b6aa60adc81801880d31df00214e1c9e /testdata/editor-examples/Heartbeat.lc
parent23107ec58f3831512da0f46d5dc3457de2d5de66 (diff)
adjust heartbeat example
Diffstat (limited to 'testdata/editor-examples/Heartbeat.lc')
-rw-r--r--testdata/editor-examples/Heartbeat.lc40
1 files changed, 40 insertions, 0 deletions
diff --git a/testdata/editor-examples/Heartbeat.lc b/testdata/editor-examples/Heartbeat.lc
new file mode 100644
index 00000000..3fb4bf02
--- /dev/null
+++ b/testdata/editor-examples/Heartbeat.lc
@@ -0,0 +1,40 @@
1time = Uniform "Time" :: Float
2
3clear = FrameBuffer $ (DepthImage @1 1000, ColorImage @1 red) -- ...
4clear' = FrameBuffer $ (DepthImage @1 1000, ColorImage @1 blue) -- ...
5
6triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
7triangles = triangleRasterCtx
8colorFragmentCtx = (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
9
10rasterizeWith s = rasterizePrimitives triangles ((Smooth)) s
11
12cubeVertexStream = fetch "stream4" Triangle (Attribute "position4" :: Vec 4 Float, Attribute "vertexUV" :: Vec 2 Float)
13mapFragments2 s fs = accumulate colorFragmentCtx (\((a)) -> ((fs a))) s clear
14
15rotate' v = (Uniform "MVP" :: Mat 4 4 Float) `PrimMulMatVec` v
16
17texImage = PrjImageColor $
18 cubeVertexStream -- cube vertices
19 & mapPrimitives (\(x, y) -> (scale 1.0 x, V2 y%x (1-y%y)))
20 & rasterizeWith -- rasterize
21 `mapFragments2`
22 (\xy -> let
23 x = ((xy :: Vec 2 Float)%x :: Float) -! 0.85
24 y = ((xy :: Vec 2 Float)%y :: Float) -! 0.85
25 t = (0.0005 *! sin (3 *! PrimATan2 x y +! 15 *! time))
26 t' = (0.002 *! sin (5 *! PrimATan2 x y -! 5 *! time))
27 t'' = (0.002 *! sin (7 *! PrimATan2 x y +! 3 *! time))
28 ti = (PrimAbs $ sin (time *! 4) -! 0.37)
29 in if x*!x +! y*!y +! t < 0.005 *! ti then navy else
30 if x*!x +! y*!y +! t' < 0.02 *! ti then blue else
31 if x*!x +! y*!y +! t'' < 0.05 *! ti then white else yellow
32 )
33
34sampler = Sampler LinearFilter MirroredRepeat $ Texture2D (V2 128 128) texImage
35
36main = cubeVertexStream -- cube vertices
37 & mapPrimitives (\(x, y) -> (scale 0.5 . rotate' $ x, y))
38 & rasterizeWith -- rasterize
39 `mapFragments2` (texture2D sampler)
40 & ScreenOut -- draw into screen