Skip to content

Instantly share code, notes, and snippets.

@mayakraft
mayakraft / Platonic Solids
Created November 30, 2011 02:20
3D coordinates and related functions for the platonic solids
// the 5 platonic solids
//
// + point coordinates
// + the related drawing functions
// + a rotate in 3D function, around the origin
//
// written for Processing (processing.org)
int xCenter = // center of polyhedra
int yCenter = // center of polyhedra
@mayakraft
mayakraft / Kepler.m
Last active February 12, 2023 22:16
Keplerian Elements for Approximate Positions of the Major Planets
// http://ssd.jpl.nasa.gov/txt/aprx_pos_planets.pdf
typedef enum{
Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto
} Planet;
// a e I L long.peri. long.node.
// AU rad deg deg deg deg
static double elements[] = {0.38709927, 0.20563593, 7.00497902, 252.25032350, 77.45779628, 48.33076593, //mercury
0.72333566, 0.00677672, 3.39467605, 181.97909950, 131.60246718, 76.67984255, //venus
1.00000261, 0.01671123, -0.00001531, 100.46457166, 102.93768193, 0.0, //earth moon barycenter
@mayakraft
mayakraft / ofApp.cpp
Created December 10, 2016 22:36
OpenFrameworks record audio example
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
soundStreamInput.printDeviceList();
bufferSize = 256;
@mayakraft
mayakraft / convexHull.js
Last active April 20, 2022 08:56
convex hull in javascript
// this is a slow convex hull calculation that you can count on to work
// it's careful of the epsilon cases, and wether or not
// to include collinear points along the hull edge
var EPSILON_LOW = 0.003;
var EPSILON = 0.00001;
var EPSILON_HIGH = 0.00000001;
function epsilonEqual(a, b, epsilon){
if(epsilon === undefined){ epsilon = EPSILON_HIGH; }
@mayakraft
mayakraft / l-system.js
Created September 18, 2019 16:21
a concise way of writing L-systems in Javascript. this rule set is the dragon curve
var rules = {
X: "X+YF+",
Y: "-FX-Y"
};
function rewrite(str) {
var s = "";
for (var i = 0; i < str.length; i++) {
if (rules[str[i]] !== undefined) {
s += rules[str[i]];
@mayakraft
mayakraft / template.html
Created March 13, 2020 01:01
threejs template
<!DOCTYPE html>
<head>
<title>three js</title>
<style>
/*css goes here*/
html, body {
margin: 0;
overflow: hidden; /*nice to not use this*/
}
</style>
@mayakraft
mayakraft / counter.pd
Created April 3, 2020 00:55
pd count
#N canvas 100 128 450 324 12;
#X obj 230 291 dac~;
#X obj 230 267 osc~;
#X obj 41 13 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1
;
#X obj 39 65 i;
#X obj 76 66 + 1;
#X obj 324 158 expr $f1 * 3 / 2;
#X obj 151 239 f;
#X obj 203 219 f;
@mayakraft
mayakraft / counter.pd
Created April 3, 2020 00:55
pd count
#N canvas 100 128 450 324 12;
#X obj 230 291 dac~;
#X obj 230 267 osc~;
#X obj 41 13 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1
;
#X obj 39 65 i;
#X obj 76 66 + 1;
#X obj 324 158 expr $f1 * 3 / 2;
#X obj 151 239 f;
#X obj 203 219 f;
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="file">
</body>
<script>
@mayakraft
mayakraft / index.html
Last active April 6, 2020 22:01
instanceof custom object
<!DOCTYPE html>
<title>.</title>
<script>
// must instantiate with "new"
var Point = function (x, y) {
this.x = x;
this.y = y;
};