Skip to content

Instantly share code, notes, and snippets.

@nataliefreed
nataliefreed / pumpkin.jscad
Created October 9, 2016 22:44
OpenJSCAD parametric pumpkin
// title : OpenJSCAD Pumpkin
// author : Natalie Freed
function getParameterDefinitions() {
return [
{ name: 'numSegments', type: 'int', initial: 10, caption: "Number of segments:" },
{ name: 'proportions', type: 'choice', caption: 'Proportions:', values: ["tall", "wide", "medium"], captions: ["tall", "wide", "medium"], initial: "medium" }
];
}
@nataliefreed
nataliefreed / rainbowArray.js
Created September 28, 2016 22:41
Array example in P5, make an array of colors and draw a rainbow. Includes how to append and splice in elements
var rainbow; //global variable
function setup() {
createCanvas(600, 600);
//make the list (array) of rainbow colors
rainbow = [color('#c0392b'), color('#e67e22'), color('#f1c40f'), color('#2ecc71'), color('#3498db'), color('#8e44ad')];
//shift to the center and down a bit
translate(width / 2, height / 3);
@nataliefreed
nataliefreed / shape_scaling_helper.js
Created September 26, 2016 23:14
Wrapper function to help scale shapes in P5
function setup() {
createCanvas(600, 600);
noFill();
strokeWeight(3);
//example: draw something, unscaled
yourFunctionThatDrawsAThing(100, 200);
//example: make a half scale version
var scaledByHalf = autoScale(yourFunctionThatDrawsAThing, 0.5);
//Scale your shapes up without them moving all over the place!
var scalingFactor = 1;
var x = 100;
var y = 200;
var w = 40;
var h = 30;
function setup()
{
@nataliefreed
nataliefreed / graphPoints.pde
Created October 7, 2014 00:13
Virtual "graph paper" for Cartesian points. Click on the screen to add a point, click and drag on points to move them and see their coordinates change
//Click to add a new point
//Drag points to see their coordinates change
//Natalie Freed Oct. 2014
DraggableHandler points;
void setup()
{
size(600, 600);
points = new DraggableHandler(this);
//Art and Science of Computing Fall 14
//Star decreases in size over time
//Click mouse to save a "screenshot" of its current state
int[] xPositions = { 90, 251, 51, 213, 151, 90 };
int[] yPositions = { 230, 112, 112, 229, 39, 230 };
float scaleSize = 1;
void setup()
@nataliefreed
nataliefreed / gridlines1
Last active September 1, 2016 17:40
draw gridlines in Processing (first way)
//draw gridlines in Processing (first way)
//this version intentionally does not use loops. It can be made much more concise with loops.
//Natalie Freed August 2014 for Art and Science of Computing
size(1000, 700);
line(0, 0, 1000, 0);
line(0, 100, 1000, 100);
line(0, 200, 1000, 200);
line(0, 300, 1000, 300);
/*
Classes and objects with arrays example
Natalie Freed for Art and Science of Computing May 16, 2016
Whale function by Courtney Peterson, March 9, 2016
From: Whales in Love https://gist.github.com/anonymous/5d5b9bdef5243e8c2973
*/
Whale orangeWhale;
Whale greenWhale;
#include <Servo.h>
//TODO: Change these variable names to the correct notes
Servo a;
Servo b;
Servo c;
Servo d;
Servo e;
Servo f;
Servo g;
/* Starting point for sorting algorithm implementation */
int[] array = new int[100000];
void setup()
{
//fill the array with random numbers
for(int i=0;i<array.length;i++)
{
array[i] = round(random(-1000, 1000));