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

a4-errica-cheng #38

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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.suo
\config
.vs
59 changes: 8 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -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: [https://a4-lockeanddemosthenes.glitch.me/](https://a4-lockeanddemosthenes.glitch.me/)

[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 `<input>` 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 <canvas>; 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.
63 changes: 63 additions & 0 deletions public/function.js
Original file line number Diff line number Diff line change
@@ -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);
63 changes: 63 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
@@ -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);
}
39 changes: 39 additions & 0 deletions views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Color Swatch - CS4241 A4</title>
<link rel="stylesheet" href="../public/style.css" />
</head>

<body>
<h1>Color Swatch</h1>
<fieldset>
<label for="r">R</label>
<input type="range" min="0" max="255" id="r" step="1" value="255">
<output for="r" id="outputR">255</output><br /><br />

<label for="g">G</label>
<input type="range" min="0" max="255" id="g" step="1" value="255">
<output for="g" id="outputG">255</output><br /><br />

<label for="b">B</label>
<input type="range" min="0" max="255" id="b" step="1" value="255">
<output for="b" id="outputB">255</output><br /><br />

<label for="a">A</label>
<input type="range" min="0" max="100" id="a" step="1" value="100">
<output for="a" id="outputA">100</output><br /><br />
</fieldset>

<output id="hexVal">#ffffffff</output><br /><br />

<fieldset>
<canvas id="canvas" height="325" width="580"></canvas>
</fieldset>

<script src="../public/function.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tweakpane.min.js"></script>

</body>
</html>