Skip to content

Instantly share code, notes, and snippets.

View mendes5's full-sized avatar
๐Ÿ“‰
[object Object]

mendes5

๐Ÿ“‰
[object Object]
View GitHub Profile
@mendes5
mendes5 / shaderManager.js
Created April 24, 2017 23:27
Copynpaste for webgl2 shader abstraction
//PROTOTYPE PROTOTYPE PROTOTYPE PROTOTYPE PROTOTYPE
function ShaderManager() {
const state = {
gl: canvas.getContext("webgl2"),
mode: null,
program: null,
arrayBuffer: null,
indexBuffer: null,
vertexArray: null,
func QueryOpenGL(){
var currentQuery int32
gl.GetIntegerv(gl.MAX_3D_TEXTURE_SIZE, &currentQuery)
fmt.Print("\nMAX_3D_TEXTURE_SIZE : ", int(currentQuery))
gl.GetIntegerv(gl.MAX_ARRAY_TEXTURE_LAYERS, &currentQuery)
fmt.Print("\nMAX_ARRAY_TEXTURE_LAYERS : ", int(currentQuery))
gl.GetIntegerv(gl.MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &currentQuery)
fmt.Print("\nMAX_ATOMIC_COUNTER_BUFFER_BINDINGS : ", int(currentQuery))
gl.GetIntegerv(gl.MAX_ATOMIC_COUNTER_BUFFER_SIZE, &currentQuery)
fmt.Print("\nMAX_ATOMIC_COUNTER_BUFFER_SIZE : ", int(currentQuery))
package shader
import (
"fmt"
"strings"
"io/ioutil"
"github.com/go-gl/gl/v3.3-core/gl"
)
type Shader struct {
package glutils
import (
"fmt"
"unsafe"
"shader"
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
)
@mendes5
mendes5 / collision.js
Last active April 27, 2018 16:20
Test Collision Between two selectors ex: testColision("#DivA", ".divsB", func)
const rangeIntersect = (min0, max0, min1, max1) =>
Math.max(min0, max0) >= Math.min(min1, max1) && Math.min(min0, max0) <= Math.max(min1, max1)
const elementsIntersect = (element1, element2) => {
const r0 = element1.getBoundingClientRect()
const r1 = element2.getBoundingClientRect()
return rangeIntersect(r0.left, r0.right, r1.left, r1.right) && rangeIntersect(r0.top, r0.bottom, r1.top, r1.bottom)
}
const testColision = (selector1, selector2, callback) =>
@mendes5
mendes5 / index.js
Last active July 26, 2017 17:51
Play a track from soundcloud, good for webaudio experiments
const playFromSoundCloud = async function (url) {
const uri = encodeURIComponent(url)
const link = `https://api.soundcloud.com/resolve.json?url=${uri}&client_id=17a992358db64d99e492326797fff3e8`
const response = await fetch(link).then(res => res.json()).then(json => json)
const audio = document.createElement('audio')
audio.crossOrigin = "anonymous"
audio.src = `http://api.soundcloud.com/tracks/${response.id}/stream?client_id=17a992358db64d99e492326797fff3e8`
audio.play()
return audio
@mendes5
mendes5 / index.js
Created September 18, 2017 23:19
Downloads all images in the webpage
document.querySelectorAll('img').forEach(e => {
let url = e.src
let name = url.slice(-20)
let a = document.createElement("a")
a.download = `${name}.png`
a.href = url
document.body.appendChild(a);
a.click()
@mendes5
mendes5 / colliders.js
Last active April 27, 2018 14:59
Simple AABB collision detetion
const Colliders = (e => {
const abs = (num) => Math.abs(num)
class BaseSprite {
constructor(x, y, w, h) {
this.x = x
this.y = y
this.width = w
this.height = h
const C$ = (str = 'html', all = false) => !all ? document.querySelector(str) : document.querySelectorAll(str);
const sin = Math.sin
const cos = Math.cos
const abs = Math.abs
const int = Number.parseInt
const float = Number.parseFloat
const rand = Math.random
const u = (_ => {
@mendes5
mendes5 / clearAllTimeoutsOrIntervals.js
Created March 14, 2018 17:31
Provides `clearAllTimeouts()` and `clearAllIntervals()`.
(()=>{
const timeout = window.setTimeout, interval = window.setInterval
let intervals = [], timeouts = []
window.setTimeout = (cb, tm, rv) => (timeouts.push(rv = timeout(cb, tm)), rv)
window.setInterval = (cb, tm, rv) => (intervals.push(rv = interval(cb, tm)), rv)
window.clearAllTimeouts = () => {timeouts.map(e => clearTimeout(e)); timeouts = []}
window.clearAllIntervals = () => {intervals.map(e => clearInterval(e)); intervals = []}
})()