Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S01a #1

Open
wants to merge 2 commits into
base: s00a
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MagicBoxes.dart.js
*~
30 changes: 30 additions & 0 deletions Board.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Board {

int x = 0;
int y = 0;
int width;
int height;

CanvasRenderingContext2D context;

Board(CanvasElement canvas) {
context = canvas.getContext("2d");
width = canvas.width;
height = canvas.height;
border();
init();
}

void init() {
new Box(this, 20, 20, 40, 60);
new Box(this, 120, 40, 60, 40);
}

void border() {
context.beginPath();
context.rect(x, y, width, height);
context.closePath();
context.stroke();
}

}
21 changes: 21 additions & 0 deletions Box.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Box {

Board board;

int x;
int y;
int width;
int height;

Box(this.board, this.x, this.y, this.width, this.height) {
draw();
}

void draw() {
board.context.beginPath();
board.context.rect(x, y, width, height);
board.context.closePath();
board.context.stroke();
}

}
21 changes: 7 additions & 14 deletions MagicBoxes.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#import('dart:html');
#source('Box.dart');
#source('Board.dart');

class MagicBoxes {
// branch s01a

MagicBoxes() {
}

void run() {
write("Hello World!");
}

void write(String message) {
// the HTML library defines a global "document" variable
document.query('#status').innerHTML = message;
}
}
// See the style guide: http://www.dartlang.org/articles/style-guide/.

void main() {
new MagicBoxes().run();
// Get a reference to the canvas.
CanvasElement canvas = document.query('#canvas');
Board board = new Board(canvas);
}
Loading