-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathch2ex7.dart
38 lines (30 loc) · 1.05 KB
/
ch2ex7.dart
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
library ch2.ex7;
import 'dart:html';
import 'dart:math' as math;
// The dart print() command will automatically print to the console
// and shouldn't throw an exception so no need to worry about creating
// our own debugger. For more complicated logging the logger package exists.
// Since dart supports class inheritance and library namespaces
// we don't need to keep our methods/properties in a local scope.
class CanvasApp {
CanvasElement theCanvas;
CanvasRenderingContext2D context;
CanvasApp() {
// Initialize the canvas and context
theCanvas = document.querySelector('#canvas');
context = theCanvas.getContext('2d');
}
void drawScreen() {
// Content goes here.
// Draw a red square and rotate it
var angleInRadians = 45 * (math.PI / 180);
context..setTransform(1, 0, 0, 1, 0, 0) // Required before rotating
..rotate(angleInRadians) // Rotate before drawing
..fillStyle = 'red'
..fillRect(100, 100, 50, 50);
}
}
void main() {
var canvasApp = new CanvasApp();
canvasApp.drawScreen();
}