Repository navigation
Expand file tree
/
Copy pathMain.lean
More file actions
49 lines (38 loc) · 1.48 KB
/
Copy pathMain.lean
File metadata and controls
49 lines (38 loc) · 1.48 KB
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
import LeanPan
-- This example has no state so we use unit
abbrev State := Unit
@[inline]
def polarCheckerExample (x y : Float) : UInt32 :=
if polarChecker 10 ⟨x, y⟩ then Color.white.toUInt32 else Color.black.toUInt32
@[inline]
def wavDistExample (x y : Float) : UInt32 :=
Color.grey (intensity := wavDist ⟨x, y⟩) |>.toUInt32
@[inline]
def bilerpExample (x y : Float) : UInt32 :=
-- Assumes that the window scale is set to 1
let i : Image Color := bilerpC_simd Color.black Color.red Color.blue Color.white
(translate (-0.5) (-0.5) i) ⟨x, y⟩ |>.toUInt32
@[inline]
def bilerpExample_unbox (x y : Float) : UInt32 :=
-- Assumes that the window scale is set to 1
let i : Image ColorUnbox := bilerpC_simd_unbox .black .red .blue .white
((translate (-0.5) (-0.5) i) ⟨x, y⟩).argb
@[inline, export image_frame]
def imageFrame (_state : Unit) (x y : Float) : UInt32 :=
bilerpExample x y
@[extern "render"]
opaque render : (state : @& State) → IO Bool
def main : IO Unit := do
initSquareWindow (dimension := 800) (scale := 1) (title := "Hello World")
let mut frameCount := 0
let mut elapsed : Float := 0
while not (← windowShouldClose) do
if not (← render .unit) then
return
frameCount := frameCount + 1
elapsed := elapsed + (← getTime)
if frameCount % 2 == 0 && elapsed > 0 then do
let fps := frameCount.toFloat / elapsed
IO.println s!"Frame {frameCount}: {fps} FPS (avg over {elapsed}s)"
frameCount := 0
elapsed := 0