Created
May 27, 2022 15:48
-
-
Save shawnco/703e2207ba454954c01bce787ba575d3 to your computer and use it in GitHub Desktop.
Collaborative Drawing App files as of article 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Collaborative Drawing App</title> | |
<style type="text/css"> | |
canvas { | |
border: 1px solid black; | |
} | |
.palette { | |
border: 1px solid black; | |
display: inline-block; | |
margin: 2px; | |
height: 25px; | |
width: 25px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Collaborative Drawing App</h1> | |
<div> | |
<canvas id="canvas" height="500px" width="500px"></canvas><br /> | |
</div> | |
<div id="palette"> | |
<div id="row-1"> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
</div> | |
<div id="row-2"> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
<div class="palette"></div> | |
</div> | |
</div> | |
<script type="text/javascript" src="./script.js"></script> | |
<script type="text/javascript"> | |
const canvas = new Canvas(); | |
const palette = new Palette(); | |
palette.draw(); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const path = require('path'); | |
const PORT = 3000; | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(express.static(path.join(__dirname + '/../client'))); | |
app.get('/script.js', (req, res) => { | |
res.sendFile(path.join(__dirname + '/../client/script.js')); | |
}); | |
app.get('/api/test', (req, res) => { | |
res.end('Test works!'); | |
}); | |
app.listen(PORT, () => { | |
console.log(`App is live on port ${PORT}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Canvas { | |
constructor() { | |
this.canvas = document.querySelector('#canvas'); | |
this.ctx = this.canvas.getContext('2d'); | |
} | |
} | |
class Palette { | |
constructor() { | |
this.colors = [ | |
['#000000', '#FFFFFF', '#7F7F7F', '#C3C3C3', '#880015', '#B97A57', '#ED1C24', '#FFAEC9', '#FF7F27', '#FFC90E'], | |
['#FFF200', '#EFE4B0', '#22B14C', '#B5E61D', '#00A2E8', '#99D9EA', '#3F48CC', '#7092BE', '#A349A4', '#C8BFE7'] | |
]; | |
} | |
draw() { | |
const row1 = document.querySelectorAll('#row-1 .palette'); | |
const row2 = document.querySelectorAll('#row-2 .palette'); | |
row1.forEach((div, idx) => { | |
div.style.backgroundColor = this.colors[0][idx]; | |
}); | |
row2.forEach((div, idx) => { | |
div.style.backgroundColor = this.colors[1][idx]; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment