From e35e39d2beb2c29461458e02f182758ece285583 Mon Sep 17 00:00:00 2001 From: acdesveaux <48537373+acdesveaux@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:54:22 -0400 Subject: [PATCH 1/2] project done! --- README.md | 64 ++------------ package.json | 17 ++++ public/css/style.css | 185 ++++++++++++++++++++++++++++++++++++++++ public/js/info.js | 23 +++++ public/js/main.js | 77 +++++++++++++++++ public/js/selectors.js | 38 +++++++++ public/views/index.html | 96 +++++++++++++++++++++ server.js | 25 ++++++ 8 files changed, 468 insertions(+), 57 deletions(-) create mode 100644 package.json create mode 100644 public/css/style.css create mode 100644 public/js/info.js create mode 100644 public/js/main.js create mode 100644 public/js/selectors.js create mode 100644 public/views/index.html create mode 100644 server.js diff --git a/README.md b/README.md index b61d3e2b..3ef9a5b4 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,9 @@ -Assignment 4 - Creative Coding: Interactive Multimedia Experiences -=== +Webware A4 - Creative Coding +Webware Paint - acdesveaux +https://a4-adam-desveaux.glitch.me/ -Due: October 11th, by 11:59 PM. +This webpage provides an application similar to microsoft paint, where users can paint a picture and then save it to their computer. Options include clearing the canvas, filling the canvas with the selected color, changing brush style and size, +uselecting from preset colors, or choosing your own color with an RGB color selector. The painted image can then be saved. This application was built using Canvas, and the parameters users can control are described above. Information +about functionality is shown in a popup when the page loads, and can be brought up again by clicking the link above the canvas. Both the HTML and CSS validate. I separated my javascript into three files for organization purposes. -For this assignment we will focus on client-side development using popular audio/graphics/visualization technologies; the server requirements are minimal. The goal of this assignment is to refine our JavaScript knowledge while exploring the multimedia capabilities of the browser. - -Baseline Requirements ---- - -Your application is required to implement the following functionalities: - -- A server created using Express. This server can be as simple as needed. -- A client-side interactive experience using at least one of the following web technologies frameworks. - - [Three.js](https://threejs.org/): A library for 3D graphics / VR experiences - - [D3.js](https://d3js.org): A library that is primarily used for interactive data visualizations - - [Canvas](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API): A 2D raster drawing API included in all modern browsers - - [SVG](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API): A 2D vector drawing framework that enables shapes to be defined via XML. - - [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API): An API for audio synthesis, analysis, processing, and file playback. -- A user interface for interaction with your project, which must expose at least six parameters for user control. [dat.gui](https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage) is highly recommended for this. You might also explore interaction by tracking mouse movement via the `window.onmousemove` event handler in tandem with the `event.clientX` and `event.clientY` properties. Consider using the [Pointer Events API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) to ensure that that mouse and touch events will both be supported in your app. -- Your application should display basic documentation for the user interface when the application first loads. This documentation should be dismissable, however, users should be able to redisplay it via either a help buton (this could, for example, be inside a dat.gui interface) or via a keyboard shortcut (commonly the question mark). -- Your HTML and CSS should validate. There are options/plugins for most IDEs to check validation. - -The interactive experience should possess a reasonable level of complexity. Some examples: -### Three.js -- A generative algorithm creates simple agents that move through a virtual world. Your interface controls the behavior / appearance of these agents. -- A simple 3D game -- An 3D audio visualization of a song of your choosing. User interaction should control aspects of the visualization. -### Canvas -- Implement a generative algorithm such as [Conway's Game of Life](https://bitstorm.org/gameoflife/) (or 1D cellular automata) and provide interactive controls. Note that the Game of Life has been created by 100s of people using ; we'll be checking to ensure that your implementation is not a copy of these. -- Design a 2D audio visualizer of a song of your choosing. User interaction should control visual aspects of the experience. -### Web Audio API -- Create a screen-based musical instrument using the Web Audio API. You can use projects such as [Interface.js](http://charlie-roberts.com/interface/) or [Nexus UI](https://nexus-js.github.io/ui/api/#Piano) to provide common musical interface elements, or use dat.GUI in combination with mouse/touch events (use the Pointer Events API). Your GUI should enable users to control aspects of sound synthesis. -### D3.js -- Create visualizations using the datasets found at [Awesome JSON Datasets](https://github.com/jdorfman/Awesome-JSON-Datasets). Experiment with providing different visualizations of the same data set, and providing users interactive control over visualization parameters and/or data filtering. Alternatively, create a single visualization with using one of the more complicated techniques shown at [d3js.org](d3js.org) and provide meaningful points of interaction for users. - -Deliverables ---- - -Do the following to complete this assignment: - -1. Implement your project with the above requirements. -3. Test your project to make sure that when someone goes to your main page on Glitch/Heroku/etc., it displays correctly. -4. Ensure that your project has the proper naming scheme `a4-firstname-lastname` so we can find it. -5. Fork this repository and modify the README to the specifications below. *NOTE: If you don't use Glitch for hosting (where we can see the files) then you must include all project files that you author in your repo for this assignment*. -6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a4-firstname-lastname`. - -Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions) ---- - -## Your Web Application Title - -your hosting link e.g. http://a4-charlieroberts.glitch.me - -Include a very brief summary of your project here. Images are encouraged when needed, along with concise, high-level text. Be sure to include: - -- the goal of the application -- challenges you faced in realizing the application -- the instructions you present in the website should be clear enough to use the application, but if you feel any need to provide additional instructions please do so here. +The main challenge I faced was learning all of the syntax and methods for canvas, and implementing many of these options on the webpage. Other than that the assignment was fairly straightforward. \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 00000000..71d11fef --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "a4-adam-desveaux", + "version": "1.0", + "description": "Webware Paint - A4", + "author": "acdesveaux", + "scripts": { + "start": "node server.js" + }, + "dependencies": { + "body-parser": "^1.19.0", + "compression": "1.7.4", + "express": "^4.17.1", + "helmet": "^4.1.1", + "semistandard": "^14.2.3", + "serve-static": "^1.14.1" + } +} diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 00000000..f41efbb4 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,185 @@ +* { + margin: 0; + padding: 0; +} + +section{ + padding-top: 20px; + padding-bottom: 20px; +} + +h2, p{ + margin: 0px auto; + width: 800px; + font-family: serif; +} + +h4{ + font-family: serif +} + +h2{ + color: #0F1FE5; +} + +canvas{ + display: block; + border: 1px solid black; + margin: 10px auto 0px; +} + +button{ + outline: 0; + border: 0; + color: #0F1FE5; + font-family: impact; + background: silver; + width: 40px; + height: 40px; + border-radius: 5px; + cursor: pointer; +} + +#tools{ + width: 800px; + height: 80px; + margin: 0px auto; + display: flex; +} + +#clearWrapper, #fillAndClear{ + display: flex; + flex-direction: column; + margin-right: 10px; +} + +#fillAndClear{ + margin-top: 19px; +} + +#clearWrapper button, #fillAndClear button{ + width: 80px; + height: 35px; + margin-bottom: 5px; +} + +#brushType, #sizes{ + display: flex; + width: 100px; + flex-wrap: wrap; +} + +#brushType button{ + margin-bottom: 5px; + margin-right: 5px; + height: 30px; + width: 42px; +} + +#sizes button{ + margin-bottom: 5px; + margin-right: 1px; + height: 30px; + width: 45px; +} + +#colors{ + height: 50px; + display: flex; + flex-direction: column; + margin-right: 10px; +} + +#currentColor{ + border: 1px solid silver; + cursor: pointer; + width: 40px; + height: 40px; + background: black; + margin-top:20px; +} + +#colors button{ + width: 20px; + height: 20px; + margin-top: 5px; + border: 1px solid silver; +} + +#colorSelect{ + visibility: hidden; +} + +#colors button:hover{ + opacity: 0.5; +} + +#red{ + background: red; +} + +#orange{ + background: orange; +} + +#yellow{ + background: yellow; +} + +#green{ + background: green; +} + +#blue{ + background: blue; +} +#indigo{ + background: indigo; +} + +#violet{ + background: violet; +} + +#black{ + background: black; +} + +#grey{ + background: grey; +} + +#white{ + background: white; +} + +#maroon{ + background: maroon; +} +#orangered{ + background: orangered; +} +#gold{ + background: gold; +} +#lime{ + background: lime; +} +#lightblue{ + background: lightblue; +} +#plum{ + background: plum; +} +#lavender{ + background: lavender; +} +#darkgrey{ + background: darkgrey; +} +#lightgrey{ + background: lightgrey; +} +#tan{ + background: tan; +} \ No newline at end of file diff --git a/public/js/info.js b/public/js/info.js new file mode 100644 index 00000000..422732fd --- /dev/null +++ b/public/js/info.js @@ -0,0 +1,23 @@ +function startup () { + window.alert('This app can be used to paint things. Functionality is outlined below\n' + + 'Save File: lets you save the canvas to your computer\n' + + 'Clear: clears the canvas\n' + + 'Fill: fills the canvas with the currently selected color\n' + + 'Brush Style: select either square or round brush\n' + + 'Brush Size: select a brush size - default is normal\n' + + 'Colors: either choose a preset color or select your own with the RGB selector on the right\n' + + 'Click and drag the mouse around the canvas to paint.'); +} + +function openInfo () { + window.alert('This app can be used to paint things. Functionality is outlined below\n' + + 'Save File: lets you save the canvas to your computer\n' + + 'Clear: clears the canvas\n' + + 'Fill: fills the canvas with the currently selected color\n' + + 'Brush Style: select either square or round brush\n' + + 'Brush Size: select a brush size - default is normal\n' + + 'Colors: either choose a preset color or select your own with the RGB selector on the right\n' + + 'Click and drag the mouse around the canvas to paint.'); +} + +export { openInfo, startup }; \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js new file mode 100644 index 00000000..36b94224 --- /dev/null +++ b/public/js/main.js @@ -0,0 +1,77 @@ +import { openInfo, startup } from './info.js'; +var canvas = document.getElementById('canvasArea'); +var context = canvas.getContext('2d'); +context.lineWidth = 5; +context.lineCap = 'round'; +var down = false; +var xPos; +var yPos; + +canvas.addEventListener('mousemove', draw); + +canvas.addEventListener('mousedown', function () { + down = true; + context.beginPath(); + context.moveTo(xPos, yPos); + canvas.addEventListener('mousemove', draw); +}); + +canvas.addEventListener('mouseup', function () { + down = false; +}); + +canvas.addEventListener('mouseleave', function () { + down = false; +}); + +function draw (e) { + xPos = e.clientX - canvas.offsetLeft; + yPos = e.clientY - canvas.offsetTop; + if (down === true) { + context.lineTo(xPos, yPos); + context.stroke(); + } +} + +function changeColor (color) { + context.strokeStyle = color; + context.fillStyle = color; + document.getElementById('currentColor').style.background = color; + document.getElementById('colorSelect').value = color; +} + +function clearCanvas () { + context.clearRect(0, 0, canvas.width, canvas.height); +} + +function changeBrushSize (size) { + context.lineWidth = size; +} + +function fillCanvas () { + context.fillRect(0, 0, canvas.width, canvas.height); +} + +function changeBrushStyle (brush) { + context.lineCap = brush; +} + +function customColor () { + var color = document.getElementById('colorSelect').value; + changeColor(color); +} + +function clickColor () { + document.getElementById('colorSelect').click(); +} + +function saveImage () { + var link = document.getElementById('link'); + link.setAttribute('download', 'webwaredrawing.png'); + link.setAttribute('href', document.getElementById('canvasArea').toDataURL('image/png').replace('image/png', 'image/octet-stream')); + link.click(); +} + +startup(); + +export {openInfo, clickColor, customColor, saveImage, changeBrushStyle, fillCanvas, changeBrushSize, clearCanvas, changeColor, draw }; \ No newline at end of file diff --git a/public/js/selectors.js b/public/js/selectors.js new file mode 100644 index 00000000..396462c1 --- /dev/null +++ b/public/js/selectors.js @@ -0,0 +1,38 @@ +import {openInfo, clickColor, customColor, saveImage, changeBrushStyle, fillCanvas, changeBrushSize, clearCanvas, changeColor } from './main.js'; + + +document.querySelector('#saveFile').addEventListener('click', saveImage); +document.querySelector('#clear').addEventListener('click', clearCanvas); +document.querySelector('#fillCanvas').addEventListener('click', fillCanvas); +document.querySelector('#fillCanvas').addEventListener('click', fillCanvas); +document.querySelector('#squareBrush').addEventListener('click', function () { changeBrushStyle('square'); }); +document.querySelector('#RoundBrush').addEventListener('click', function () { changeBrushStyle('round'); }); +document.querySelector('#brushSize1').addEventListener('click', function () { changeBrushSize(1); }); +document.querySelector('#brushSize2').addEventListener('click', function () { changeBrushSize(5); }); +document.querySelector('#brushSize3').addEventListener('click', function () { changeBrushSize(15); }); +document.querySelector('#brushSize4').addEventListener('click', function () { changeBrushSize(40); }); + +document.querySelector('#red').addEventListener('click', function () { changeColor('#ff0000'); }); +document.querySelector('#orange').addEventListener('click', function () { changeColor('#ffa500'); }); +document.querySelector('#yellow').addEventListener('click', function () { changeColor('#ffff00'); }); +document.querySelector('#green').addEventListener('click', function () { changeColor('#008000'); }); +document.querySelector('#blue').addEventListener('click', function () { changeColor('#0000ff'); }); +document.querySelector('#indigo').addEventListener('click', function () { changeColor('#4b0082'); }); +document.querySelector('#violet').addEventListener('click', function () { changeColor('#ee82ee'); }); +document.querySelector('#black').addEventListener('click', function () { changeColor('#000000'); }); +document.querySelector('#grey').addEventListener('click', function () { changeColor('#808080'); }); +document.querySelector('#white').addEventListener('click', function () { changeColor('#ffffff'); }); +document.querySelector('#maroon').addEventListener('click', function () { changeColor('#800000'); }); +document.querySelector('#orangered').addEventListener('click', function () { changeColor('#ff4500'); }); +document.querySelector('#gold').addEventListener('click', function () { changeColor('#ffd700'); }); +document.querySelector('#lime').addEventListener('click', function () { changeColor('#00ff00'); }); +document.querySelector('#lightblue').addEventListener('click', function () { changeColor('#add8e6'); }); +document.querySelector('#plum').addEventListener('click', function () { changeColor('#dda0dd'); }); +document.querySelector('#lavender').addEventListener('click', function () { changeColor('#e6e6fa'); }); +document.querySelector('#darkgrey').addEventListener('click', function () { changeColor('#a9a9a9'); }); +document.querySelector('#lightgrey').addEventListener('click', function () { changeColor('#d3d3d3'); }); +document.querySelector('#tan').addEventListener('click', function () { changeColor('#d2b48c'); }); + +document.querySelector('#currentColor').addEventListener('click', clickColor); +document.querySelector('#colorSelect').addEventListener('change', customColor); +document.querySelector('#info').addEventListener('click', openInfo); \ No newline at end of file diff --git a/public/views/index.html b/public/views/index.html new file mode 100644 index 00000000..bc958c7d --- /dev/null +++ b/public/views/index.html @@ -0,0 +1,96 @@ + + + + + Webware Paint + + + + + + + + + + +
+
+

+ Webware Paint +

+

+ Paint things below. + Click here for information on functionality. +

+
+
+

+ Tools +

+ +
+
+ + +
+
+

+ Brush Style +

+ + +
+
+

+ Brush Size +

+
+ + +
+
+ + +
+
+
+

+ Colors +

+
+ + + + + + + + + + +
+
+ + + + + + + + + + +
+
+
+ +
+ +
+ +
+ +
+ + + \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 00000000..408bbaf0 --- /dev/null +++ b/server.js @@ -0,0 +1,25 @@ +const express = require('express'); +const app = express(); +const helmet = require('helmet'); +const compression = require('compression'); +const path = require('path'); + +app.use(express.static('public')); +app.use(helmet()); +app.use(compression()); + +app.get('/', function (request, response) { + response.sendFile(path.join(__dirname, 'views/index.html')); +}); + +app.get('/public/js/scripts.js', function (request, response) { + response.sendFile(path.join(__dirname, '/public/js/scripts.js')); +}); + +app.get('/public/js/main.js', function (request, response) { + response.sendFile(path.join(__dirname, '/public/js/main.js')); +}); + +const listener = app.listen(process.env.PORT, function () { + console.log('Your app is listening on port ' + listener.address().port); +}); \ No newline at end of file From 8d672f9e654976b4d60f6a2d851202f4225d4494 Mon Sep 17 00:00:00 2001 From: acdesveaux <48537373+acdesveaux@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:54:35 -0400 Subject: [PATCH 2/2] package lock --- package-lock.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..9338a453 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "a4-adam-desveaux", + "version": "1.0", + "lockfileVersion": 1 +}