diff --git a/Blastar HTML/blastar.PNG b/Blastar HTML/blastar.PNG new file mode 100644 index 0000000..6c00cbd Binary files /dev/null and b/Blastar HTML/blastar.PNG differ diff --git a/Blastar HTML/css/CommodorePixelized.ttf b/Blastar HTML/css/CommodorePixelized.ttf new file mode 100644 index 0000000..6bf582a Binary files /dev/null and b/Blastar HTML/css/CommodorePixelized.ttf differ diff --git a/Blastar HTML/css/style.css b/Blastar HTML/css/style.css new file mode 100644 index 0000000..10c43e9 --- /dev/null +++ b/Blastar HTML/css/style.css @@ -0,0 +1,45 @@ +@font-face { + font-family: 'Commodore'; + src: url('CommodorePixelized.ttf'); +} +body { + font-family: 'Verdana'; + text-align: center; + color: #BBB; +} +canvas { + font-size: 24px; +} +h1 { + font-family: 'Commodore'; +} +a:link { + color: #888888; +} +a:visited { + color: #666666; +} +a:active { + color: #DDDDDD; +} +td { + text-align: center; + -webkit-touch-callout: none; + -webkit-user-select: none; +} +div { + width: 750px; + margin: 0 auto; +} +input[type=button] { + height: 120px; + width: 120px; + font-size: 200%; + box-sizing: content-box; + -moz-box-sizing: content-box; + -ms-box-sizing: content-box; + -webkit-box-sizing: content-box; +} +input#spcbar { + width: 250px; +} diff --git a/Blastar HTML/img/blastar0.ico b/Blastar HTML/img/blastar0.ico new file mode 100644 index 0000000..725ac06 Binary files /dev/null and b/Blastar HTML/img/blastar0.ico differ diff --git a/Blastar HTML/img/blastar1.ico b/Blastar HTML/img/blastar1.ico new file mode 100644 index 0000000..5a3beec Binary files /dev/null and b/Blastar HTML/img/blastar1.ico differ diff --git a/Blastar HTML/img/blastar2.ico b/Blastar HTML/img/blastar2.ico new file mode 100644 index 0000000..7961d61 Binary files /dev/null and b/Blastar HTML/img/blastar2.ico differ diff --git a/Blastar HTML/img/blastar3.ico b/Blastar HTML/img/blastar3.ico new file mode 100644 index 0000000..ef896c6 Binary files /dev/null and b/Blastar HTML/img/blastar3.ico differ diff --git a/Blastar HTML/img/blastar4.ico b/Blastar HTML/img/blastar4.ico new file mode 100644 index 0000000..3990b88 Binary files /dev/null and b/Blastar HTML/img/blastar4.ico differ diff --git a/Blastar HTML/img/blastar5.ico b/Blastar HTML/img/blastar5.ico new file mode 100644 index 0000000..8ce984f Binary files /dev/null and b/Blastar HTML/img/blastar5.ico differ diff --git a/Blastar HTML/img/dragon.png b/Blastar HTML/img/dragon.png new file mode 100644 index 0000000..e979f50 Binary files /dev/null and b/Blastar HTML/img/dragon.png differ diff --git a/Blastar HTML/index.html b/Blastar HTML/index.html new file mode 100644 index 0000000..c3fbe7f --- /dev/null +++ b/Blastar HTML/index.html @@ -0,0 +1,692 @@ + + +Blastar for HTML5: a web version of Elon Musk's 1984 video game + + + + +
+

Blastar for HTML5

+ + + + + + + +
+[YOUR BROWSER IS NOT SUPPORTED] +
+

+
+ +


+ +

+
+

 

+

Instructions for the web version

+
Use the arrow keys to move your ship and the space bar to shoot.
+
+ diff --git a/lights-out/LICENSE b/lights-out/LICENSE new file mode 100644 index 0000000..428efc7 --- /dev/null +++ b/lights-out/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Tayllan Búrigo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/lights-out/LightsOut.pdf b/lights-out/LightsOut.pdf new file mode 100644 index 0000000..c5264bb Binary files /dev/null and b/lights-out/LightsOut.pdf differ diff --git a/lights-out/README.md b/lights-out/README.md new file mode 100644 index 0000000..209cb36 --- /dev/null +++ b/lights-out/README.md @@ -0,0 +1,3 @@ +# Lights Out + +A JavaScript implementation of the game [Lights Out](https://en.wikipedia.org/wiki/Lights_Out_(game)) as a way to apply/learn Linear Algebra: [Lights Out: Solutions Using Linear Algebra](http://cau.ac.kr/~mhhgtx/courses/LinearAlgebra/references/MadsenLightsOut.pdf). \ No newline at end of file diff --git a/lights-out/favicon.ico b/lights-out/favicon.ico new file mode 100644 index 0000000..a592951 Binary files /dev/null and b/lights-out/favicon.ico differ diff --git a/lights-out/index.html b/lights-out/index.html new file mode 100644 index 0000000..c7c3542 --- /dev/null +++ b/lights-out/index.html @@ -0,0 +1,67 @@ + + + + + + Lights Out + + + + + +
+ + + + +
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Rules + + + \ No newline at end of file diff --git a/lights-out/main.css b/lights-out/main.css new file mode 100644 index 0000000..4290c00 --- /dev/null +++ b/lights-out/main.css @@ -0,0 +1,59 @@ +@font-face { + font-family: "Lato", Helvetica, Arial, sans-serif; + } +body { + font-family:'Roboto Mono'; + text-align: center; +} + +.row div { + display: inline-block; + height: 40px; + width: 40px; + background-color: rgb(223, 223, 223); + border: 5px solid white; +} + +.row div:hover { + cursor: pointer; +} + +.row div.yellow { + border: 5px solid yellow; +} + +.on { + background-color: rgb(66, 184, 221) !important; +} + +.not-show { + display: none; +} + +button { + font-family: 'Roboto Mono'; + font-size: 100%; + padding: 0.5em 1em; + border: none; + text-decoration: none; + cursor: pointer; + color: white; + border-radius: 4px; + text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2); +} + +#shuffle { + background-color: rgb(242, 207, 7); +} + +#solve { + background-color: rgb(2, 141, 247); +} + +#hide { + background-color: rgb(4, 206, 242); +} + +a { + font-size: 150%; +} \ No newline at end of file diff --git a/lights-out/main.js b/lights-out/main.js new file mode 100644 index 0000000..e6f9ccc --- /dev/null +++ b/lights-out/main.js @@ -0,0 +1,244 @@ +(function() { + 'use strict'; + + // removing Magic Numbers + // Zero and One from GaloisField(2) + var zero = 0; + var one = 1; + var A = [ + [ one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [ one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, one, one, zero, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [ one, zero, zero, zero, zero, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, one, zero, zero, zero, one, one, zero, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, one, zero, zero, zero, zero, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, zero, zero, zero, zero, one, zero, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, zero, one, one, zero, zero, zero, one, zero, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero, zero, one, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, zero, zero, zero, zero, one], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, zero, one, one, zero, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one, zero], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one, one], + [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, one, zero, zero, zero, one, one] + ]; + var n1 = [zero, one, one, one, zero, one, zero, one, zero, one, one, one, zero, one, one, one, zero, one, zero, one, zero, one, one, one, zero]; + var n2 = [ one, zero, one, zero, one, one, zero, one, zero, one, zero, zero, zero, zero, zero, one, zero, one, zero, one, one, zero, one, zero, one]; + var hide = document.getElementById('hide'); + var obj = document.querySelectorAll('.row div'); + var cells = []; + + for (var key in obj) { + if (obj.hasOwnProperty(key) && key !== 'length') { + cells.push(obj[key]); + } + } + + var deepCopyMatrix = function(M) { + return M.map(function(row) { + return row.slice(); + }); + }; + var sumGF2 = function(a, b) { + return (a !== b) ? one : zero; + }; + var multGF2 = function(a, b) { + return a * b; + }; + var divGF2 = function(a, b) { + if (b === zero) { + console.log('Trying to divide by zero!'); + } + return a; + }; + var dotProduct = function(v1, v2) { + return v1.map(function(e, index) { + return multGF2(e, v2[index]); + }).reduce(function(a, b) { + return sumGF2(a, b); + }, 0); + }; + + // Returns the Reduce Row Echelon Form representation of the M matrix + var rref = function(M) { + var N = deepCopyMatrix(M); + var lead = 0; + var rowCount = N.length; + var columnCount = N[0].length; + + for (var r = 0; r < rowCount; r++) { + if (lead >= columnCount) { + return N; + } + i = r; + while (N[i][lead] === zero) { + i += 1; + if (i === rowCount) { + i = r; + lead += 1; + if (columnCount === lead) { + return N; + } + } + } + var aux = N[i].slice(); + N[i] = N[r].slice(); + N[r] = aux; + var lv = N[r][lead]; + N[r] = N[r].map(function(e) { + return divGF2(e, lv) + }); + for (var i = 0; i < rowCount; i++) { + if (i !== r) { + lv = N[i][lead]; + N[i] = N[i].map(function(e, index) { + return sumGF2( + e, + multGF2(lv, N[r][index]) + ) + }); + } + } + lead += 1; + } + return N; + }; + var getRandomGF2Array = function() { + var length = A.length; + var arr = []; + + for (var i = 0; i < length; i++) { + arr.push(Math.floor(Math.random() * 2)); + } + return arr; + }; + var getRandomState = function() { + var b = getRandomGF2Array(); + + // checking for Orthogonality for (b, n1) and (b, n2) so that b is a winnable state + while (dotProduct(b, n1) !== zero || dotProduct(b, n2) !== zero) { + b = getRandomGF2Array(); + } + return b; + }; + var hasWon = function() { + return document.querySelector('.on') === null; + }; + var getCurrentState = function() { + var obj = document.querySelectorAll('.on'); + var b = [zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero]; + + for (var key in obj) { + if (obj.hasOwnProperty(key) && key !== 'length') { + b[obj[key].id - 1] = one; + } + } + + return b; + }; + var getSolution = function(b) { + var B = deepCopyMatrix(A); + + for (var i = b.length - 1; i >= 0; i--) { + B[i].push(b[i]); + } + + B = rref(B); + + return B.map(function(row, index) { + return row[row.length - 1]; + }); + }; + + document.getElementById('shuffle').addEventListener('click', function(event) { + var b = getRandomState(); + for (var i = b.length - 1; i >= 0; i--) { + var element = document.getElementById(i + 1); + if (b[i] === one) { + element.className = 'on'; + } + else { + element.className = ''; + } + } + + hide.className = 'not-show'; + }); + + document.getElementById('solve').addEventListener('click', function(event) { + var b = getCurrentState(); + var x = getSolution(b); + + x.forEach(function(e, index) { + if (e === one) { + var element = document.getElementById(index + 1); + element.classList.add('yellow'); + element.classList.add('solver'); + } + }); + + hide.className = ''; + }); + + hide.addEventListener('click', function(event) { + this.className = 'not-show'; + + cells.forEach(function(e, i) { + e.classList.remove('yellow'); + e.classList.remove('solver'); + }); + }); + + cells.forEach(function(e, i) { + e.addEventListener('click', function(event) { + var aux = parseInt(this.id, 10); + var toSwitch = [aux, aux - 5, aux + 5]; + + if (aux % 5 !== 0) { + toSwitch.push(aux + 1); + } + if (aux % 5 !== 1) { + toSwitch.push(aux - 1); + } + + if (this.classList.contains('yellow')) { + this.classList.remove('yellow'); + } + else if (this.classList.contains('solver')) { + this.classList.add('yellow'); + } + + for (var i = toSwitch.length - 1; i >= 0; i--) { + if (toSwitch[i] > 0 && toSwitch[i] <= A.length) { + var element = document.getElementById(toSwitch[i]); + + if (element.classList.contains('on')) { + element.classList.remove('on'); + } + else { + element.classList.add('on'); + } + } + } + + if (hasWon()) { + alert('Congratulations, You Win!!'); + + cells.forEach(function(e, i) { + e.className = ''; + hide.className = 'not-show'; + }); + } + }); + }); +})(); \ No newline at end of file