Skip to content

Instantly share code, notes, and snippets.

View mattdesl's full-sized avatar
👋

Matt DesLauriers mattdesl

👋
View GitHub Profile
@mattdesl
mattdesl / rgb-cmyk.glsl
Last active November 26, 2024 06:35
RGB / CMYK conversion in GLSL
// From the book: Graphics Shaders
vec3 CMYKtoRGB (vec4 cmyk) {
float c = cmyk.x;
float m = cmyk.y;
float y = cmyk.z;
float k = cmyk.w;
float invK = 1.0 - k;
float r = 1.0 - min(1.0, c * invK + k);
@mattdesl
mattdesl / about.md
Created May 29, 2019 14:11
canvas-sketch + typescript

canvas-sketch + TypeScript

After installing canvas-sketch globally, create a new folder to hold your sketch:

mkdir my-sketch
cd my-sketch

Now run the following to generate a new default .ts file, package.json, etc:

@mattdesl
mattdesl / point-to-line-2d.js
Created March 22, 2018 00:36
2D Point to Line Segment distance function
// Taken From:
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
function sqr (x) {
return x * x;
}
function dist2 (v, w) {
return sqr(v[0] - w[0]) + sqr(v[1] - w[1]);
}

Rendering High-Resolution Meridian Outputs

Meridian is a generative art project deployed on Ethereum, and distributed as unique, artist-signed tokens. This creates an interesting scenario where the value and acquisition of the art project is not tied to the scarcity of access to its media (such as high-resolution PNGs and fine art prints of the algorithm's output). And so, I've created some tools to help all audiences—whether collectors of the tokens or not—export high-resolution outputs of a given Meridian for personal and non-commercial means. For example: fine art printing to hang a Meridian on your walls, or using it as a social media avatar or banner, or including it in a blog post.

First, open the following page and scroll to the interactive component, showing the Meridian software: https://meridian.mattdesl.com/

In that page, open your DevTools Console in the browser, in Chrome it is under View > Developer > JavaScript Console. Each time you click the artwork, it

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
@mattdesl
mattdesl / load-images.js
Created May 8, 2015 16:29
load images in parallel
function loadImage(url, callback) {
var image = new Image();
image.onload = function() {
callback(null, image);
};
image.onerror = function() {
callback(new Error('Could not load image at ' + url));
};
image.src = url;
}
@mattdesl
mattdesl / modules.md
Last active October 12, 2024 16:17
my favourite modules.
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@mattdesl
mattdesl / offset-path.js
Created December 19, 2018 14:44
MIT – 2D vector path offsetting algorithm (work in progress)
/*
Copyright 2018 Matt DesLauriers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;