diff --git a/README.md b/README.md index 7f170cdb2..6d09d5b9f 100755 --- a/README.md +++ b/README.md @@ -1,72 +1,13 @@ -Assignment 4 - Creative Coding: Interactive Multimedia Experiences -=== +###Technical Achievements### +While I did not complete this project, I found that I came incredibly close to implementing the 3d game of life algorithm. I made a decent module out of it for +further use. I chose this as an academic project and while I did not overly test it, I believe I came up with a decently fast algorithm for this project. -Due: September 27th, by 11:59 PM. +This project is lacking the second graphics module, and a proper front end. I do not pass the information gathered by the front end to the game module, +but that is the next implementation of this project. -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. +The goal of this application was to test my programming skills in the flavor of a systems project and then bring it to life with animation. +This is what I am fond of in CS. -Baseline Requirements ---- +I did not use a JS linter due to time constraints. -Your application is required to implement the following functionalities: - -- A server created using Express (you can also use an alternative server framework such as Koa) for basic file delivery and middleware. Your middleware stack should include the `compression` and `helmet` [middlewares]((https://expressjs.com/en/resources/middleware.html)) by default. You are not required to use Glitch for this assignment (but using Glitch is fine!); [Heroku](https://www.heroku.com) is another excellent option to explore. The course staff can't be resposible for helping with all other hosting options outside of Glitch, but some of us do have experience with other systems. It also never hurts to ask on Slack, as there's 99 other classmates who might have the experience you're looking for! -- A client-side interactive experience using at least one of the web technologies frameworks we discussed in class over the past week. - - [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 application should feature at least two different ES6 modules that you write ([read about ES6 modules](https://www.sitepoint.com/understanding-es6-modules/)) and include into a main JavaScript file. This means that you will need to author *at least three JavaScript files* (a `app.js` or `main.js` file and two modules). We'll discuss modules in class on Monday 9/23; for this assignment modules should contain at least two functions. -- You are required to use a linter for your JavaScript. There are plugins for most IDEs, however it will be difficult to run the linter directly in Glitch. If you haven't moved to developing on your personal laptop and then uploading to Glitch when your project is completed, this is the assignment to do so! -- 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-yourname` 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-gitname-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, along with concise, high-level text. Be sure to include: - -- the goal of the application -- challenges you faced in realizing the application -- a brief description of the JS linter you used and what rules it follows (we'll be looking at your JS files for consistency) - -## Technical Achievements -- **Tech Achievement 1**: I wrote my own custom GLSL shaders to use as a material for my Three.js objects. -- **Tech Achievement 2**: My audiovisualizer uses both FFT and amplitude analysis to drive visualization. -- **Tech Achievement 3**: I optimized the efficiency of my reaction-diffusion algorithm by... -- **Tech Achievement 4**: I visualized the dataset X using three different visualization technqiues provided by D3, andprovided - -### Design/Evaluation Achievements -- **Design Achievement 1**: I ensured that my application would run on both desktops / mobile devices by changing X -- **Design Achievement 2**: I followed best practices for accessibility, including providing alt attributes for images and using semantic HTML. There are no `
` or `` elements in my document. -- **Design Achievement 3**: We tested the application with n=X users, finding that... +Glitch: https://glitch.com/~tweedchristian-a4-creativecoding \ No newline at end of file diff --git a/gameoflife.js b/gameoflife.js new file mode 100644 index 000000000..eb5fd131c --- /dev/null +++ b/gameoflife.js @@ -0,0 +1,235 @@ + +/**A function that takes a string and sees if it is 'loosely' + * formatted correctly + * Note: it cannot see if the amount of coordinates is correct, + * nor can it check to see if a paretheses is put too early **/ +const validateInput = function(input) { + let errorFound, errorMessage; + if (/[a-zA-Z!@#$%^&*~`/.:;_+=]/.test(input)) { + errorFound = 1; + errorMessage = "Invalid characters present"; + } + else { + errorFound = 0; + errorMessage = 'valid expression'; + } + let a = { + error: errorFound, + message: errorMessage + }; + return a; +} + + +/**Runs an entire generation and returns a results object + * which contains information about all the events of the + * generation **/ +const evolve = function(rules, cells) { + let el = rules[0]; + let eu = rules[1]; + let fl = rules[2]; + let fu = rules[3]; + + let newCells = []; + let count; + let tempCells = []; + let deadCells = 0; + let birthedCells = 0; + let unchangedCells = 0; + /**Counting the neighbors for each cell **/ + for (let i = 0; i < cells.length; i++) { + count = countNeighbors(cells, cells[i]); + if (count >= el && count <= eu) { + newCells.push(cells[i]); + unchangedCells++; + } + else { + deadCells++; + } + } + + /**Going through all neighboring empty cells and counting their neighbors **/ + + for (let i = 0; i < cells.length; i++) { + //Generate a list of neighboring cells + tempCells = generate(cells[i]); + for (let j = 0; j < tempCells.length; j++) { + //Checking if the cell is empty + if(owns(cells, tempCells[j])){ + //do nothing + } + else { + count = countNeighbors(cells, tempCells[j]); + if (count >= fl && count <= fu) { + newCells.push(tempCells[j]); + birthedCells++; + } + else { + //Do nothing + } + } + } + } + let results = { + nextGen: newCells, + deaths: deadCells, + births: birthedCells, + sustains: unchangedCells + }; + return results; +} + + +//A function that checks the array of cells and +//counts the number of neighbors of a single point +function countNeighbors(cells, cell) { + let count = 0; + let cellCheck = generate(cell); + //Check a wide array of neighbors + for (let i = 0; i < cells.length; i++) { + for (let j = 0; j < cellCheck.length; j++) { + if (equate(cells[i], cellCheck[j])) { + count++; + } + } + } + return count; +} + +//An array of coordinates where if added to a single cell, +//generates the coordinates of all the cells of that neighbor +let neighCoords = [ + //Top layer + [0, 1, 0], + [0, 1, 1], + [0, 1, -1], + [1, 1, 0], + [-1, 1, 0], + [1, 1, 1], + [-1, 1, 1], + [1, 1, -1], + [-1, 1, -1], + //Middle Layer + [1, 0, 0], + [-1, 0, 0], + [0, 0, 1], + [0, 0, -1], + [1, 0, 1], + [1, 0, -1], + [-1, 0, 1], + [-1, 0, -1], + //Bottom Layer + [0, -1, 0], + [0, -1, -1], + [0, -1, 1], + [1, -1, 0], + [-1, -1, 0], + [-1, -1, -1], + [-1, -1, 1], + [1, -1, 1], + [1, -1, -1] +]; + +//A simple barebones add function for xyz coordinates +function add(a, b) { + let c = []; + c.push(a[0] + b[0]); + c.push(a[1] + b[1]); + c.push(a[2] + b[2]); + return c; +} + +//Checking to see if two cells are equal +function equate(a, b) { + let truth = true; + //This could be reduced to a single line, but + //I did this for the sake of readability + if (a[0] !== b[0]) { + truth = false + } + else if (a[1] !== b[1]) { + truth = false; + } + else if (a[2] !== b[2]) { + truth = false; + } + return truth; +} + + +//A function that takes a cell and generates all of the neighboring coordinates for an individual +//cell +function generate(a) { + let checkCells = []; + for (let i = 0; i < neighCoords.length; i++) { + checkCells.push(add(a, neighCoords[i])); + } + return checkCells; +} + +//Checking to see if a certain cell is in the list of cells +function owns(cells, a) { + let result = false; + for (let i = 0; i < cells.length; i++) { + if (equate(cells[i], a)) { + result = true; + } + } +} + +/**Generates an array of cells based on json passed in**/ +function getCells(string) { + let points = []; + let loc = 0; + let a = { errorMessage: '', errorFound: 0 }; + let invalidChars = validateInput(string); + if (invalidChars.errorFound == 1) { + a = invalidChars; + } + while (string.indexOf("(", loc) !== -1 && a.errorFound === 0) { + + let first = string.indexOf("(", loc); + let second = string.indexOf(")", first + 1); + + let coord = string.substr(first + 1, second - first - 1); + + //Empty String + if (coord.length === 0) { + a.errorFound = 1; + a.errorMessage = "Empty String"; + } + let coordArray = JSON.parse("[" + coord + "]"); + //Checking for proper length + //I'm not sure whether or not this checks against all invalid input + //But I'm sure it covers a lot of cases. + if (coordArray.length !== 3) { + a.errorFound = 1; + a.errorMessage = "Incorrect amount of coordinates"; + } + + loc = second + 1; //Make sure not to infinitely loop + + if (a.errorFound === 0) { + points.push(coordArray); + } + } + if (a.errorFound === 1) { + //This is going to be type checked to adjust response header/body + return a; + } + else { + //This will be processed into graphics data + return points; + } +} + +const test = function(a){ + console.log(a); +} + +//Module to be exported, generate and getCells only. + + +exports.test = test => (console.log(test)); +exports.charCheck = input => validateInput(input); +exports.generate = (rules, cells) => evolve(rules, cells); \ No newline at end of file diff --git a/graphics.js b/graphics.js new file mode 100644 index 000000000..d8d1328db --- /dev/null +++ b/graphics.js @@ -0,0 +1,13 @@ +import * as THREE from 'three'; + + + +/**This module reads the data passed to it and generates a graphics output**/ + + + +/**Set scene**/ + + + +/**Render**/ \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 000000000..fbf2beced --- /dev/null +++ b/index.html @@ -0,0 +1,91 @@ + + + + + CS4241 Assignment 4 + + + + + + + +

3D Game of Life


+ +
+ +

This is an implementation of Conway's famous game of life extrapolated into 3D. + The entire game operates under a rule set that may be formalized as a tuple (shown below). The equations below + are the formalizaiton of the game of life + projected to 3d. Where E and F are the respective rule sets for living + cells and the non-filled cells. The respective L and U variables indicate the bounds for the count of neighbors + to either sustain a generation + or populate the non-filled cell. E and F are the count of numbers for an individual cell. +

+

For example, Conway's game of life can be represented as {2,3,3,3}
+ Notable, the two rule sets that generate a comparable game of life that is not infinitely expansive, and + posseses gliders are:

+

{4,6,6,6} and {}

+

El, Eu, Fl, Fu
+ El ≤ E ≤ Eu
+ Fl ≤ F ≤ Fu
+

+ +
+ El: + Eu: + Fl: + Fu: + Frames: +
+
+ Points: + +
+ + + \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 000000000..9cee0b175 --- /dev/null +++ b/server.js @@ -0,0 +1,27 @@ +const express = require('express'), + app = express(), + bodyParser = require('body-parser'), + helmet = require('helmet'), + compression = require('compression'), + game = require('./gameoflife.js'); + + app.use(helmet()); + app.use(compression()); + + //Safety precautions from helmet + app.use(helmet.xssFilter()); + app.use(helmet.frameguard()); + + app.use(bodyParser.json()); + app.use(express.static('./')); + + app.post('/submit', function(req, res){ + console.log(req.body); + res.status(200).send('haha lmoa'); + }); + + + console.log(game.charCheck("{(1,2,3)}")); + console.log(game.generate([1,2,0,1], [[0,0,0], [1,1,1]])); + +app.listen(3000); diff --git a/style.css b/style.css new file mode 100644 index 000000000..36694201e --- /dev/null +++ b/style.css @@ -0,0 +1,24 @@ + +#canvas{ + display: flex; + align-self: center; + align-content: center; + align-items: center; + justify-self: center; + width: 600px; + height: 600px; + background-color: blueviolet; + border: 2px; + border-color: darkred; +} + +#description{ + display: flex; + flex-wrap: wrap; + align-self: center; +} + +#title{ + display: flex; + justify-content: center; +} \ No newline at end of file