Skip to content

Instantly share code, notes, and snippets.

@dribnet
Forked from prestojack/.block
Last active October 18, 2018 21:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dribnet/8beccb60eb57adcaf8e82e21e89ac43a to your computer and use it in GitHub Desktop.
Save dribnet/8beccb60eb57adcaf8e82e21e89ac43a to your computer and use it in GitHub Desktop.
PAPER: Parametric Alphabet
license: mit
// note: this file is poorly named - it can generally be ignored.
// helper functions below for supporting blocks/purview
function saveBlocksImages(doZoom) {
if(doZoom == null) {
doZoom = false;
}
// generate 960x500 preview.jpg of entire canvas
// TODO: should this be recycled?
var offscreenCanvas = document.createElement('canvas');
offscreenCanvas.width = 960;
offscreenCanvas.height = 500;
var context = offscreenCanvas.getContext('2d');
// background is flat white
context.fillStyle="#FFFFFF";
context.fillRect(0, 0, 960, 500);
context.drawImage(this.canvas, 0, 0, 960, 500);
// save to browser
var downloadMime = 'image/octet-stream';
var imageData = offscreenCanvas.toDataURL('image/jpeg');
imageData = imageData.replace('image/jpeg', downloadMime);
p5.prototype.downloadFile(imageData, 'preview.jpg', 'jpg');
// generate 230x120 thumbnail.png centered on mouse
offscreenCanvas.width = 230;
offscreenCanvas.height = 120;
// background is flat white
context = offscreenCanvas.getContext('2d');
context.fillStyle="#FFFFFF";
context.fillRect(0, 0, 230, 120);
if(doZoom) {
// pixelDensity does the right thing on retina displays
var pd = this._pixelDensity;
var sx = pd * mouseX - pd * 230/2;
var sy = pd * mouseY - pd * 120/2;
var sw = pd * 230;
var sh = pd * 120;
// bounds checking - just displace if necessary
if (sx < 0) {
sx = 0;
}
if (sx > this.canvas.width - sw) {
sx = this.canvas.width - sw;
}
if (sy < 0) {
sy = 0;
}
if (sy > this.canvas.height - sh) {
sy = this.canvas.height - sh;
}
// save to browser
context.drawImage(this.canvas, sx, sy, sw, sh, 0, 0, 230, 120);
}
else {
// now scaledown
var full_width = this.canvas.width;
var full_height = this.canvas.height;
context.drawImage(this.canvas, 0, 0, full_width, full_height, 0, 0, 230, 120);
}
imageData = offscreenCanvas.toDataURL('image/png');
imageData = imageData.replace('image/png', downloadMime);
p5.prototype.downloadFile(imageData, 'thumbnail.png', 'png');
}

PS2 MDDN 342 2016 - Origami

The challenge for this piece was to create a font that could animate between its letters. The inspiration for the typeface was a folding piece of paper, as any letter can be created by bending a simple strip of paper. The animation is based on the folding motion of the paper, and each letter can transition to any other by simply adjusting the positions of its joints. Overall the Origami font has a unique transition between letters that creates a dynamic, engaging visual effect.

{
"A":
{
"box1": {
"xpos": 54,
"ypos": -2,
"color": 1
},
"box2": {
"xpos": 86,
"ypos": 149,
"color": 0
},
"box3": {
"xpos": 61,
"ypos": 93,
"color": 1
},
"box4": {
"xpos": 23,
"ypos": 107,
"color": 1
},
"box5": {
"xpos": -5,
"ypos": 170,
"color": 0
},
"box6": {
"xpos": 26,
"ypos": 9,
"color": 0
},
"box7": {
"xpos": 54,
"ypos": -2
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"B":
{
"box1": {
"xpos": -5,
"ypos": 170,
"color": 1
},
"box2": {
"xpos": 86,
"ypos": 149,
"color": 1
},
"box3": {
"xpos": 79,
"ypos": 107,
"color": 1
},
"box4": {
"xpos": 47,
"ypos": 75,
"color": 1
},
"box5": {
"xpos": 79,
"ypos": -12,
"color": 0
},
"box6": {
"xpos": -9,
"ypos": 9,
"color": 0
},
"box7": {
"xpos": -5,
"ypos": 170
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"C":
{
"box1": {
"xpos": 73,
"ypos": 156,
"color": 1
},
"box2": {
"xpos": 26,
"ypos": 181,
"color": 0
},
"box3": {
"xpos": -12,
"ypos": 146,
"color": 0
},
"box4": {
"xpos": -19,
"ypos": 96,
"color": 0
},
"box5": {
"xpos": -12,
"ypos": 44,
"color": 0
},
"box6": {
"xpos": 23,
"ypos": -2,
"color": 0
},
"box7": {
"xpos": 66,
"ypos": -2
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"D":
{
"box1": {
"xpos": -12,
"ypos": 181,
"color": 1
},
"box2": {
"xpos": 40,
"ypos": 163,
"color": 1
},
"box3": {
"xpos": 68,
"ypos": 121,
"color": 1
},
"box4": {
"xpos": 68,
"ypos": 58,
"color": 1
},
"box5": {
"xpos": 30,
"ypos": 12,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 12,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"E":
{
"box1": {
"xpos": 73,
"ypos": 156,
"color": 1
},
"box2": {
"xpos": -12,
"ypos": 181,
"color": 0
},
"box3": {
"xpos": -12,
"ypos": 103,
"color": 0
},
"box4": {
"xpos": 69,
"ypos": 79,
"color": 1
},
"box5": {
"xpos": -12,
"ypos": 93,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": 66,
"ypos": -5
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"F":
{
"box1": {
"xpos": -12,
"ypos": 181,
"color": 1
},
"box2": {
"xpos": -12,
"ypos": 103,
"color": 1
},
"box3": {
"xpos": 69,
"ypos": 73,
"color": 0
},
"box4": {
"xpos": -12,
"ypos": 93,
"color": 1
},
"box5": {
"xpos": -12,
"ypos": 25,
"color": 1
},
"box6": {
"xpos": 69,
"ypos": 2,
"color": 0
},
"box7": {
"xpos": -15,
"ypos": 15
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"G":
{
"box1": {
"xpos": 73,
"ypos": 161,
"color": 1
},
"box2": {
"xpos": 66,
"ypos": 107,
"color": 0
},
"box3": {
"xpos": 53,
"ypos": 164,
"color": 0
},
"box4": {
"xpos": -12,
"ypos": 181,
"color": 1
},
"box5": {
"xpos": -12,
"ypos": 25,
"color": 1
},
"box6": {
"xpos": 69,
"ypos": 2,
"color": 0
},
"box7": {
"xpos": 69,
"ypos": 46
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"H":
{
"box1": {
"xpos": 73,
"ypos": 161,
"color": 1
},
"box2": {
"xpos": 69,
"ypos": 2,
"color": 0
},
"box3": {
"xpos": 65,
"ypos": 79,
"color": 0
},
"box4": {
"xpos": 32,
"ypos": 93,
"color": 0
},
"box5": {
"xpos": -9,
"ypos": 111,
"color": 1
},
"box6": {
"xpos": -12,
"ypos": 25,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"I":
{
"box1": {
"xpos": -15,
"ypos": 178,
"color": 0
},
"box2": {
"xpos": 39,
"ypos": 168,
"color": 0
},
"box3": {
"xpos": 76,
"ypos": 161,
"color": 1
},
"box4": {
"xpos": 32,
"ypos": 154,
"color": 0
},
"box5": {
"xpos": 32,
"ypos": 22,
"color": 1
},
"box6": {
"xpos": -15,
"ypos": 19,
"color": 0
},
"box7": {
"xpos": 83,
"ypos": 5
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"J":
{
"box1": {
"xpos": -15,
"ypos": 131,
"color": 1
},
"box2": {
"xpos": 8,
"ypos": 175,
"color": 0
},
"box3": {
"xpos": 49,
"ypos": 161,
"color": 0
},
"box4": {
"xpos": 53,
"ypos": 154,
"color": 0
},
"box5": {
"xpos": 49,
"ypos": 22,
"color": 1
},
"box6": {
"xpos": -15,
"ypos": 19,
"color": 0
},
"box7": {
"xpos": 83,
"ypos": 5
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"K":
{
"box1": {
"xpos": 76,
"ypos": 151,
"color": 0
},
"box2": {
"xpos": 66,
"ypos": 164,
"color": 1
},
"box3": {
"xpos": 12,
"ypos": 103,
"color": 1
},
"box4": {
"xpos": 63,
"ypos": 8,
"color": 0
},
"box5": {
"xpos": -5,
"ypos": 86,
"color": 1
},
"box6": {
"xpos": -19,
"ypos": 19,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 168
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"L":
{
"box1": {
"xpos": -12,
"ypos": 168,
"color": 1
},
"box2": {
"xpos": 90,
"ypos": 127,
"color": 1
},
"box3": {
"xpos": 90,
"ypos": 103,
"color": 0
},
"box4": {
"xpos": 12,
"ypos": 134,
"color": 1
},
"box5": {
"xpos": 5,
"ypos": 12,
"color": 0
},
"box6": {
"xpos": -19,
"ypos": 19,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 168
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"M":
{
"box1": {
"xpos": 73,
"ypos": 161,
"color": 1
},
"box2": {
"xpos": 63,
"ypos": 2,
"color": 0
},
"box3": {
"xpos": 49,
"ypos": 5,
"color": 0
},
"box4": {
"xpos": 32,
"ypos": 139,
"color": 1
},
"box5": {
"xpos": 5,
"ypos": 12,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"N":
{
"box1": {
"xpos": 82,
"ypos": -2,
"color": 0
},
"box2": {
"xpos": 68,
"ypos": 2,
"color": 0
},
"box3": {
"xpos": 72,
"ypos": 163,
"color": 0
},
"box4": {
"xpos": 58,
"ypos": 167,
"color": 1
},
"box5": {
"xpos": 12,
"ypos": 9,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"O":
{
"box1": {
"xpos": -12,
"ypos": 181,
"color": 1
},
"box2": {
"xpos": 68,
"ypos": 153,
"color": 1
},
"box3": {
"xpos": 68,
"ypos": -5,
"color": 1
},
"box4": {
"xpos": 54,
"ypos": -26,
"color": 0
},
"box5": {
"xpos": 5,
"ypos": -12,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"P":
{
"box1": {
"xpos": -12,
"ypos": 177,
"color": 1
},
"box2": {
"xpos": 23,
"ypos": 82,
"color": 1
},
"box3": {
"xpos": 68,
"ypos": 47,
"color": 1
},
"box4": {
"xpos": 68,
"ypos": -5,
"color": 1
},
"box5": {
"xpos": 54,
"ypos": -19,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 9,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"Q":
{
"box1": {
"xpos": -12,
"ypos": 181,
"color": 1
},
"box2": {
"xpos": 68,
"ypos": 153,
"color": 1
},
"box3": {
"xpos": 100,
"ypos": 163,
"color": 1
},
"box4": {
"xpos": 68,
"ypos": 135,
"color": 1
},
"box5": {
"xpos": 68,
"ypos": -9,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"R":
{
"box1": {
"xpos": 79,
"ypos": 160,
"color": 1
},
"box2": {
"xpos": 23,
"ypos": 82,
"color": 1
},
"box3": {
"xpos": 68,
"ypos": 47,
"color": 1
},
"box4": {
"xpos": 68,
"ypos": -5,
"color": 1
},
"box5": {
"xpos": 54,
"ypos": -19,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 9,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"S":
{
"box1": {
"xpos": -12,
"ypos": 184,
"color": 0
},
"box2": {
"xpos": -12,
"ypos": 170,
"color": 0
},
"box3": {
"xpos": 68,
"ypos": 142,
"color": 0
},
"box4": {
"xpos": 69,
"ypos": 72,
"color": 1
},
"box5": {
"xpos": -12,
"ypos": 100,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": 66,
"ypos": -12
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"T":
{
"box1": {
"xpos": 79,
"ypos": -19,
"color": 1
},
"box2": {
"xpos": 33,
"ypos": 12,
"color": 1
},
"box3": {
"xpos": 37,
"ypos": 153,
"color": 1
},
"box4": {
"xpos": 19,
"ypos": 160,
"color": 0
},
"box5": {
"xpos": 16,
"ypos": 19,
"color": 1
},
"box6": {
"xpos": -44,
"ypos": 23,
"color": 0
},
"box7": {
"xpos": 79,
"ypos": -19
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"U":
{
"box1": {
"xpos": 82,
"ypos": -5,
"color": 0
},
"box2": {
"xpos": 58,
"ypos": 2,
"color": 0
},
"box3": {
"xpos": 58,
"ypos": 153,
"color": 0
},
"box4": {
"xpos": 26,
"ypos": 167,
"color": 0
},
"box5": {
"xpos": -16,
"ypos": 167,
"color": 1
},
"box6": {
"xpos": -19,
"ypos": 16,
"color": 0
},
"box7": {
"xpos": -47,
"ypos": 23
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"V":
{
"box1": {
"xpos": 37,
"ypos": 161,
"color": 1
},
"box2": {
"xpos": 79,
"ypos": -2,
"color": 0
},
"box3": {
"xpos": 49,
"ypos": 5,
"color": 0
},
"box4": {
"xpos": 30,
"ypos": 93,
"color": 1
},
"box5": {
"xpos": 5,
"ypos": 12,
"color": 0
},
"box6": {
"xpos": -26,
"ypos": 19,
"color": 0
},
"box7": {
"xpos": 37,
"ypos": 163
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"W":
{
"box1": {
"xpos": 86,
"ypos": 44,
"color": 1
},
"box2": {
"xpos": 79,
"ypos": -2,
"color": 0
},
"box3": {
"xpos": 51,
"ypos": 153,
"color": 1
},
"box4": {
"xpos": 30,
"ypos": 44,
"color": 0
},
"box5": {
"xpos": 9,
"ypos": 163,
"color": 1
},
"box6": {
"xpos": -26,
"ypos": 19,
"color": 0
},
"box7": {
"xpos": -37,
"ypos": 68
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"X":
{
"box1": {
"xpos": 104,
"ypos": 167,
"color": 1
},
"box2": {
"xpos": 47,
"ypos": 93,
"color": 1
},
"box3": {
"xpos": 93,
"ypos": -5,
"color": 0
},
"box4": {
"xpos": 23,
"ypos": 65,
"color": 1
},
"box5": {
"xpos": -40,
"ypos": 9,
"color": 0
},
"box6": {
"xpos": 12,
"ypos": 89,
"color": 0
},
"box7": {
"xpos": -44,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"X2":
{
"box1": {
"xpos": 104,
"ypos": 167,
"color": 1
},
"box2": {
"xpos": 47,
"ypos": 93,
"color": 1
},
"box3": {
"xpos": 89,
"ypos": -9,
"color": 0
},
"box4": {
"xpos": 26,
"ypos": 82,
"color": 1
},
"box5": {
"xpos": -40,
"ypos": 9,
"color": 0
},
"box6": {
"xpos": 12,
"ypos": 89,
"color": 0
},
"box7": {
"xpos": -23,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"Y":
{
"box1": {
"xpos": 89,
"ypos": -9,
"color": 0
},
"box2": {
"xpos": 65,
"ypos": -5,
"color": 0
},
"box3": {
"xpos": 33,
"ypos": 82,
"color": 1
},
"box4": {
"xpos": -16,
"ypos": 5,
"color": 0
},
"box5": {
"xpos": -40,
"ypos": 9,
"color": 0
},
"box6": {
"xpos": 12,
"ypos": 89,
"color": 0
},
"box7": {
"xpos": 12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"Z":
{
"box1": {
"xpos": 75,
"ypos": 121,
"color": 0
},
"box2": {
"xpos": 65,
"ypos": 142,
"color": 0
},
"box3": {
"xpos": -12,
"ypos": 170,
"color": 1
},
"box4": {
"xpos": -12,
"ypos": 156,
"color": 1
},
"box5": {
"xpos": 65,
"ypos": 9,
"color": 1
},
"box6": {
"xpos": 65,
"ypos": -12,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 16
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"1":
{
"box1": {
"xpos": 65,
"ypos": -2,
"color": 1
},
"box2": {
"xpos": 61,
"ypos": 170,
"color": 1
},
"box3": {
"xpos": 37,
"ypos": 181,
"color": 0
},
"box4": {
"xpos": 40,
"ypos": 40,
"color": 1
},
"box5": {
"xpos": 2,
"ypos": 51,
"color": 0
},
"box6": {
"xpos": 23,
"ypos": 9,
"color": 0
},
"box7": {
"xpos": 66,
"ypos": -2
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"2":
{
"box1": {
"xpos": 65,
"ypos": 142,
"color": 0
},
"box2": {
"xpos": -12,
"ypos": 170,
"color": 1
},
"box3": {
"xpos": -12,
"ypos": 132,
"color": 1
},
"box4": {
"xpos": 65,
"ypos": 33,
"color": 1
},
"box5": {
"xpos": 54,
"ypos": -5,
"color": 0
},
"box6": {
"xpos": 5,
"ypos": 2,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 47
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"3":
{
"box1": {
"xpos": -12,
"ypos": 125,
"color": 0
},
"box2": {
"xpos": 26,
"ypos": 167,
"color": 1
},
"box3": {
"xpos": 61,
"ypos": 114,
"color": 1
},
"box4": {
"xpos": 30,
"ypos": 89,
"color": 1
},
"box5": {
"xpos": 65,
"ypos": 40,
"color": 1
},
"box6": {
"xpos": 26,
"ypos": -2,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 47
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"4":
{
"box1": {
"xpos": 86,
"ypos": 107,
"color": 1
},
"box2": {
"xpos": 61,
"ypos": 114,
"color": 1
},
"box3": {
"xpos": 61,
"ypos": 160,
"color": 1
},
"box4": {
"xpos": 44,
"ypos": 167,
"color": 0
},
"box5": {
"xpos": 44,
"ypos": 121,
"color": 1
},
"box6": {
"xpos": -12,
"ypos": 142,
"color": 0
},
"box7": {
"xpos": 47,
"ypos": -5
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"5":
{
"box1": {
"xpos": -12,
"ypos": 170,
"color": 0
},
"box2": {
"xpos": 68,
"ypos": 142,
"color": 0
},
"box3": {
"xpos": 79,
"ypos": 86,
"color": 0
},
"box4": {
"xpos": 51,
"ypos": 61,
"color": 1
},
"box5": {
"xpos": -12,
"ypos": 96,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": 68,
"ypos": -12
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"6":
{
"box1": {
"xpos": -12,
"ypos": 107,
"color": 1
},
"box2": {
"xpos": -12,
"ypos": 181,
"color": 0
},
"box3": {
"xpos": 68,
"ypos": 149,
"color": 0
},
"box4": {
"xpos": 68,
"ypos": 65,
"color": 1
},
"box5": {
"xpos": -12,
"ypos": 96,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": 68,
"ypos": -12
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"7":
{
"box1": {
"xpos": 79,
"ypos": -5,
"color": 1
},
"box2": {
"xpos": 2,
"ypos": 167,
"color": 1
},
"box3": {
"xpos": -30,
"ypos": 177,
"color": 0
},
"box4": {
"xpos": 37,
"ypos": 30,
"color": 1
},
"box5": {
"xpos": -47,
"ypos": 51,
"color": 0
},
"box6": {
"xpos": -47,
"ypos": 26,
"color": 0
},
"box7": {
"xpos": 79,
"ypos": -5
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"8":
{
"box1": {
"xpos": -5,
"ypos": 170,
"color": 1
},
"box2": {
"xpos": 86,
"ypos": 149,
"color": 1
},
"box3": {
"xpos": 40,
"ypos": 82,
"color": 1
},
"box4": {
"xpos": 79,
"ypos": -12,
"color": 0
},
"box5": {
"xpos": -9,
"ypos": 9,
"color": 0
},
"box6": {
"xpos": 40,
"ypos": 82,
"color": 0
},
"box7": {
"xpos": -5,
"ypos": 170
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"9":
{
"box1": {
"xpos": 86,
"ypos": 160,
"color": 1
},
"box2": {
"xpos": 86,
"ypos": -12,
"color": 0
},
"box3": {
"xpos": 9,
"ypos": 9,
"color": 0
},
"box4": {
"xpos": -9,
"ypos": 37,
"color": 0
},
"box5": {
"xpos": -9,
"ypos": 93,
"color": 1
},
"box6": {
"xpos": 47,
"ypos": 72,
"color": 0
},
"box7": {
"xpos": 86,
"ypos": 160
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"0":
{
"box1": {
"xpos": 68,
"ypos": -5,
"color": 0
},
"box2": {
"xpos": -12,
"ypos": 181,
"color": 1
},
"box3": {
"xpos": 68,
"ypos": 153,
"color": 1
},
"box4": {
"xpos": 68,
"ypos": -5,
"color": 0
},
"box5": {
"xpos": 26,
"ypos": -2,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 15,
"color": 0
},
"box7": {
"xpos": -12,
"ypos": 181
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
},
"12":
{
"box1": {
"xpos": 135,
"ypos": 128,
"color": 0
},
"box2": {
"xpos": 100,
"ypos": 142,
"color": 0
},
"box3": {
"xpos": 68,
"ypos": 153,
"color": 0
},
"box4": {
"xpos": 47,
"ypos": 160,
"color": 0
},
"box5": {
"xpos": 26,
"ypos": 167,
"color": 0
},
"box6": {
"xpos": -12,
"ypos": 181,
"color": 0
},
"box7": {
"xpos": -68,
"ypos": 200
},
"box8": {
"width": 10,
"height": 4,
"alpha": 400
}
}
}
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/p5.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/addons/p5.dom.js"></script>
<script language="javascript" type="text/javascript" src=".purview_helper.js"></script>
<script language="javascript" type="text/javascript" src="sketch.js"></script>
<style>
body { padding: 0; margin: 0; }
.inner { position: absolute; }
#controls {
font: 300 12px "Helvetica Neue";
padding: 5;
margin: 5;
background: #f0f0f0;
opacity: 0.0;
-webkit-transition: opacity 0.2s ease;
-moz-transition: opacity 0.2s ease;
-o-transition: opacity 0.2s ease;
-ms-transition: opacity 0.2s ease;
}
#controls:hover { opacity: 0.9; }
</style>
</head>
<body style="background-color:white">
<div class="outer">
<div class="inner">
<div id="canvasContainer"></div>
</div>
<div class="inner" id="controls" height="500px">
<table>
<tr>
<td>Width</td>
<td id="slider15Container"></td>
</tr>
<tr>
<td>Height</td>
<td id="slider16Container"></td>
</tr>
<tr>
<td>Alpha</td>
<td id="slider23Container"></td>
</tr>
<tr>
<td>
<hr>
</td>
</tr>
<tr>
<td>Draw Mode</td>
<td id="modeContainer"></td>
</tr>
<tr>
<td></td>
<td id="buttonContainer"></td>
</tr>
</div>
</div>
</table>
</body>
var main_canvas;
var width_slider;
var height_slider;
var alpha_slider;
var sel_mode;
var canvasWidth = 960;
var canvasHeight = 500;
var savedValues = null;
var initialDrawMode = "exhibition";
var curDrawMode;
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var soloCurLetter = "1";
var soloPrevObj = null;
var soloIsAnimating = false;
var soloNumAnimationFrames = 10;
var soloCurAnimationFrame = 0;
var chosenLetters = ["P", "A", "P", "E", "R"];
var chosenPrevObjs = ["P", "A", "P", "E", "R"];
var chosenIsAnimating = [false, false, false, false, false];
var chosenNumAnimationFrames = 10;
var chosenCurAnimationFrame = [0, 0, 0, 0, 0];
var curChosenLetter = 0;
var lastKeyPressedTime;
var secondsUntilSwapMode = 5;
var lastWordSwappedTime;
var isSwappingWords = true;
var secondsPerWord = 8;
var curSwapWord = 0;
var swapWords = [
"PAPER",
"TWIST",
"FAIRY",
"SHARD",
"DONUT",
"CREPE",
"SKUNK",
"JUDGE",
"DRAIN",
"EXILE",
"AMAZE",
"ASTRO",
"HEART",
"QUEST",
"RIVER",
"BRAIN",
"PLUCK"
]
function preload () {
if (savedValues == null) {
savedValues = loadJSON('alphabet.json');
}
}
function setup () {
main_canvas = createCanvas(canvasWidth, canvasHeight);
angleMode(DEGREES);
var now = millis();
lastKeyPressedTime = now;
lastWordSwappedTime = now - 1000 * (secondsPerWord - 1);
width_slider = createSlider(1, 100, 23);
height_slider = createSlider(-30, 30, 7);
alpha_slider = createSlider(0, 400, 400);
sel_mode = createSelect();
sel_mode.option("alphabet");
sel_mode.option("solo");
sel_mode.option("exhibition")
sel_mode.changed(modeChangedEvent);
sel_mode.value(initialDrawMode);
curDrawMode = initialDrawMode;
button = createButton('show data');
button.mousePressed(buttonPressedEvent);
main_canvas.parent('canvasContainer');
width_slider.parent('slider15Container');
height_slider.parent('slider16Container');
alpha_slider.parent('slider23Container');
sel_mode.parent('modeContainer');
button.parent('buttonContainer');
}
function buttonPressedEvent() {
var obj = sliderToDataObject();
json = JSON.stringify(obj, null, 2);
console.log(json);
}
function modeChangedEvent() {
curDrawMode = sel_mode.value();
}
var colorFront = [220, 187, 255];
var colorBack = [87, 82, 97];
var rotY = 0.0;
var wd = 10;
var xOffset = 16;
var yOffset = 3;
var a = 400;
function draw () {
background(colorBack);
a = alpha_slider.value();
xOffset = width_slider.value();
yOffset = height_slider.value();
var o = 40
var w2 = width - 2 * o
var h2 = height - 2 * o
var cur_index = 0;
var hw = (w2 / 9.0) / 2.0;
var hh = (h2 / 4.0) / 2.0;
if (curDrawMode == "exhibition") {
now = millis();
if(!isSwappingWords && lastKeyPressedTime + 1000 * secondsUntilSwapMode < now) {
isSwappingWords = true;
}
if(isSwappingWords) {
if(lastWordSwappedTime + 1000 * secondsPerWord < now) {
lastWordSwappedTime = now;
curSwapWord = (curSwapWord + 1) % swapWords.length;
for(var i=0; i<5; i++) {
var c = swapWords[curSwapWord][i];
swapExhibitLetter(i, c, i*15);
}
}
}
}
if (curDrawMode == "alphabet") {
for(var j=0; j<4; j++) {
for(var i=0; i<9; i++) {
var cur_letter = letters[cur_index];
var obj = savedValues[cur_letter];
drawFromObject(o + hw + i * w2/9.0, o - 50 + hh + j * h2/4.0, 0.40, obj)
cur_index = cur_index + 1;
}
}
}
else if (curDrawMode == "solo") {
if(soloIsAnimating && soloCurAnimationFrame >= (soloNumAnimationFrames*7)) {
soloIsAnimating = false;
}
if(soloIsAnimating) {
soloCurAnimationFrame = soloCurAnimationFrame + 1;
}
var obj = savedValues[soloCurLetter];
if (soloCurAnimationFrame <= 10) {
obj = computeCurrentSoloChar(7, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
if (soloCurAnimationFrame <= 10) {
soloPrevObj = obj;
}
}
if (soloCurAnimationFrame <= 20 && soloCurAnimationFrame > 10) {
obj = computeCurrentSoloChar(6, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
if (soloCurAnimationFrame <= 20) {
soloPrevObj = obj;
}
}
if (soloCurAnimationFrame <= 30 && soloCurAnimationFrame > 20) {
obj = computeCurrentSoloChar(5, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
if (soloCurAnimationFrame <= 30) {
soloPrevObj = obj;
}
}
if (soloCurAnimationFrame <= 40 && soloCurAnimationFrame > 30) {
obj = computeCurrentSoloChar(4, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
if (soloCurAnimationFrame <= 40) {
soloPrevObj = obj;
}
}
if (soloCurAnimationFrame <= 50 && soloCurAnimationFrame > 40) {
obj = computeCurrentSoloChar(3, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
if (soloCurAnimationFrame <= 50) {
soloPrevObj = obj;
}
}
if (soloCurAnimationFrame <= 60 && soloCurAnimationFrame > 50) {
obj = computeCurrentSoloChar(2, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
if (soloCurAnimationFrame <= 60) {
soloPrevObj = obj;
}
}
if (soloCurAnimationFrame < 70 && soloCurAnimationFrame > 60) {
obj = computeCurrentSoloChar(1, soloCurAnimationFrame%10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
}
if (soloCurAnimationFrame >= 69) {
obj = computeCurrentSoloChar(1, 10);
drawFromObject(o + w2/2.0, o + h2/3.0, 1.0, obj);
}
}
else if (curDrawMode == "exhibition") {
for(var i=0; i<5; i++) {
if(chosenIsAnimating[i] && chosenCurAnimationFrame[i] >= (chosenNumAnimationFrames*7)) {
chosenIsAnimating[i] = false;
}
if(chosenIsAnimating[i]) {
chosenCurAnimationFrame[i] = chosenCurAnimationFrame[i] + 1;
}
var obj = savedValues[curChosenLetter];
if (chosenCurAnimationFrame[i] <= 10) {
obj = computeCurrentChosenChar(7, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
chosenPrevObjs[i] = obj;
}
if (chosenCurAnimationFrame[i] <= 20 && chosenCurAnimationFrame[i] > 10) {
obj = computeCurrentChosenChar(6, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
chosenPrevObjs[i] = obj;
}
if (chosenCurAnimationFrame[i] <= 30 && chosenCurAnimationFrame[i] > 20) {
obj = computeCurrentChosenChar(5, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
chosenPrevObjs[i] = obj;
}
if (chosenCurAnimationFrame[i] <= 40 && chosenCurAnimationFrame[i] > 30) {
obj = computeCurrentChosenChar(4, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
chosenPrevObjs[i] = obj;
}
if (chosenCurAnimationFrame[i] <= 50 && chosenCurAnimationFrame[i] > 40) {
obj = computeCurrentChosenChar(3, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
chosenPrevObjs[i] = obj;
}
if (chosenCurAnimationFrame[i] <= 60 && chosenCurAnimationFrame[i] > 50) {
obj = computeCurrentChosenChar(2, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
chosenPrevObjs[i] = obj;
}
if (chosenCurAnimationFrame[i] < 70 && chosenCurAnimationFrame[i] > 60) {
obj = computeCurrentChosenChar(1, chosenCurAnimationFrame[i]%10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
}
if (chosenCurAnimationFrame[i] >= 69) {
obj = computeCurrentChosenChar(1, 10, i);
drawFromObject(o + w2/12.0 + i*w2/5.0, o + h2/3.0, 1.0, obj);
}
}
}
}
function drawFromObject (xPosition, yPosition, sz, obj) {
push();
translate(xPosition, yPosition);
scale(sz, sz);
var highlight = color(255,200,200,a);
var shadow = color(220, 120, 120, a);
stroke(red(shadow)-30, green(shadow)-30, blue(shadow)-30);
col1 = lerpColor(highlight, shadow, obj["box1"]["color"]);
col2 = lerpColor(highlight, shadow, obj["box2"]["color"]);
col3 = lerpColor(highlight, shadow, obj["box3"]["color"]);
col4 = lerpColor(highlight, shadow, obj["box4"]["color"]);
col5 = lerpColor(highlight, shadow, obj["box5"]["color"]);
col6 = lerpColor(highlight, shadow, obj["box6"]["color"]);
drawPart(obj["box1"]["xpos"], obj["box1"]["ypos"], obj["box2"]["xpos"], obj["box2"]["ypos"], col1, xOffset, yOffset);
drawPart(obj["box2"]["xpos"], obj["box2"]["ypos"], obj["box3"]["xpos"], obj["box3"]["ypos"], col2, xOffset, yOffset);
drawPart(obj["box3"]["xpos"], obj["box3"]["ypos"], obj["box4"]["xpos"], obj["box4"]["ypos"], col3, xOffset, yOffset);
drawPart(obj["box4"]["xpos"], obj["box4"]["ypos"], obj["box5"]["xpos"], obj["box5"]["ypos"], col4, xOffset, yOffset);
drawPart(obj["box5"]["xpos"], obj["box5"]["ypos"], obj["box6"]["xpos"], obj["box6"]["ypos"], col5, xOffset, yOffset);
drawPart(obj["box6"]["xpos"], obj["box6"]["ypos"], obj["box7"]["xpos"], obj["box7"]["ypos"], col6, xOffset, yOffset);
pop();
}
function drawPart (xval1, yval1, xval2, yval2, col, xDiff, yDiff) {
push();
beginShape(QUADS);
fill(col);
vertex(xval1 - xDiff, yval1 - yDiff);
vertex(xval2 - xDiff, yval2 - yDiff);
vertex(xval2 + xDiff, yval2 + yDiff);
vertex(xval1 + xDiff, yval1 + yDiff);
endShape();
pop();
}
function swapExhibitLetter(n, c, frameDelay) {
chosenPrevObjs[n] = computeCurrentChosenChar(0, 0, n);
chosenLetters[n] = c;
chosenIsAnimating[n] = true;
chosenCurAnimationFrame[n] = 0 - frameDelay;
}
function computeCurrentChosenChar(partIndex, frameNum, n) {
var obj;
var indexes = [1,2,3,4,5,6,7];
var movingPart = partIndex;
indexes.splice(partIndex-1, 1);
if (chosenIsAnimating[n]) {
if(chosenCurAnimationFrame[n] < 0) {
obj = chosenPrevObjs[n];
} else {
nextObj = savedValues[chosenLetters[n]];
obj = {};
for (var i = 0; i < 6; i++) {
if (indexes[i] != 7) {
obj["box"+indexes[i]] = {};
obj["box"+indexes[i]]["xpos"] = chosenPrevObjs[n]["box"+indexes[i]]["xpos"];
obj["box"+indexes[i]]["ypos"] = chosenPrevObjs[n]["box"+indexes[i]]["ypos"];
obj["box"+indexes[i]]["color"] = chosenPrevObjs[n]["box"+indexes[i]]["color"];
} else {
obj["box"+indexes[i]] = {};
obj["box"+indexes[i]]["xpos"] = chosenPrevObjs[n]["box"+indexes[i]]["xpos"];
obj["box"+indexes[i]]["ypos"] = chosenPrevObjs[n]["box"+indexes[i]]["ypos"];
}
}
if (indexes[i] != 7) {
obj["box"+movingPart] = {};
obj["box"+movingPart]["xpos"] = map(frameNum, 0, chosenNumAnimationFrames, chosenPrevObjs[n]["box"+movingPart]["xpos"], nextObj["box"+movingPart]["xpos"]);
obj["box"+movingPart]["ypos"] = map(frameNum, 0, chosenNumAnimationFrames, chosenPrevObjs[n]["box"+movingPart]["ypos"], nextObj["box"+movingPart]["ypos"]);
obj["box"+movingPart]["color"] = map(frameNum, 0, chosenNumAnimationFrames, chosenPrevObjs[n]["box"+movingPart]["color"], nextObj["box"+movingPart]["color"]);
} else {
obj["box"+movingPart] = {};
obj["box"+movingPart]["xpos"] = map(frameNum, 0, chosenNumAnimationFrames, chosenPrevObjs[n]["box"+movingPart]["xpos"], nextObj["box"+movingPart]["xpos"]);
obj["box"+movingPart]["ypos"] = map(frameNum, 0, chosenNumAnimationFrames, chosenPrevObjs[n]["box"+movingPart]["ypos"], nextObj["box"+movingPart]["ypos"]);
}
}
}
else {
obj = savedValues[chosenLetters[n]];
}
return obj;
}
function computeCurrentSoloChar(partIndex, frameNum) {
var obj;
var indexes = [1,2,3,4,5,6,7];
var movingPart = partIndex;
indexes.splice(partIndex-1, 1);
if (soloIsAnimating) {
nextObj = savedValues[soloCurLetter];
obj = {};
for (var i = 0; i < 6; i++) {
if (indexes[i] != 7) {
obj["box"+indexes[i]] = {};
obj["box"+indexes[i]]["xpos"] = soloPrevObj["box"+indexes[i]]["xpos"];
obj["box"+indexes[i]]["ypos"] = soloPrevObj["box"+indexes[i]]["ypos"];
obj["box"+indexes[i]]["color"] = soloPrevObj["box"+indexes[i]]["color"];
} else {
obj["box"+indexes[i]] = {};
obj["box"+indexes[i]]["xpos"] = soloPrevObj["box"+indexes[i]]["xpos"];
obj["box"+indexes[i]]["ypos"] = soloPrevObj["box"+indexes[i]]["ypos"];
}
}
if (indexes[i] != 7) {
obj["box"+movingPart] = {};
obj["box"+movingPart]["xpos"] = map(frameNum, 0, soloNumAnimationFrames, soloPrevObj["box"+movingPart]["xpos"], nextObj["box"+movingPart]["xpos"]);
obj["box"+movingPart]["ypos"] = map(frameNum, 0, soloNumAnimationFrames, soloPrevObj["box"+movingPart]["ypos"], nextObj["box"+movingPart]["ypos"]);
obj["box"+movingPart]["color"] = map(frameNum, 0, soloNumAnimationFrames, soloPrevObj["box"+movingPart]["color"], nextObj["box"+movingPart]["color"]);
} else {
obj["box"+movingPart] = {};
obj["box"+movingPart]["xpos"] = map(frameNum, 0, soloNumAnimationFrames, soloPrevObj["box"+movingPart]["xpos"], nextObj["box"+movingPart]["xpos"]);
obj["box"+movingPart]["ypos"] = map(frameNum, 0, soloNumAnimationFrames, soloPrevObj["box"+movingPart]["ypos"], nextObj["box"+movingPart]["ypos"]);
}
}
else {
obj = savedValues[soloCurLetter];
}
return obj;
}
function keyTyped() {
if (key == '!') {
saveBlocksImages();
}
else if (key == '@') {
saveBlocksImages(true);
}
else {
lastKeyPressedTime = millis();
if(isSwappingWords) {
isSwappingWords = false;
}
upper_key = key.toUpperCase();
if (upper_key in savedValues) {
if(curDrawMode == "solo") {
soloPrevObj = savedValues[soloCurLetter];
soloCurLetter = upper_key;
soloIsAnimating = true;
soloCurAnimationFrame = 0;
}
else if(curDrawMode == "exhibition") {
if (!chosenIsAnimating[curChosenLetter]) {
swapExhibitLetter(curChosenLetter, upper_key, 0);
curChosenLetter = (curChosenLetter + 1) % 5;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment