Skip to content

Instantly share code, notes, and snippets.

View grifdail's full-sized avatar

Julien Berthou grifdail

View GitHub Profile
@grifdail
grifdail / Voxelizer.js
Created November 18, 2017 11:44
Voxelizer
// Copy that into MeshPlayground
// http://grifdail.fr/MeshPlayground/
var box = new Box(1);
const sphereVolume = (radius, center) => (x,y,z) => sqrt((x-center.x)*(x-center.x)+(y-center.y)*(y-center.y)+(z-center.z)*(z-center.z))<radius;
const mainSphere = sphereVolume(0.4, Vector3.one().scale(0.5));
const holeSphere = sphereVolume(0.7, Vector3.one().scale(1));
const holeSphere2 = sphereVolume(0.3, new Vector3(0.3,0.3,0.6));
@grifdail
grifdail / pico8colors.pde
Created June 6, 2017 14:52
pico8colors.pde
// Pico 8 colors for processing
color BLACK = #000000;
color DARK_BLUE = #1D2B53;
color DARK_PURPLE = #7E2553;
color DARK_GREEN = #008751;
color BROWN = #AB5236;
color DARK_GRAY = #5F574F;
color LIGHT_GRAY = #C2C3C7;
color WHITE = #FFF1E8;
@grifdail
grifdail / PoissonDisk.pde
Created May 21, 2017 11:45
Poisson disk distribution
//very inneficient
PVector[] PoissonDiskGenerate(int count, PVector range, int sample) {
PVector[] list = new PVector[count];
for(int i =0; i<count; i++) {
PVector[] samples = new PVector[sample];
float[] distances = new float[sample];
for(int j = 0; j<sample; j++) {
PVector newPoint = new PVector(random(range.x), random(range.y));
samples[j] = newPoint;
//Get the distance to the nearest point
@grifdail
grifdail / TextureGradient.pde
Last active May 19, 2017 11:49
Use a color to create a gradient
class TextureGradient {
public color[] pixels;
TextureGradient(String name) {
PImage background = loadImage(name);
background.loadPixels();
pixels = background.pixels;
}
color get(float t) {
@grifdail
grifdail / PyramidGenerator.cs
Created April 28, 2016 08:33
Editor tool to generate Pyramid and Cone in unity. Save this script in an Editor Folder and it will create a new menu option in Assets/Create; You can chose the number of side and between hard and soft edge.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class PyramidGenerator : ScriptableWizard
{
public int size = 4;
public bool flat = true;
@grifdail
grifdail / Input.js
Last active January 17, 2021 04:02
The best javascript input controller for game. Include gamepad support.
/*
Input.jump = {
key: 32//Space
gamepad: 0// A button on as XBOX360 gamepad
}
dont forget to call
Input.update();
at the end of each frame.
@grifdail
grifdail / camera.js
Created April 11, 2015 21:46
Raycaster Javascript
function RayCastCamera(fov,resolution) {
this.fov = fov;
this.resolution = resolution; //How Many ray should we cast and draw;
}
RayCastCamera.prototype.render = function(map, pos, angle, walls) {
ctx.fillStyle = "black";
ctx.fillRect(0,0,width,height*0.5); //The Top of the Screen is black
ctx.fillStyle = "grey";
ctx.fillRect(0,height*0.5,width,height*0.5); // The bottom is grey
@grifdail
grifdail / gulpfile.js
Last active June 5, 2018 13:35
Simple babel livereload
var gulp = require('gulp'),
babel = require('gulp-babel'),
livereload = require('gulp-livereload'),
http = require('http'),
st = require('st'),
transform = require('vinyl-transform'),
browserify = require('browserify');
gulp.task('js', ["es6"],function() {
@grifdail
grifdail / CameraControle.cs
Created February 21, 2015 13:21
Unity script to move a camera like in Black and White or almost any 3d strategie game.
using UnityEngine;
using System.Collections;
public class CameraControl : MonoBehaviour {
public float translateScale = 20;
public float rotateScale = 1;
public float zoomScale = 100;
private Vector3 _lastHitPoint;
var a = [":bowtie:",":smile:",":laughing:",":blush:",":smiley:",":relaxed:",":smirk:",":heart_eyes:",":kissing_heart:",":kissing_closed_eyes:",":flushed:",":relieved:",":satisfied:",":grin:",":wink:",":stuck_out_tongue_winking_eye:",":stuck_out_tongue_closed_eyes:",":grinning:",":kissing:",":kissing_smiling_eyes:",":stuck_out_tongue:",":sleeping:",":worried:",":frowning:",":anguished:",":open_mouth:",":grimacing:",":confused:",":hushed:",":expressionless:",":unamused:",":sweat_smile:",":sweat:",":disappointed_relieved:",":weary:",":pensive:",":disappointed:",":confounded:",":fearful:",":cold_sweat:",":persevere:",":cry:",":sob:",":joy:",":astonished:",":scream:",":neckbeard:",":tired_face:",":angry:",":rage:",":triumph:",":sleepy:",":yum:",":mask:",":sunglasses:",":dizzy_face:",":imp:",":smiling_imp:",":neutral_face:",":no_mouth:",":innocent:",":alien:",":yellow_heart:",":blue_heart:",":purple_heart:",":heart:",":green_heart:",":broken_heart:",":heartbeat:",":heartpulse:",":two_hearts:",":revolving_hearts:","