Skip to content

Instantly share code, notes, and snippets.

View ooflorent's full-sized avatar

Florent Cailhol ooflorent

  • Toulouse, France
  • 23:16 (UTC +02:00)
  • X @ooflorent
View GitHub Profile
// WebGL 1.0
export const GL_ACTIVE_ATTRIBUTES = 0x8b89;
export const GL_ACTIVE_TEXTURE = 0x84e0;
export const GL_ACTIVE_UNIFORMS = 0x8b86;
export const GL_ALIASED_LINE_WIDTH_RANGE = 0x846e;
export const GL_ALIASED_POINT_SIZE_RANGE = 0x846d;
export const GL_ALPHA = 0x1906;
export const GL_ALPHA_BITS = 0x0d55;
export const GL_ALWAYS = 0x0207;
export const GL_ARRAY_BUFFER = 0x8892;

Usage

node compile-html.cjs in.html out.html
function hashSet(arr) {
let h = 0;
for (let x of arr) {
h = Math.imul((h << 5) ^ x, 0x9e3779b9);
}
return h;
}
function rand(n) {
return (Math.random() * n) | 0;
@ooflorent
ooflorent / game.js
Last active August 23, 2019 11:43
Simple asset manager
let assets = {};
let getAsset = (id, callback) =>
assets[id] || (assets[id] = callback(document.querySelector("#" + id)));
let getImage = id => getAsset(id, img => img);
let getSource = id => getAsset(id, node => node.innerHTML.trim());
onload = () => {
let texture1 = getImage("tex1")
let texture2 = getImage("tex2")
#!/bin/bash
set -e
# Clean previous build
rm -rf dist
mkdir dist
# Compile the game
$(yarn bin)/rollup -c \
-i src/index.js \
@ooflorent
ooflorent / example.js
Created July 19, 2018 07:28
Simple PRNG
let rng = createNumberGenerator(
createSeedFromString("Hello friends!") // 2053374269
);
// Generate a boolean with 30% success
console.log(generateBoolean(rng, 0.3)); // false
console.log(generateBoolean(rng, 0.3)); // true
// Generate a D6
console.log(generateNumber(rng, 1, 6)); // 3
@ooflorent
ooflorent / canvas.js
Last active February 18, 2024 21:19
Canvas helpers & noise generator
/**
* @param {number} width
* @param {number} height
* @param {!CanvasPattern} pattern
* @constructor
*/
function Texture(width, height, pattern) {
this.width = width
this.height = height
this.pattern = pattern
const eventBus = new EventEmitter()
function someSystem() {
for (const entity of em.query(Timer)) {
const {delay} = entity.get(Timer)
if (delay <= 0) {
// Remove `Timer` component…
entity.remove(Timer)
// …then dispatch an event
eventBus.emit("componentRemoved", {entity})
import { applyMiddleware, compose, createStore } from "redux"
import { reduxReactIntl } from "redux-react-intl"
import thunk from "redux-thunk"
import rootReducer from "./reducers"
const createStoreFactory = compose(
applyMiddleware(thunk),
reduxReactRouter({ routes, createHistory })
)
@ooflorent
ooflorent / flux.js
Created April 16, 2015 13:31
Dummy Flux implementation
export const actions = {
doSomeStuff() {
return fetch('/api/stuff').then(
(res) => (stores.stuffList = res),
(err) => Promise.reject(err)
)
}
}
export const stores = {