@@ -64,7 +64,7 @@ We could use a simple function, but Minart already provides some optimized kerne
6464out of the box.
6565
6666``` scala
67- val blurKernel = Kernel .averageBlur(3 , 3 )
67+ val blurKernel = Kernel .averageBlur(9 , 9 )
6868
6969```
7070
@@ -77,15 +77,7 @@ def application(t: Double, canvas: Canvas): Unit = {
7777 val zoom = 1.0 / (frameSin + 2.0 )
7878
7979 val image = updatedBitmap.view.repeating // Create an infinite Plane from our surface
80- .scale(zoom, zoom) // Scale
8180 .coflatMap(blurKernel) // Average blur
82- .rotate(t) // Rotate
83- .contramap((x, y) => (x + (5 * Math .sin(t + y / 10.0 )).toInt, y)) // Wobbly effect
84- .flatMap(color =>
85- (x, y) => // Checkerboard effect
86- if (x % 32 < 16 != y % 32 < 16 ) color.invert
87- else color
88- )
8981
9082 canvas.blitPlane(image)(0 , 0 )
9183}
@@ -94,16 +86,31 @@ def application(t: Double, canvas: Canvas): Unit = {
9486### Putting it all together
9587
9688``` scala
97- val canvasSettings = Canvas .Settings (width = 128 , height = 128 , scale = Some (4 ), clearColor = Color (0 , 0 , 0 ))
89+ val frameCounter = {
90+ var frameNumber : Int = 0
91+ var timer = System .currentTimeMillis
92+ () => {
93+ frameNumber += 1
94+ if (frameNumber % 10 == 0 ) {
95+ val currTime = System .currentTimeMillis()
96+ val fps = 10.0 / ((currTime - timer) / 1000.0 )
97+ println(" FPS:" + fps)
98+ timer = System .currentTimeMillis()
99+ }
100+ }
101+ }
102+
103+ val canvasSettings = Canvas .Settings (width = 512 , height = 512 , scale = Some (1 ), clearColor = Color (0 , 0 , 0 ))
98104
99105AppLoop
100106 .statefulRenderLoop((t : Double ) => (canvas : Canvas ) => {
107+ frameCounter()
101108 canvas.clear()
102109 application(t, canvas)
103110 canvas.redraw()
104111 t + 0.01
105112 }
106113 )
107- .configure(canvasSettings, LoopFrequency .hz60 , 0 )
114+ .configure(canvasSettings, LoopFrequency .Uncapped , 0 )
108115 .run()
109116```
0 commit comments