diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2016-02-22 15:01:02 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2016-02-22 15:01:02 +0100 |
commit | 7d0bf6578695466e6116566332072f5fcfa4a903 (patch) | |
tree | 0d977864b6aa60adc81801880d31df00214e1c9e /testdata/editor-examples/Heartbeat.lc | |
parent | 23107ec58f3831512da0f46d5dc3457de2d5de66 (diff) |
adjust heartbeat example
Diffstat (limited to 'testdata/editor-examples/Heartbeat.lc')
-rw-r--r-- | testdata/editor-examples/Heartbeat.lc | 40 |
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 @@ | |||
1 | time = Uniform "Time" :: Float | ||
2 | |||
3 | clear = FrameBuffer $ (DepthImage @1 1000, ColorImage @1 red) -- ... | ||
4 | clear' = FrameBuffer $ (DepthImage @1 1000, ColorImage @1 blue) -- ... | ||
5 | |||
6 | triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex | ||
7 | triangles = triangleRasterCtx | ||
8 | colorFragmentCtx = (DepthOp Less True, ColorOp NoBlending (V4 True True True True)) | ||
9 | |||
10 | rasterizeWith s = rasterizePrimitives triangles ((Smooth)) s | ||
11 | |||
12 | cubeVertexStream = fetch "stream4" Triangle (Attribute "position4" :: Vec 4 Float, Attribute "vertexUV" :: Vec 2 Float) | ||
13 | mapFragments2 s fs = accumulate colorFragmentCtx (\((a)) -> ((fs a))) s clear | ||
14 | |||
15 | rotate' v = (Uniform "MVP" :: Mat 4 4 Float) `PrimMulMatVec` v | ||
16 | |||
17 | texImage = 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 | |||
34 | sampler = Sampler LinearFilter MirroredRepeat $ Texture2D (V2 128 128) texImage | ||
35 | |||
36 | main = 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 | ||