Skip to content

Instantly share code, notes, and snippets.

View mfandl's full-sized avatar

Matej Fandl mfandl

View GitHub Profile
@mfandl
mfandl / file.cc
Created February 9, 2018 20:59
openFrameworks + ofxVideoRecorder setup to record video with h264
/**
* openFrameworks + ofxVideoRecorder setup to record video with h264
* You will need ffmpeg and libx264 in your system. On mac, you can use homebrew.
* reason for yuv420p:
* 'QuickTime only supports YUV planar color space with 4:2:0 chroma subsampling (use -vf format=yuv420p or -pix_fmt yuv420p) for H.264 video.'
* as mentioned here: https://trac.ffmpeg.org/wiki/Encode/H.264
*/
recorder.setVideoCodec("libx264");
string fileName = ofToDataPath("v" + ofGetTimestampString() + ".mp4");
/*
* This is an Applicative Order Y-Combinator written in JavaScript. Y combinator is used to formally define recursion
* in languages that do not support it. JavaScript already does, but studying and understanding how this works
* is an enlightening experience anyway.
*
* Y and Yb are identical, just written differently - pick the one that's easier to read for you. An example is provided with
* factorial function.
*
* If you want to learn more, this article is great: http://mvanier.livejournal.com/2897.html
*/
import Data.List
lookAndSay :: [Int] -> [Int]
lookAndSay = foldr fn [] . group
where fn x acc = length x : head x : acc
export function sphere (radius, meridians, parallels) {
const vertices = []
for (let i = 0; i < parallels; ++i) {
const polar = Math.PI * i / (parallels - 1)
for (let j = 0; j < meridians; ++j) {
const azimuth = 2.0 * Math.PI * j / meridians
vertices.push(sphericalToCartesian(radius, azimuth, polar))
}
}
@mfandl
mfandl / godot_line_dist_shader
Created May 30, 2017 11:23
Godot engine line distance fragment shader
color current_color = tex(TEXTURE, UV);
float cross2(vec2 a, vec2 b ){
return a.x * b.y - a.y * b.x;
}
float dist_to_line(vec2 point, vec2 line_begin, vec2 line_end) {
vec2 c1 = line_end - line_begin;
vec2 c2 = point - line_begin;
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofGLFWWindowSettings settings;
settings.windowMode = OF_FULLSCREEN;
settings.glVersionMajor = 4;
settings.glVersionMinor = 1;
// -- vertex shader
#version 150
uniform mat4 modelViewProjectionMatrix;
uniform float elapsedTime;
in vec4 position;
void main(){
gl_Position = modelViewProjectionMatrix * vec4(position.x * sin(elapsedTime), position.y * cos(elapsedTime), position.z, position.w);
}
@mfandl
mfandl / recursiveInterpolation.js
Last active March 2, 2017 15:31
recursiveInterpolation in javascript
function interpolatedPairs (array) {
return array.slice(0, array.length - 1).map((v, i) => [v, interpolate(v, array[i + 1])])
}
function interpolate(a, b) {
return (a + b) / 2
}
function flatten (arr) {
return arr.reduce((acc, v) => acc.concat(v), [])
const countryMap = countryData.reduce((map, data) => Object.assign(map, {[data.name]: data}), {})
@mfandl
mfandl / tex.js
Created January 13, 2017 12:31
texture webgl
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);