fogbound.net




Page 1 of 2912345...1020...Last »

Wed, 27 Sep 2017

Seasonal Palettes

— SjG @ 7:43 pm

Over the years, I’ve written various JavaScript mandala-generators. I like giving variety to the color sets used, and in the past, I’ve hand-crafted collections of colors which I’ve given descriptive names like “Earthy,” “Angst,” and “Scorchio.”

For a new project, I wanted seasonal palettes. Being a northern-hemisphere dweller, I think of January as cool colors, May as yellows and greens, August as ambers and oranges, etc. Rather than hand assemble them, I thought this would be a good use for the Interwebs.

So I wrote a bash/php/ImageMagick script that would hit flickr.com with a seasonal search term to bring back the first twenty-five matching pictures. It then made a composite of the pictures, did a pixelation process, reduced the colors to a minimum set, and built a palette from them.

With excuses of fair use, here’s a visual of that process, using the example where the search terms were “Landscape July”:

1. Images are brought down, each scaled to fit in a 64 x 64 pixel square, and then they’re all combined into a single image.

2. The combined image is pixelated by scaling to 5% of the original size, then scaling back up to a larger size.

3. To get a little more punch and a little less muddy, the pixelated image has its histogram equalized

4. For good measure, the script then reduces the image to 32 colors.

Now, some of this may be redundant. For example, we could easily skip step 2, since we’re reducing colors in step 4. However, this way we sort of reduce the color space before we equalize the histogram. Maybe I should experiment with other paths here.

In any case, the results for my first search term “($month) Landscape” was not very good:

I tried some other search terms for good measure.

Here’s “($month) colors”:

Here’s “($month) thoughts”:

And finally, here’s “($month) skies”:

I have a few conclusions. First, it’s obvious that a hand-created set of palettes would be better. The pictures Flickr returned for each search term didn’t match my expectations very well. Perhaps I’d have done better with season names instead of month names. Lastly finding the best palette from an image is a problem that Google tells me many have worked on. I’m assuming others have probably done better than I.

But it’s a curious question — what are the “characteristic” colors from an image? My approach largely comes down to the number of pixels of a given general color. Are there lots of blues? My approach will have at least some blue. But if an accent color is “important,” whatever that means, my approach will probably lose it.

In any case, it’s probably back to mandalas and hand-crafted palettes for the next project.


Mon, 16 May 2016

Airships

— SjG @ 6:13 pm

The Goodyear Blimp was passing overhead. It’s noisy! Since it was pretty low, I tried to take an iPhone picture. In the shot, I got a serendipitous cameo by one of the local Anna’s Hummingbirds.

Serendipity

Click to see bigger.


Sat, 19 Mar 2016

Kwan Yin Stereogif

— SjG @ 9:08 am

Equinox in the Garden.

KwanYin

Stereo separation’s a little too wide on this experiment. I think it might be time to fabricate a precise positioning rig for my tripod… another project on the list.


Sat, 20 Feb 2016

Anniversary Game

— SjG @ 10:17 pm

So, for our tenth anniversary, I thought I’d make something slightly more … dynamic … than your standard Hallmark card. I thought a simple JavaScript game might be fun.

Since everyone knows that a happy marriage is made of unicorns and rainbows, I figured I’d work with that. My first though was a single-level platform game. I looked at a number of JavaScript game frameworks, and they were all either much too simplistic or much to complicated for what I wanted to do. I spent too much time in the process of starting a game with a new framework, getting frustrated, and then abandoning it. Oh no! I was running out of time!

I decided to bail on frameworks, and just write a quick, simple, pure JavaScript game. I would use animated GIFs as sprites, and do the rest in Canvas. Seems easy.

I raided the usual sources for my assets. I needed a unicorn, so I gave a horn to the Wikipedia running horse animated GIF (which itself is derived from Muybridge’s photos) and knocked out the background. It looked pretty good on a white background!
ur
I then made some animating rainbow hearts, and I was ready.

After the initial stab at coding, unicorns would run back and forth, and rainbows appeared where the user clicked. If the unicorn was within the rainbow ring, I’d register the hit. I was well on my way.

Next, I added the score animations. I was impressed by how smoothly the animation all worked. On a reasonably recent machine, browsers keep up very nicely. Then I went and tested on iOS. Uh-oh. I’d not been very careful about browser size. I ended up recoding the CSS and dimension code to be more or less responsive. OK, seemed good. I added an explosion of hearts effect for when you hit the unicorn. Next, I found a nice source for sounds.

One of the problems I faced was that I was trying to develop the project while sitting on the sofa in the evenings. I’d come home from a long day of coding, and, well, start coding. But then Elizabeth would come home, and I’d have to keep switching windows to avoid creating suspicion. This is where the ability to disable the audio came in. Over the course of a week, I was able to polish it up enough for deployment. It’s far from perfect, but it was well received.

game-1

game-2

Play it yourself, or use the code to create your own game.

Some Lessons Learned:

  • Players will resize the window in the middle of a game. The code should probably trap for that, and do the right thing.
  • I expected players to launch a single rainbow at a time. In fact, there was a whole lot more clicking than that.
  • It might be faster to write a game from scratch, but seriously, take the time to learn a framework and use it. With any luck, it will handle all those weird edge cases, and probably have better support for odd platforms.
  • Sound in JavaScript is nasty, and not very portable. Again, use a framework (or commit to modern browsers, and use Web Audio API).
  • Responsive design is all good, but for a game, it might make sense to commit to a fixed size for playability.
  • Under iOS, things don’t work quite as you’d expect. This game should have been optimized, and used something like the touchAction style to improve playability. Better yet, I should have created a native version with PhoneGap.

Wed, 27 Jan 2016

Onion Texture in Javascript and Canvas

— SjG @ 9:23 pm

When I’m focused on other things and doodling, one of the textures that regularly emerges is a fill pattern of concentric irregular circles.

onions_1
(click to enlarge)

Now, doodling is a way of letting my mind idle. Why I’d want to automate that, I couldn’t say. But for some reason, I did.

So the question was: how do I draw a “sloppy circle,” or one that’s not exactly regular, especially if I want to then draw another similar circle inside of it, and so on.

I settled on the idea of picking a set of points around a circle, with roughly the same radius. If I just drew a line between these points, it would be a regular polygon, and not as gentle as I’d like. So, instead of lines, I needed gentle Bezier curves from point to point.

To get the Bezier control points, I need to create a tangent to the radial line, and put the control points for the curve on that tangent. But how far away from the original point? Better make it a variable!

So, with some playing, I was able to get reasonable values.

You can play with it yourself!

You can easily get results like these:
onions_2

onions_5

onions_3

onions_4
(click to enlarge any of them)

onion_exp_f

Page 1 of 2912345...1020...Last »