OLD | NEW |
1 // Copyright (c) 2016, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 import 'dart:math'; | 5 import 'dart:math'; |
6 | 6 |
7 import 'package:stm32/stm32f746g_disco.dart'; | 7 import 'package:stm32/stm32f746g_disco.dart'; |
8 import 'package:stm32/lcd.dart'; | 8 import 'package:stm32/lcd.dart'; |
9 | 9 |
10 main() { | 10 main() { |
11 // Initialize display, and get display dimensions. | 11 // Initialize display, and get display dimensions. |
12 STM32F746GDiscovery discoBoard = new STM32F746GDiscovery(); | 12 STM32F746GDiscovery discoBoard = new STM32F746GDiscovery(); |
13 var display = discoBoard.frameBuffer; | 13 var display = discoBoard.frameBuffer; |
14 display.backgroundColor = Color.black; | 14 display.backgroundColor = Color.black; |
15 int w = display.width; | 15 int w = display.width; |
16 int h = display.height; | 16 int h = display.height; |
17 | 17 |
18 // Loop eternally drawing random lines. | 18 // Loop eternally drawing random lines. |
19 Random rnd = new Random(42); | 19 Random rnd = new Random(42); |
20 int lineCounter = 0; | 20 int lineCounter = 0; |
21 while (true) { | 21 while (true) { |
22 // Render a line of random color from the centre to a random location. | 22 // Render a line of random color from the centre to a random location. |
23 var color = new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)); | 23 var color = new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)); |
24 display.drawLine(w ~/ 2, h ~/ 2, rnd.nextInt(w), rnd.nextInt(h), color); | 24 display.drawLine(w ~/ 2, h ~/ 2, rnd.nextInt(w), rnd.nextInt(h), color); |
25 | 25 |
26 // Every 100 lines, clear the display and update the counter. | 26 // Every 100 lines, clear the display and update the counter. |
27 lineCounter += 1; | 27 lineCounter += 1; |
28 if ((lineCounter % 100) == 0) { | 28 if ((lineCounter % 100) == 0) { |
29 display.clear(Color.black); | 29 display.clear(); |
30 display.writeText(10, 10, 'Rendered $lineCounter lines'); | 30 display.writeText(10, 10, 'Rendered $lineCounter lines'); |
31 } | 31 } |
32 } | 32 } |
33 } | 33 } |
OLD | NEW |