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

Made some Adjustments #42

Open
wants to merge 2 commits into
base: main
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
node_modules
File renamed without changes.
33 changes: 4 additions & 29 deletions sketch.js → board/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ let tiles = [];
const tileImages = [];

let grid = [];

const DIM = 25;
const DIM = 15;

function preload() {
// const path = 'rail';
// for (let i = 0; i < 7; i++) {
// tileImages[i] = loadImage(`${path}/tile${i}.png`);
// }

const path = 'tiles/circuit-coding-train';
const path = 'tiles/circuit';
for (let i = 0; i < 13; i++) {
tileImages[i] = loadImage(`${path}/${i}.png`);
}
Expand All @@ -28,15 +22,6 @@ function removeDuplicatedTiles(tiles) {

function setup() {
createCanvas(400, 400);
//randomSeed(15);

// tiles[0] = new Tile(tileImages[0], ['AAA', 'AAA', 'AAA', 'AAA']);
// tiles[1] = new Tile(tileImages[1], ['ABA', 'ABA', 'ABA', 'AAA']);
// tiles[2] = new Tile(tileImages[2], ['BAA', 'AAB', 'AAA', 'AAA']);
// tiles[3] = new Tile(tileImages[3], ['BAA', 'AAA', 'AAB', 'AAA']);
// tiles[4] = new Tile(tileImages[4], ['ABA', 'ABA', 'AAA', 'AAA']);
// tiles[5] = new Tile(tileImages[5], ['ABA', 'AAA', 'ABA', 'AAA']);
// tiles[6] = new Tile(tileImages[6], ['ABA', 'ABA', 'ABA', 'ABA']);

// Loaded and created the tiles
tiles[0] = new Tile(tileImages[0], ['AAA', 'AAA', 'AAA', 'AAA']);
Expand Down Expand Up @@ -66,8 +51,7 @@ function setup() {
tempTiles = removeDuplicatedTiles(tempTiles);
tiles = tiles.concat(tempTiles);
}
console.log(tiles.length);


// Generate the adjacency rules based on edges
for (let i = 0; i < tiles.length; i++) {
const tile = tiles[i];
Expand All @@ -85,7 +69,6 @@ function startOver() {
}

function checkValid(arr, valid) {
//console.log(arr, valid);
for (let i = arr.length - 1; i >= 0; i--) {
// VALID: [BLANK, RIGHT]
// ARR: [BLANK, UP, RIGHT, DOWN, LEFT]
Expand All @@ -96,12 +79,6 @@ function checkValid(arr, valid) {
arr.splice(i, 1);
}
}
// console.log(arr);
// console.log("----------");
}

function mousePressed() {
redraw();
}

function draw() {
Expand All @@ -126,9 +103,7 @@ function draw() {
// Pick cell with least entropy
let gridCopy = grid.slice();
gridCopy = gridCopy.filter((a) => !a.collapsed);
// console.table(grid);
// console.table(gridCopy);


if (gridCopy.length == 0) {
return;
}
Expand Down
File renamed without changes.
16 changes: 11 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<script src="./tiles/p5.js"></script>
<meta charset="utf-8" />
<title>Wave Function Collapse</title>
<style>
body {
background-color: #555;
background-repeat: no-repeat;
background: linear-gradient(to bottom right, #33c5ff 0%, #3366ff 100%);
background-attachment: fixed;
}
canvas{
display: block;
margin: auto;
}
</style>
</head>

<body>
<main></main>
<script src="tile.js"></script>
<script src="cell.js"></script>
<script src="sketch.js"></script>
<script src="./board/tile.js"></script>
<script src="./board/cell.js"></script>
<script src="./board/sketch.js"></script>
</body>
</html>
53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const fs = require('fs');
const http = require('http');
const path = require('path');

var mimeTypes = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.wav': 'audio/wav',
'.mp4': 'video/mp4',
'.woff': 'application/font-woff',
'.ttf': 'application/font-ttf',
'.eot': 'application/vnd.ms-fontobject',
'.otf': 'application/font-otf',
'.wasm': 'application/wasm'
};

const server = http.createServer((req,res)=>{

var filePath = '.' + req.url;
if (filePath == './') {
filePath = './index.html';
}

var extname = String(path.extname(filePath)).toLowerCase();
var contentType = mimeTypes[extname] || 'application/octet-stream';

fs.readFile(filePath, function(error, content) {
if (error) {
if(error.code == 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
}
else {
res.writeHead(500);
res.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
}
}
else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
});
});

const PORT = 8000;

server.listen(PORT,()=>console.log(`Listening on PORT : ${PORT}`))
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "wave-function-collapse",
"version": "1.0.0",
"description": "Wave Function Collapse",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/DarkMortal/Wave-Function-Collapse.git"
},
"keywords": [
"Wave",
"Function",
"Collapse"
],
"author": "Saptarshi Dey,The Coding Train contributors",
"license": "MIT",
"bugs": {
"url": "https://github.com/DarkMortal/Wave-Function-Collapse/issues"
},
"homepage": "https://github.com/DarkMortal/Wave-Function-Collapse#readme"
}
Loading