This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x=0,y=0,tx=0,ty=0,r=150,a=0; //States | |
let context = new AudioContext(); //Audio context | |
let times = new Uint8Array(360); //Typed array to hold only 360 items | |
let canvas = document.createElement('canvas'); //Create the canvas | |
let ctx = canvas.getContext('2d'); | |
ctx.fillStyle = 'black'; | |
document.body.appendChild(canvas); | |
document.body.style.margin = '0px'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create the canvas and get the WebGlRederingContext | |
let ctx = document.createElement('canvas') | |
let gl = ctx.getContext('webgl') | |
document.body.appendChild(ctx) | |
ctx.width = 600 | |
ctx.height = 600 | |
gl.viewport(0, 0, 600, 600) | |
gl.clearColor(0.0, 0.0, 0.0, 1.0) | |
//Vertex Shader steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Only work with primitives values | |
const isEqualToAny = (input, items = []) => { | |
let result = false | |
items.map(i => !result && (result = i === input)) | |
return result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KeyListener { | |
constructor(obj ,element = window){ | |
element.addEventListener('keyup', this.keyUp.bind(this), false); | |
element.addEventListener('keydown', this.keyDown.bind(this), false); | |
this.elememt = element | |
this.keys = {} | |
for(let key in obj){ | |
this.keys[key] = { | |
isDown:false, | |
press:obj[key].press, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tinyTimer = (function () { | |
const timers = [] | |
function update() { | |
const time = performance.now() | |
let i = 0 | |
while (i < timers.length) { | |
let timer = timers[i] | |
if (time > timer.start + timer.duration) { | |
timer.callback() | |
timers.splice(i, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BooleanicKeys { | |
constructor(obj, element = window) { | |
element.addEventListener('keyup', this.keyUp.bind(this), false); | |
element.addEventListener('keydown', this.keyDown.bind(this), false); | |
this.elememt = element | |
this.keys = {} | |
for (let key in obj) { | |
this.keys[key] = { | |
isDown: false, | |
press: obj[key], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Camera { | |
constructor(gl ,vMU, pMU) { | |
this.viewMatrix = mat4.create() | |
this.projMatrix = mat4.create() | |
this.gl = gl | |
this.viewMatrixUniform = vMU | |
this.projectionMatrixUniform = pMU | |
this.speed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getShaderData = (str) => { | |
let shaderData = { uniform: {}, attribute: {} } | |
str.match(/attribute.*;|uniform.*;/g).map(item => { | |
let [type1, type2, name] = item.split(' ') | |
name = name.slice(0,name.length-1) | |
shaderData[type1][name] = {} | |
shaderData[type1][name].location = name | |
shaderData[type1][name].type = type2 | |
}) | |
shaderData.isFragmentShader = /gl_FragColor/.test(str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//From utils.js | |
Math.TWO_PI = Math.PI * 2 | |
const random = (v) => Math.floor(Math.random() * v) | |
const range = (n, s = 0, f = 1) => new Array(n).fill(1).map(i => i = s += f) | |
const overlays = { | |
button(name,f){ | |
const btn = document.createElement('input') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PROTOTYPE PROTOTYPE PROTOTYPE PROTOTYPE PROTOTYPE | |
function ShaderManager() { | |
const state = { | |
gl: canvas.getContext("webgl2"), | |
mode: null, | |
program: null, | |
arrayBuffer: null, | |
indexBuffer: null, | |
vertexArray: null, |
OlderNewer