Skip to content

Instantly share code, notes, and snippets.

View mahmed8003's full-sized avatar

Muhammad Ahmed mahmed8003

View GitHub Profile
/**
* Converts nested arrays into one-dimensional flattening array (recursively)
* @param {Array} arr Input nested arrays
* @param {Array} result Output one-dimensional flattening array
* @return Output one-dimensional flattening array
*/
function flattenNestedArrays(arr, result = []) {
const length = arr.length;
for (let i = 0; i < length; i++) {
@mahmed8003
mahmed8003 / debugdraw.js
Created February 8, 2016 09:16
Pixi.js and Box2D debug draw demo
// Credit goes to https://gist.github.com/cbranch/260224a7e4699552d2dc
// Gets a JSDraw instance which renders to a PIXI graphics object.
// graphics: an instance of PIXI.Graphics
// scale: the scaling factor to convert from Box2D coordinates to screen pixels
function getPIXIDebugDraw(graphics, scale) {
function getColorFromDebugDrawCallback(color) {
var col = Box2D.wrapPointer(color, Box2D.b2Color);
var red = (col.get_r() * 255 * 255 * 255)|0;
var green = (col.get_g() * 255 * 255)|0;
var blue = (col.get_b() * 255)|0;