From c153eca50a1948bc5bb266072d07f2f28788e563 Mon Sep 17 00:00:00 2001 From: Errica Date: Mon, 4 Oct 2021 21:54:27 -0400 Subject: [PATCH 1/2] okay hopefully this one actually works --- .gitignore | 3 +++ README.md | 59 ++++++------------------------------------- public/function.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++ public/style.css | 63 ++++++++++++++++++++++++++++++++++++++++++++++ views/index.html | 39 ++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 51 deletions(-) create mode 100644 .gitignore create mode 100644 public/function.js create mode 100644 public/style.css create mode 100644 views/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f46f63d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.suo +\config +.vs \ No newline at end of file diff --git a/README.md b/README.md index 3ae10a92..c0e2bc4b 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,18 @@ Assignment 4 - Creative Coding: Interactive Multimedia Experiences === -Due: October 4th, by 11:59 AM. +## Color Swatch -For this assignment we will focus on client-side development using popular audio/graphics/visualization technologies. The goal of this assignment is to refine our JavaScript knowledge while exploring the multimedia capabilities of the browser. +Link: [linkhere](linkhere) -[WebAudio / Canvas / Three Tutorial](https://github.com/cs4241-21a/cs4241-21a.github.io/blob/main/webaudio_canvas_three.md) -[SVG + D3 tutorial](https://github.com/cs4241-21a/cs4241-21a.github.io/blob/main/using_svg_and_d3.md) +NOTE: The professor gave me an extension to work on this due to family business that came up over the weekend. -Baseline Requirements ---- +The goal of this application was to create a color picker with sliders that uses Canvas to display the color. This application can display both the RGBA and hex values (calculated in the Javascript end of things) of the color. I personally strongly prefer using RGBA sliders to pick my colors because of the way I initially learned light-based color theory, so I will definitely continue to use this tool in the future. -Your application is required to implement the following functionalities: +The inputs controlled by the user in this application include red, green, blue, and alpha values. -- 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 four parameters for user control. [tweakpane](https://cocopon.github.io/tweakpane/) is highly recommended for this, but you can also use regular HTML `` tags (the `range` type is useful to create sliders). 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 both 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. +I struggled for a while in getting the Canvas component to recognize the input color - initially, I was trying to use hexVal (the string containing the hex value), but for some reason that I still can't figure out, fillStyle would not read that particular string. Like a fool, I didn't think to use the console to diagnose my issue, so I chalked it up to the sliders not being read correctly for way too long. Once I realized the issue, however, I found a workaround by setting the fillStyle to a string that included the variables in RGB format. -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... you really want this to be a simple as possible or it will be outside the scope of this assignment. -- 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. If you want to use higher-level instruments instead of the raw WebAudio API sounds, consider trying the instruments provided by [Tone.js]() or [Gibber](https://github.com/charlieroberts/gibber.audio.lib). -### 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. +I had another issue for a while with reading the alpha value. It would only change when going to or from 0. In order to debug, I added several console statements, all of which printed correctly. I ended up moving a lot of code around to make it more effective and to see if that would fix things. In the end, it turned out that the alpha used 0-1, and I am just a complete buffoon. -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 usage of this website should be relatively straightforward: adjust the sliders labeled R, G, and B using your mouse. Alternatively, clicking on the corresponding slider and using the keyboard arrows is also accepted. \ No newline at end of file diff --git a/public/function.js b/public/function.js new file mode 100644 index 00000000..bec48a77 --- /dev/null +++ b/public/function.js @@ -0,0 +1,63 @@ +var body = document.body, + r = document.querySelector('#r'), + g = document.querySelector('#g'), + b = document.querySelector('#b'), + a = document.querySelector('#a'), + outputR = document.querySelector('#outputR'), + outputG = document.querySelector('#outputG'), + outputB = document.querySelector('#outputB'), + outputA = document.querySelector('#outputA'), + hexVal_out = document.querySelector('#hexVal'); + +const canvas = document.getElementById('canvas'); +const ctx = canvas.getContext('2d'); + +ctx.strokeStyle = 'rgb(42,42,42)'; +ctx.strokeRect(1, 1, 540, 300); +ctx.fillStyle = '#ffffffff'; +ctx.fillRect(1, 1, 540, 300); + +function setColor() { + ctx.fillStyle = '#ffffffff'; + ctx.fillRect(1, 1, 540, 300); + ctx.fillStyle = 'rgba(' + r.value + ',' + g.value + ',' + b.value + ',' + a.value/100 + ')'; + ctx.fillRect(1, 1, 540, 300); + hexVal_out.value = hexVal(); +} + +function hexVal() { + var r_hexVal = parseInt(r.value).toString(16), + g_hexVal = parseInt(g.value).toString(16), + b_hexVal = parseInt(b.value).toString(16), + a_hexVal = alphaMath(); + return '#' + pad(r_hexVal) + pad(g_hexVal) + pad(b_hexVal) + pad(a_hexVal); +} + +function alphaMath() { + var baseTen = parseInt(255 * parseInt(a.value) / 100); + return baseTen.toString(16); +} + +function pad(n) { + return (n.length < 2) ? '0' + n : n; +} + +r.addEventListener('input', function () { + setColor(); + outputR.value = r.value; +}, false); + +g.addEventListener('input', function () { + setColor(); + outputG.value = g.value; +}, false); + +b.addEventListener('input', function () { + setColor(); + outputB.value = b.value; +}, false); + +a.addEventListener('input', function () { + setColor(); + outputA.value = a.value; +}, false); \ No newline at end of file diff --git a/public/style.css b/public/style.css new file mode 100644 index 00000000..4daf1b4b --- /dev/null +++ b/public/style.css @@ -0,0 +1,63 @@ +body { + background-color: rgb(200,200,200); + padding: 40px; + margin: auto; + margin-top: 5%; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + max-width: 38em; + text-align: center; +} + +h1 { + font-size: 3em; +} + +fieldset { + border: none; +} + +output { + display: inline-block; + min-width: 2.5em; +} + +label, output { + padding: 2px 10px; + border-radius: 5px; + font-family: 'Roboto', sans-serif; + color: #000; + font-size: 1.1em; +} + +fieldset label, fieldset output { + min-width: 50px; + float: left; +} + +input[type=range] { + min-width: 360px; + background: black; +} + +label[for=r], output[for=r] { + background-color: #f00; +} + +label[for=g], output[for=g] { + background-color: #0f0; +} + +label[for=b], output[for=b] { + background-color: #00f; +} + +label[for=a], output[for=a] { + background-color: #fff; +} + +#hexVal { + margin-top: 25px; + min-width: 4.5em; + font-size: 3em; + background: rgba(255,255,255,.3); +} diff --git a/views/index.html b/views/index.html new file mode 100644 index 00000000..fb73036f --- /dev/null +++ b/views/index.html @@ -0,0 +1,39 @@ + + + + + Color Swatch - CS4241 A4 + + + + +

Color Swatch

+
+ + + 255

+ + + + 255

+ + + + 255

+ + + + 100

+
+ + #ffffffff

+ +
+ +
+ + + + + + \ No newline at end of file From 544d81b160b2ae51eb3ed2b63e8a89788c8cd727 Mon Sep 17 00:00:00 2001 From: Errica Date: Mon, 4 Oct 2021 21:59:59 -0400 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0e2bc4b..b23f3874 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Assignment 4 - Creative Coding: Interactive Multimedia Experiences ## Color Swatch -Link: [linkhere](linkhere) +Link: [https://a4-lockeanddemosthenes.glitch.me/](https://a4-lockeanddemosthenes.glitch.me/) NOTE: The professor gave me an extension to work on this due to family business that came up over the weekend. @@ -15,4 +15,4 @@ I struggled for a while in getting the Canvas component to recognize the input c I had another issue for a while with reading the alpha value. It would only change when going to or from 0. In order to debug, I added several console statements, all of which printed correctly. I ended up moving a lot of code around to make it more effective and to see if that would fix things. In the end, it turned out that the alpha used 0-1, and I am just a complete buffoon. -The usage of this website should be relatively straightforward: adjust the sliders labeled R, G, and B using your mouse. Alternatively, clicking on the corresponding slider and using the keyboard arrows is also accepted. \ No newline at end of file +The usage of this website should be relatively straightforward: adjust the sliders labeled R, G, and B using your mouse. Alternatively, clicking on the corresponding slider and using the keyboard arrows is also accepted.