Skip to content

Instantly share code, notes, and snippets.

var x, y, z, a, b, c, dt;
var points;
function setup(){
createCanvas(600, 600, WEBGL);
points = [];
x = 0.01;
y = 0;
@jrc03c
jrc03c / arrangements.js
Last active February 9, 2017 15:50
A JS function to enumerate all arrangements of some letters
function arrangements(letters){
if (letters.length == 1){
return [letters];
}
else if (letters.length == 2){
return [letters[0] + letters[1], letters[1] + letters[0]];
}
else {
@jrc03c
jrc03c / spiro.js
Created February 26, 2017 16:00
A Spirograph
var n = 4;
var angles;
var speeds;
var lengths;
function setup(){
createCanvas(window.innerWidth, window.innerHeight);
stroke(0, 10);
fill(0);
frameRate(99999999999);
@jrc03c
jrc03c / spiro2.js
Last active February 27, 2017 00:48
More spirographs.
var n = 7;
var angles, speeds, lengths;
function setup(){
createCanvas(window.innerWidth, window.innerWidth);
background(255);
fill(0, 20);
frameRate(9999);
angles = [];
@jrc03c
jrc03c / git.txt
Last active April 19, 2023 20:05
Git Cheat Sheet
##################
Basic Git Commands
##################
git init = turns the current working directory into a repository
git clone = downloads a remote repository to your machine
Syntax: git clone <source> <destination>
Example: git clone https://github.com/willfind/uplift-website /home/josh/projects/uplift.app
@jrc03c
jrc03c / download-canvas-as-image.js
Created February 13, 2020 15:10
Download the contents of an HTML5 canvas as an image
function downloadCanvasAsImage(canvas, filename){
let a = document.createElement("a")
a.href = canvas.toDataURL()
a.download = filename
a.dispatchEvent(new MouseEvent("click"))
}
@jrc03c
jrc03c / download-text.js
Last active May 9, 2023 00:30
Download text as a file
function downloadText(filename, text){
const a = document.createElement("a")
a.href = "data:text/plain;charset=utf-8," + encodeURIComponent(text)
a.download = filename
a.dispatchEvent(new MouseEvent("click"))
}
@jrc03c
jrc03c / high-dpi-canvas.js
Last active March 7, 2021 23:51
Create a high-DPI-compatible canvas element
function createHighDPICanvas(width, height){
let dpi = window.devicePixelRatio || 1
let canvas = document.createElement("canvas")
canvas.width = width * dpi
canvas.height = height * dpi
canvas.style.width = width + "px"
canvas.style.height = height + "px"
canvas.getContext("2d").scale(dpi, dpi)
return canvas
}
@jrc03c
jrc03c / copy-text.js
Last active April 19, 2023 20:00
Copy arbitrary text to the clipboard in the browser
// 🚨 🚨 🚨
// NOTE: According to MDN, `document.execCommand()` is deprecated. See:
// https://developer.mozilla.org/en-US/docs/Web/API/document/execCommand
// Instead, use the Clipboard API:
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
// 🚨 🚨 🚨
function copy(text) {
const input = document.createElement("input")
input.type = "text"
@jrc03c
jrc03c / get-scrollbar-width.js
Created July 31, 2021 21:03
Get the width of a browser scrollbar
// from: https://davidwalsh.name/detect-scrollbar-width
function getScrollbarWidth() {
const div = document.createElement("div")
div.style = `
width: 100px;
height: 100px;
overflow: scroll;
position: absolute;