Crickets Chirping

mon qui si, mon qui d’où

Archive for November, 2008

Guilloches

with 2 comments

I was inspired by this post on Guilloches to generate them in Processing (It’s been that kind of weekend. At least my unit tests are passing now :)

Click here to try out the applet

Or check out these stills:

This basically look like spirographs for now, but I’m sure there are ways to make them more interesting. Maybe have the extended cycloid follow some other curve besides a circle.

Written by banksean

November 24th, 2008 at 1:00 am

Posted in Code,General,Processing

A 16,777,216 Color Picture

with one comment

I was bored waiting for some unit tests to run and I ran across allRGB: images made from all the colors in the 24-bit RGB space, none missing and none repeated. Each color is used by exactly one pixel.

I love challenges/constraints like this. Here’s my 4096×4096 pixel image:

These are scaled down. The full size image doesn’t compress very well, and if you want to see it up close you can just use the Processing source code at the end of this post.

Algorithm rough outline: first fill up the 4096×4096 pixel array with all the distinct integers in that range, in increasing order. Then scan all the pixels in order, swapping each with a neighbor located nearby adjusted by some sinusoidal terms. The swap operation preserves the 1-1 mapping of pixels to colors. Then count the colors to make sure you didn’t miss one, or have any duplicates. I came up with a way to do this check, but I thought it was pretty brain dead. Turns out it’s the recommended way to do it over on Stack Overflow.

Source (wouldn’t dare embed this as an applet):

int HEIGHT=800;
int WIDTH=800;

PImage img;
boolean saved = false;

void setup() {
  size(WIDTH, HEIGHT);
}

void draw() {
  if (img == null) {
    img = createImage(4096, 4096, RGB);
    for(int i=0; i < img.pixels.length; i++) {
      img.pixels[i] = i;
    }
  }

  for(int x=0; x < img.width; x++) {
    for(int y=0; y < img.height; y++) {
      double i = Math.sqrt(Math.pow(img.width/2 - (x % img.width/2), 2) +
        Math.pow(img.height/2 - (y % img.height/2), 2));
      int x2 = x + (int)(Math.sin(i*0.001*PI) * i);
      int y2 = y + (int)(Math.cos(i*0.001*PI) * i);
      swapPixels(x, y, x2, y2);
    }
  }

  image(img, 0, 0, WIDTH, HEIGHT);
  if (!saved) {
    img.save("rgb.png");
    saved = true;
    checkColorsUsed();
  }
}

void swapPixels(int x1, int y1, int x2, int y2) {
  x1 = x1 % img.width;
  if (x1 < 0) { x1 = img.width + x1; }
  x2 = x2 % img.width;
  if (x2 < 0) { x2 = img.width + x2; }
  y1 = y1 % img.height;
  if (y1 < 0) { y1 = img.height + y1; }
  y2 = y2 % img.height;
  if (y2 < 0) { y2 = img.height + y2; }

  swapPixels(x1 + y1*img.width, x2 + y2*img.width);
}

void swapPixels(int i, int j) {
    int a = img.pixels[i];
    int b = img.pixels[j];
    img.pixels[j] = a;
    img.pixels[i] = b;
}

void checkColorsUsed() {
  System.out.println("scanning colors");

  boolean colorsUsed[] = new boolean[img.pixels.length];
  for (int i = 0; i < img.pixels.length; i++) {
    if (colorsUsed[img.pixels[i]]) {
      System.out.println("duplicate: " + img.pixels[i]);
    }
   colorsUsed[img.pixels[i]] = true;
  }

  System.out.println("counting colors");

  for (int i=0; i < colorsUsed.length; i++) {
    if(!colorsUsed[i]) {
      System.out.println("unused: " + i);
    }
  }

  System.out.println("color check complete");
}



If you want to run it from Processing, you’ll probably have to increase the maximum available memory to some very large number (it’s in the Preferences window).

I love writing sloppy crap in processing because the code really doesn’t matter :)

I would have posted this image to allRGB, but they want you to sign up for an account on some other site first. Shrug.

Written by banksean

November 23rd, 2008 at 2:35 am

Posted in Processing

Hypothetically Speaking

with one comment

The other day I set my gchat status message to a quote from a 30 Rock episode:

I don’t believe in hypothetical situations. That’s like lying to your brain.

Josh IM’d me in response:

what if it’s only a “hypothetical situation” because you aren’t aware that it is an actual situation?

Me: I see what you did there. nice try.

Written by banksean

November 14th, 2008 at 1:09 am

Posted in General

Ramble: Japanese Infographics, Album Art

with 3 comments

(via (via)):

I recommend watching Ensuring Food Security in hi-def. I’m impressed by the level of detail they present, given the complexity of the issues. It’s in Japanese but it is subtitled in English. I think it’s wonderful, aside from the background music which is distracting (to me at least).

I wonder what this movie would look like if it were redone for the U.S. audience. A lot of issues would be the same- especially the reliance on corn, fat and oils. On the other hand, I feel like the presentation and level of detail would be too much for the average consumer here in the states to pay attention long enough to grok it. Or maybe I’ve just been conditioned to believe that based on the quality of PSAs we’ve enjoyed for so many years.



I love this isometric aesthetic. This particular frame:

reminded me of Josh Keyes:

The album cover, jacket and disc for Brad Laner’s Neighbors Singing feature Keyes’ work, and I just so happened to get it in the mail the other day.

I don’t even own a record player. I actually bought this LP just because I wanted the artwork.

But after listening to the album (it came with a card printed with a link to download the mp3s) I really kinda dig it. Reminds me of Caribou. Reading more about Laner, I found out he was in a band called Medicine from the early 90′s, and I rather liked them already.

Written by banksean

November 12th, 2008 at 3:09 am

Posted in General