TAD2011.07 Color Nav

My seventh TAD project is a Processing sketch that creates a sort of image map based on colors. To demonstrate, click on the below image. Clicking the blue circle will open one Wikipedia page (in a new window); clicking the red square will open a different Wikipedia page. Note that the links work even though the circle and square intersect. That is because when you click on the image, the sketch retrieves the pixel color at your mouse position; if the color is red, the sketch opens one link; if the color is blue, the sketch opens a different link.

The example here is quite simple, but imagine a sketch that returns esoteric qualities of a color when you select that color from an image of a Tarot card.

Source code:

PImage circleSquare;

void setup() {
  size(170, 100);
  circleSquare = loadImage("circle_square.png");
}

void draw() {
  background(0);
  image(circleSquare, 0, 0);
}

void mousePressed() {
  int theColor = circleSquare.get(mouseX, mouseY);
  if(theColor == color(255, 0, 0)) { // red
    link("http://en.wikipedia.org/wiki/Red_Square", "_new");
  } else if(theColor == color(0, 0, 255)) { // blue
    link("http://en.wikipedia.org/wiki/Blue_Circle_Industries", "_new");
  }
}

TAD2011.06 Lorenz Attractor

Sixth TAD project. Draws Lorenz attractors. The algorithm I am using is from Clifford Pickover’s Computers and the Imagination: Visual Adventures Beyond the Edge. Click within the white square, below, to draw a new attractor:

Source code:

/**
 * LorenzAttractor
 * by Joshua Madara, hyperRitual.com
 * Adapted from Clifford Pickover's
 * _Computers and the Imagination_, p.125.
 * Click in the display area to generate a new drawing.
 */

// define variables
float h = 0.01;
int npts = 4000;
float frac = 8 / 3;
float x = 0.6;
float y = 0.6;
float z = 0.6;
float xNew;
float yNew;
float zNew;

void setup() {
  size(400, 400);
  background(0);
  stroke(255, 127);
  smooth();
}

void draw() {
  // draw border
  line(0, 0, width-1, 0);
  line(width-1, 0, width-1, height-1);
  line(width-1, height-1, 0, height-1);
  line(0, height-1, 0, 0);
}

void mousePressed() {
  background(0);
  translate(width/2, height/2);
  // draw attractor
  for(int i=0; i<npts; i++) {
    xNew = x + h*10*(y-x);
    yNew = y + h*((-x*z) + 28*x-y);
    zNew = z + h*(x*y - frac*z);
    line(x*(width/50), y*(height/50), xNew*(width/50), yNew*(height/50));
    x = xNew; y = yNew; z = zNew;
    // println("x:"+x+" y:"+y+" z:"+z);
  }
  translate(-(width/2), -(height/2));
}

TAD2011.05 Labeled Graph Maker

Fifth TAD project. Similar to yesterday’s, but labels each node with a sequential number.

Labeled Graph Maker

Source code:

/**
 * LabeledGraphMaker
 * by Joshua Madara, hyperRitual.com
 * This sketch draws complete graphs from 1 to 20 nodes,
 * and labels each node with a sequential number.
 * The vertex calculations are based on Ira Greenberg's
 * Poly Maker from _Processing: Creative Coding and 
 * Computational Art_, pp. 229-230.
 * Move your mouse left/right across the drawing to 
 * decrease/increase the size of the graph.
 */

PFont nanoSansLC;
int minNodes = 1;
int maxNodes = 20;

void setup() {
  size(400, 400);
  background(0);
  smooth();
  fill(0);
  stroke(255);
  strokeWeight(1);
  ellipseMode(CENTER);
  nanoSansLC = loadFont("NanoSansLC.vlw");
  textFont(nanoSansLC);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(0);
  // vary # of nodes by mouse's horizontal position
  int varNodes = round(map(mouseX, 0, width, minNodes, maxNodes));
  // calc # of edges from # of nodes
  int edges = varNodes*(varNodes - 1)/2;
  // call function to draw graph
  makeGraph(width/2, height/2, varNodes, width/2.5);
}

void makeGraph(int x, int y, int nodes, float radius) {
  float[] px = new float[nodes];
  float[] py = new float[nodes];
  float angle = 270;
  // calculate and store vertex positions
  for(int i=0; i<nodes; i++) {
    px[i] = x+cos(radians(angle))*radius;
    py[i] = y+sin(radians(angle))*radius;
    angle+=360.0/nodes; // 360/nodes returns int; need float
  }
  // draw edges
  for(int j=0; j<nodes; j++) {
    for(int k=1; k<nodes; k++) {
      line(px[j], py[j], px[k], py[k]);
    }
  }
  // draw labeled nodes
  for(int j=0; j<nodes; j++) {
    fill(0);
    ellipse(px[j], py[j], width/8, height/8);
    fill(255);
    text(j+1, px[j], py[j]);
  }
}

Graph Maker

Fourth TAD project. Unfortunately, some personal matters have become more pressing such that I may need to soon bow out of this year’s TAD having barely begun.

I am uncertain what it is that so fascinates me about graphs such as those generated here, but it has long been part of my interest in the occult and its circles, triangles, squares, pentagrams, hexagrams, etc. Geometry was one of my favorite subjects in school, and I often fantasized about what goes on at the corners of these shapes, what happens to us when we gain or lose a dimension.

This is my first time using Processing.js with Keyvan Minoukadeh‘s Processing JS WordPress plugin, so you can play with the sketch right here on this page, and do not need Java (move your mouse around the image until you see interaction):

Source code:

/**
 * GraphMaker
 * by Joshua Madara, hyperRitual.com
 * This sketch draws complete graphs from 1 to 20 nodes.
 * The vertex calculations are based on Ira Greenberg's
 * Poly Maker from _Processing: Creative Coding and 
 * Computational Art_, pp. 229-230.
 * Move your mouse left/right across the drawing to 
 * decrease/increase the size of the graph.
 */

int minNodes = 1;
int maxNodes = 22;

void setup() {
  size(400, 400);
  background(0);
  smooth();
  noFill();
  stroke(255);
  strokeWeight(1);
  ellipseMode(CENTER);
}

void draw() {
  background(0);
  // vary # of nodes by mouse's horizontal position
  int varNodes = round(map(mouseX, 0, width, minNodes, maxNodes));
  // calc # of edges from # of nodes
  int edges = varNodes*(varNodes - 1)/2;
  // display # of vertices and # of edges
  text("vertices: "+varNodes+"  edges: "+edges, 5, 15);
  // call function to draw graph
  makeGraph(width/2, height/2, varNodes, width/2.5);
}

void makeGraph(int x, int y, int nodes, float radius) {
  float[] px = new float[nodes];
  float[] py = new float[nodes];
  float angle = 270;
  // calculate and store vertex positions
  for(int i=0; i<nodes; i++) {
    px[i] = x+cos(radians(angle))*radius;
    py[i] = y+sin(radians(angle))*radius;
    angle+=360.0/nodes; // 360/nodes returns int; need float
  }
  // draw nodes and edges
  for(int j=0; j<nodes; j++) {
    ellipse(px[j], py[j], width/9, height/9);
    for(int k=1; k<nodes; k++) {
      line(px[j], py[j], px[k], py[k]);
    }
  }
}

TAD2011.03 Planetary Color Grid

Third TAD project. I intend to use the 2D array in future sketches.

Planetary Color Grid

Source code:

/**
 * PlanetaryColorGrid
 * by Joshua Madara, hyperRitual.com
 * This project displays a grid of the planetary colors
 * for each hour * day of the week, per "Table of the Planetary 
 * Hours" from the "Introduction" to Mathers' _The Key of 
 * Solomon the King_. The colors are specified in the 
 * same book: "Table of the Archangels, Angels, Metals, 
 * Days of the Week, and Colours Attributed to each Planet."
 */

// set color for each planet
color MER = #800080; // Mercury, Purple
color MOO = #FFFFFF; // Moon, White
color SAT = #000000; // Saturn, Black
color JUP = #0000FF; // Jupiter, Blue
color MAR = #FF0000; // Mars, Red
color SUN = #FFFF00; // Sun, Yellow
color VEN = #008000; // Venus, Green

// create 2D array to store color by hour (row) and day (column)
color[][] TBL = {
// SUN,MON,TUE,WED,THU,FRI,SAT
  {MER,JUP,VEN,SAT,SUN,MOO,MAR}, // 12 AM
  {MOO,MAR,MER,JUP,VEN,SAT,SUN}, // 1
  {SAT,SUN,MOO,MAR,MER,JUP,VEN}, // 2
  {JUP,VEN,SAT,SUN,MOO,MAR,MER}, // 3
  {MAR,MER,JUP,VEN,SAT,SUN,MOO}, // 4
  {SUN,MOO,MAR,MER,JUP,VEN,SAT}, // 5
  {VEN,SAT,SUN,MOO,MAR,MER,JUP}, // 6
  {MER,JUP,VEN,SAT,SUN,MOO,MAR}, // 7
  {MOO,MAR,MER,JUP,VEN,SAT,SUN}, // 8
  {SAT,SUN,MOO,MAR,MER,JUP,VEN}, // 9
  {JUP,VEN,SAT,SUN,MOO,MAR,MER}, // 10
  {MAR,MER,JUP,VEN,SAT,SUN,MOO}, // 11
  {SUN,MOO,MAR,MER,JUP,VEN,SAT}, // 12 PM
  {VEN,SAT,SUN,MOO,MAR,MER,JUP}, // 1
  {MER,JUP,VEN,SAT,SUN,MOO,MAR}, // 2
  {MOO,MAR,MER,JUP,VEN,SAT,SUN}, // 3
  {SAT,SUN,MOO,MAR,MER,JUP,VEN}, // 4
  {JUP,VEN,SAT,SUN,MOO,MAR,MER}, // 5
  {MAR,MER,JUP,VEN,SAT,SUN,MOO}, // 6
  {SUN,MOO,MAR,MER,JUP,VEN,SAT}, // 7
  {VEN,SAT,SUN,MOO,MAR,MER,JUP}, // 8
  {MER,JUP,VEN,SAT,SUN,MOO,MAR}, // 9
  {MOO,MAR,MER,JUP,VEN,SAT,SUN}, // 10
  {SAT,SUN,MOO,MAR,MER,JUP,VEN}, // 11
};

// variable x and y positions for each square in grid
int xPos = 0;
int yPos = 0;

void setup() {
  size(70, 240); // columns * 10, rows * 10
  noStroke(); // fill only
  noLoop(); // draw once
}

void draw() {
  yPos = 0;
  for(int i = 0; i < 24; i++) { // for all rows
    xPos = 0;
    for(int j = 0; j < 7; j++) { // for all columns
      fill(TBL[i][j]); // set color of square
      rect(xPos, yPos, 10, 10); // draw square
      xPos += 10; // move to draw next column
    }
    yPos += 10; // move to draw next row
  }
}