Skip to content

Instantly share code, notes, and snippets.

View ooflorent's full-sized avatar

Florent Cailhol ooflorent

  • Toulouse, France
  • 10:03 (UTC +02:00)
  • X @ooflorent
View GitHub Profile
@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
@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
// 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")
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 })
)
#!/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 / LICENSE
Last active April 18, 2018 03:55
Seeded random number generator
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2014 Florent Cailhol <https://github.com/ooflorent>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ooflorent
ooflorent / demo.js
Created January 8, 2014 10:39
Basic ECS
// Components
// ----------
function KeyboardController() {}
function AIController() {}
function Position(x, y) {
this.x = x || 0;
this.y = y || 0;
}