Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Jun 18, 2020
1 parent 2871b2e commit 5da993a
Show file tree
Hide file tree
Showing 41 changed files with 5,015 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Aldous-Broder/index copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<!-- <script src="https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/p5.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.js"></script>

<title>Maze Generation</title>
<style>
#defaultCanvas0
{
transform: rotate(90deg) scaleY(-1);
border: 3px solid black;
}
</style>
</head>
<body>
<!-- <script src="ray.js"></script>
<script src="boundary.js"></script>
<script src="particle.js"></script> -->
<script src="sketch copy.js"></script>
</body>
</html>
58 changes: 58 additions & 0 deletions Aldous-Broder/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<!-- <script src="https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/p5.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.js"></script>

<title>Maze Generation</title>
<style>
button {
padding: 20px;
margin-left: 20px;
margin-top: 50px;
width: 150px;
clear: both;

}

#defaultCanvas0 {
transform: rotate(90deg) scaleY(-1);
border: 3px solid black;
margin-left: 25px;
margin-top: 25px;
float: left;
}
</style>
</head>

<body>
<button id="play" onclick="Play()">Play</button>
<button onclick="redraw()">Next Step</button>

<script src="sketch.js"></script>
<script>

var Button = document.querySelector('#play');
var flag = 0;
function Play() {
if (flag % 2 != 0) {
//pause
noLoop();
Button.innerHTML = "Play";
}
else {
//play
loop();
Button.innerHTML = "Pause";

}
flag++;
}
</script>
</body>

</html>
145 changes: 145 additions & 0 deletions Aldous-Broder/sketch copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
var w;
var size;
var rows;
var cols;
var grid = [];
var v;
var u;
var cnt = 0;

function setup() {
size = 1000;
w = 10;
createCanvas(size, size);
// frameRate(20);
background(255, 204, 0);
rows = floor(size / w);
cols = floor(size / w);
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
var cell = new Cell(r, c);
grid.push(cell);
}
}
AldousBroder();
console.log("Aldous Broder Algorithm Comopleted");

}

function AldousBroder() {
v = random(grid);
v.markVisited();
cnt++;
while (cnt != rows * cols) { // until all cells have not been visited
var current_neighbours = v.checkNeighbours();
var u = random(current_neighbours);
// if(cnt!=rows*cols)
u.focus();
if (!u.visited) {
v.connect(u);
u.markVisited();
cnt++;
}
v = u;
}

}

function draw() {
stroke(51);
noFill();
for (let i = 0; i < grid.length; i++) {
grid[i].show();
}
}



function Cell(i, j) {
this.i = i;
this.j = j;
this.index = Index(i, j);
this.walls = [true, true, true, true];
this.visited = false;
this.parent = -1;
this.checkNeighbours = function () {

var neighbours = [];
var top = grid[Index(i - 1, j)];
var right = grid[Index(i, j + 1)];
var bottom = grid[Index(i + 1, j)];
var left = grid[Index(i, j - 1)];
if (top)
neighbours.push(top);
if (right)
neighbours.push(right);
if (bottom)
neighbours.push(bottom);
if (left)
neighbours.push(left);
return neighbours;
}

this.focus = function () {
noStroke();
fill('blue');
let x = this.i * w;
let y = this.j * w;
rect(x, y, w, w);
}

this.show = function () {
let x = this.i * w;
let y = this.j * w;
stroke(51);
strokeWeight(5);
// strokeColor('black');
if (this.walls[0]) {
line(x, y, x, y + w);
}
if (this.walls[1]) {
line(x, y + w, x + w, y + w);
}
if (this.walls[2]) {
line(x + w, y + w, x + w, y);
}
if (this.walls[3]) {
line(x + w, y, x, y);
}
if (this.visited) {
noStroke();
fill(255, 255, 255, 100);
rect(x, y, w, w);
}
}
this.markVisited = function () {
fill('red');
rect(this.i * w, this.j * w, w, w);
this.visited = true;
}
this.connect = function (u) {
var value = this.index - u.index;
if (value == 1) {
this.walls[3] = false;
u.walls[1] = false;
}
if (value == -1) {
u.walls[3] = false;
this.walls[1] = false;
}
if (value == cols) {
this.walls[0] = false;
u.walls[2] = false;
}
if (value == -cols) {
u.walls[0] = false;
this.walls[2] = false;
}
}
}

function Index(i, j) {
if (i < 0 || j < 0 || i >= rows || j >= cols)
return -1;
return i * cols + j;
}
156 changes: 156 additions & 0 deletions Aldous-Broder/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
var w;
var size;
var rows;
var cols;
var grid=[];
var v;
var u;
var cnt=0;

function setup() {
size=400;
w=40;
createCanvas(size, size);
frameRate(20);
background(255, 204, 0);
rows = floor(size / w);
cols = floor(size / w);
for(let r=0;r<rows;r++)
{
for(let c=0;c<cols;c++)
{
var cell = new Cell(r,c);
grid.push(cell);
}
}
v=grid[0];
v.markVisited();
cnt++;
noLoop();
}

function draw() {
stroke(51);
noFill();
for(let i=0;i<grid.length;i++)
{
grid[i].show();
}
var current_neighbours=v.checkNeighbours();
var u=random(current_neighbours);
if(cnt!=rows*cols)
u.focus();
if(!u.visited)
{
v.connect(u);
u.markVisited();
cnt++;
}
v=u;
}



function Cell(i,j)
{
this.i=i;
this.j=j;
this.index=Index(i,j);
this.walls=[true,true,true,true];
this.visited=false;
this.parent=-1;
this.checkNeighbours=function()
{

var neighbours=[];
var top=grid[Index(i-1,j)];
var right=grid[Index(i,j+1)];
var bottom=grid[Index(i+1,j)];
var left=grid[Index(i,j-1)];
if(top)
neighbours.push(top);
if(right)
neighbours.push(right);
if(bottom)
neighbours.push(bottom);
if(left)
neighbours.push(left);
return neighbours;
}

this.focus=function()
{
noStroke();
fill('blue');
let x = this.i * w;
let y = this.j * w;
rect(x,y, w, w);
}

this.show = function()
{
let x = this.i * w;
let y = this.j * w;
stroke(51);
strokeWeight(5);
// strokeColor('black');
if(this.walls[0])
{
line(x,y,x,y+w);
}
if(this.walls[1])
{
line(x,y+w,x+w,y+w);
}
if(this.walls[2])
{
line(x+w,y+w,x+w,y);
}
if(this.walls[3])
{
line(x+w,y,x,y);
}
if (this.visited) {
noStroke();
fill(255, 255, 255, 100);
rect(x, y, w, w);
}
}
this.markVisited=function()
{
fill('red');
rect(this.i*w, this.j*w, w, w);
this.visited=true;
}
this.connect=function(u)
{
var value=this.index-u.index;
if(value==1)
{
this.walls[3]=false;
u.walls[1]=false;
}
if(value==-1)
{
u.walls[3]=false;
this.walls[1]=false;
}
if(value==cols)
{
this.walls[0]=false;
u.walls[2]=false;
}
if(value==-cols)
{
u.walls[0]=false;
this.walls[2]=false;
}
}
}

function Index(i,j)
{
if(i<0 || j<0 || i>=rows || j>=cols)
return -1;
return i*cols+j;
}
Loading

0 comments on commit 5da993a

Please sign in to comment.