Emphasis on Maze Generation
Text
Executes only once
Executes in Loop
approx 60Hz
Try
Axes
Axes
Try
Try
Challenge: Get rid of the trace!?
Try
Challenge: Get rid of the trace!?
Try
Challenge: Get rid of the trace!?
Reasoning?
Try
Draw Rectangle
rect(x,y,w,h)
Try
"Objectify" It!!
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
ncols,nrows=??
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
ncols,nrows=??
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
ncols,nrows=??
0
1
ncol
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
ncols,nrows=??
0
1
ncol
nrows
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
ncols,nrows=??
0
1
ncol
nrows
for (var x = 0; x < cols; ++x) {
grid[x] = new Array(rows); // add 2d array
for (var y = 0; y < rows; ++y) {
var cell = new Cell(x, y);
grid[x][y] = cell;
//grid[x][y].show();
}
}
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
var w = 50;
var grid = [];
var cols = 0;
var rows = 0;
var canvasHeight = 400+2;
var canvasWidth = 400+2;
function Cell(x, y) {
this.x = x*w;
this.y = y*w;
this.show = function () {
var x = this.x ;
var y = this.y ;
fill(255);
rect(x, y, w, w);
}
}
var cell;
function setup() {
createCanvas(400, 400);
background(0);
cols = floor(canvasWidth / w);
rows = floor(canvasHeight / w);
for (var x = 0; x < cols; ++x) {
grid[x] = new Array(rows); // add 2d array
for (var y = 0; y < rows; ++y) {
var cell = new Cell(x, y);
grid[x][y] = cell;
//grid[x][y].show();
}
}
}
function draw() {
for (var x = 0; x < cols; ++x) {
for (var y = 0; y < rows; ++y) {
grid[x][y].show();
}
}
}
Try
Add more "Logic"
Before That... How will you fill in a "Grid of Cells"??
Add more "Logic"
Cell(0,0)
Cell(m,n)
All other cells
No fill if cell is not visited