Archive for the 'JavaScript' category

New JS Library: grid

Aug 02 2014 Published by under JavaScript

Send to Kindle

I’m continuing to dig through old code and consolidate and release it.

This new library, grid, is not a CSS layout util, but draws grids of various kinds on an HTML5 Canvas. Here’s a demo of the various kinds of grids it can currently draw. Click for full size.

demo

I could go into all the options and so forth, but it’s all pretty straightforward and you can just check the readme at the github site:

https://github.com/bit101/grid

There may be some minor bugs in this or some tweaks needed. If so, just let me know, and I’ll fix it up. There’s definitely a lot of optimization that can go on here. I may experiment with creating an offscreen canvas the size of one cell, drawing one cell there, and then blitting that across the rest of the grid. We’ll see. In the meantime, it mostly works. Enjoy.

Send to Kindle

No responses yet

New JS Library: Shapes

Jul 21 2014 Published by under JavaScript

Send to Kindle

Another week, another JS library.

https://github.com/bit101/shapes

Again, I’m sure there are hundreds of other libraries that add improved functionality for Canvas drawing. There’s even CreateJS, which is super powerful, creating a Flash-like display list with animation, etc. That’s cool, but it kind of becomes a framework that you need to buy into fully. My goal was not to create a new paradigm, just make the existing one a bit easier to work with.

Almost everything in the library is stuff that I’ve created before. Again, I just decided to consolidate it all into one code base, clean it all up and put it up on github. If nothing else, I won’t need to write that stuff again. And if someone else finds it useful, either as a whole, or something to borrow bits and pieces from, that’s great.

Like the shaky library from last week, shapes wraps both the Canvas and Context2D. I’ve proxied most of the existing Context2D methods to the shapes object, so you can work directly from that for 99% of what you need to do. A lot of it is obvious stuff – circles, ellipses, rounded rects, polygons, etc. But there are some unique and fun items in there as well. Explore. The demo page will give you a few ideas of what’s possible.

http://www.bit-101.com/bitlib/shapes/

The source for the whole demo page is in the repo as well, so you can easily see the code that is used to create the examples.

Send to Kindle

2 responses so far

shaky Library for HTML/Canvas/JS

Jul 15 2014 Published by under JavaScript

Send to Kindle

A few days ago, I released my clrs color library for HTML/JS/Canvas/CSS. It’s not that I thought it was revolutionary or anything. In fact I’d be surprised if you couldn’t dig up at least a dozen other similar libraries out there. I’ve already been shown two. But it was code that I’d written myself a few times, so I consolidated it all into one place and put it on line. If nothing else, it will keep me from writing it again. And judging from the number of favorites and retweets on twitter, it seems like others thought it might be useful as well. If one person uses it and likes it, my job is done.

It’s occurred to me that I’ve written a lot of other code over the last few years that has never seen the light of day. Some has been for my Art From Code site, for other apps or experiments I’ve done, and other ideas that I’ve just messed around with and never did a damned thing with. So rather than keeping that stuff all on a hard drive somewhere, I’m slowly gathering it together, cleaning it up, rewriting some of it, and releasing it, bit by bit. Again, maybe nobody will find this stuff useful. Maybe there are other similar projects out there. But I’m going to github it so it’s in one place where I can find it, and if anyone else can possibly benefit from it, that’s just icing on the cake.

The next library I’ve just released is called “shaky”. I first did this in ActionScript years ago, and more recently in Canvas. It’s simple enough, it draws shaky lines and shapes. The problem, if you want to call it a problem, with computer drawing, is that all the lines are perfectly straight. It’s good in most cases, but sometimes you want to replicate a hand-drawn look, or just mix it up a bit and draw some jittery lines. You’ll probably never need it, but if you do, here it is:

https://github.com/bit101/shaky

It basically wraps the canvas and context 2d. So you can call most of the usual Canvas drawing methods like moveTo, lineTo, rect, arc, quadraticCurveTo, bezierCurveTo, and instead of drawing perfect shapes, it will draw shaky versions. I’ve also added some convenience methods like circle, ellipse, and fill and stroke versions of those, as well as setSize and clear methods. Other methods like beginPath, stroke, fill, clearRect are proxied right through to the context2d object, so you can do most of your drawing without ever accessing the context itself.

The shakiness of the drawing is utterly tweakable via two properties, segSize and shake. Any single line will be broken down into a series of short line segments. The rough length of these segments is controlled by segSize. And the shake property controls how much randomness will be applied to each segment.

The following image demonstrates these two properties interacting. Here, shake is increasing left to right, and segSize is decreasing top to bottom.

At the top left is 0 shake and a large segSize. This gives you straight lines. At the bottom right is a large shake and small segSize. This gives you lots of individual segments, each of which is randomly offset by a lot. You can crank that up even higher and get complete chaos.

But tweaked just right, somewhere in the middle, you get stuff that looks a lot like hand-drawn lines. Useful? You tell me.

Send to Kindle

No responses yet

clrs: A Color Library for HTML/JS/CSS/Canvas

Jul 13 2014 Published by under JavaScript

Send to Kindle

As most of you know, I grew up as a programmer using Flash and ActionScript, and in the last few years have been much more into web programming, particularly with HTML’s Canvas. In general I do like Canvas a lot. It’s a different mindset than Flash, but I enjoy the challenge.

One thing that has consistently annoyed me, though, is using colors. In ActionScript, colors were 24-bit or 32-bit numbers. So they were easy to manipulate. Want RGB? 0xffcc00. Combine channels? red << 16 | green << 8 | blue. Extract a channel? red = color >> 16, green = color >> 8 & 0xff, blue = color & 0xff. Because everything is numbers, numbers, numbers, it’s super easy to create random colors, tween colors, generate colors based on any math formula, etc.

Then you get into HTML/CSS/JS/Canvas. It’s all strings. You can do named CSS color: “cornflowerblue” or hex values “#ffcc00″ and you can even do rgb/rgba: “rgb(255,128,0)” or “rgb(255,128,0,0.5)”. It looks all about as easy as ActionScript until you actually try to do it. Those rgb numbers must be integers, so if you have red, green blue values that might be floating point numbers, its:

"rgb(" + Math.round(red) + "," + Math.round(green) + "," + Math.round(blue) + ")";

GAH! You write that a few times and you want to kill someone.

So I’d usually write some kind of function that would deal with that.

function rgb(red, green, blue) {
    return "rgb(" + Math.round(red) + "," + Math.round(green) + "," + Math.round(blue) + ")";
}

This past week, I took it a bit further and made a little library that did that and added a bunch of other neat features as well. Introducing “clrs”:

https://github.com/bit101/clrs

Essentially, clrs is an object that has a bunch of methods on it. These return a color object. So you can say:

var myColor = clrs.rgb(255, 128, 0);

The color object is just an object, but its toString method returns an “rgba(…)” string concatenated as above. It turns out that if you use an object for anything that needs a color value, it will call that toString method and will get the string you set. Thus, you can use color objects anywhere you need a color value in JavaScript:

document.body.style.backgroundColor = myColor;
context.fillStyle = myColor;

So now you can set colors with rgb values (floats or ints), rgba values, 24-bit numbers, strings of any kind, even hsv values. I threw in some random functions as well. Not functions that do random things, but functions that return random colors. You can even interpolate between two colors.

So that’s cool in itself, but there’s more. That color object has a bunch of other methods. So once you have a color, you can set or get any of its red, green, blue or alpha channels, or all at once. Any of the set methods are chainable, so you can say:

myColor
    .setRed(255)
    .setGreen(128)
    .setBlue(0);

Another neat feature is binding. you can bind a color to a particular property of an object, say fillColor of a context2d.

myColor.bind(context, "fillStyle");

Now, whenever you change anything about that color, by calling setRed, setGreen, setRGB, etc. it will automatically update the context’s fill color with the new color.

Anyway, it’s early code. It needs to be more extensively tested. I welcome all feedback and contributions. I’d like to make it require.js compatible at some point. Any other standardization / best practice issue you see, or any methods you would like to see added, let me know, or do a pull request.

Send to Kindle

5 responses so far

Coding Math Application Series

Feb 10 2014 Published by under General, JavaScript, Technology

Send to Kindle

Last week I kicked off a new series on the Coding Math Channel. It’s the Application series.

I was thinking that it’s nice to present new concepts in each video, but there is a limited amount that I can do with them. I try to make the main episodes be 10-15 minutes long. I can explain a concept, do a few drawings, show some math, write some code, see it in action, and maybe iterate on that once or twice. And then, that’s it for that topic. Hopefully the brief example was good enough, because I’m moving on to something else now.

So my thought was to start another series where I actually build some simple app or game, or at least the barest outline of such. With some real world applications of the principles that are covered in the other videos. Each video will be in the five minute range, adding just one or two small features to the current app or game. Each feature may make use of one or more of the concepts from the other videos.

The first game is something I call Ballistics. It’s just a simple idea where you aim a gun and it shoots a cannonball that you try to hit a target. Like the old QBasic game, Gorillas.

gorilla2

In the first episode, we use a bit of trigonometry, including arctangent, to aim the gun using the mouse. In this week’s upcoming episode, we’ll actually get a cannonball firing, so that will use the particle class, with velocity and gravity, and lots more real world application of trigonometry. But each one is a bite sized piece of an application. We might hit the same concept over and over in different parts of the same app, or in different apps. But that’s the whole idea, to see many different ways you can use these concepts.

So now, we have the main episode each Monday, a Mini episode – shorter 5-minute simple concept – on Wednesday, and these Application episodes on Friday.

I want to thank all of you who have supported me on Patreon.com. It really makes doing these videos more justifiable in terms of the time I spend on them. And if you are a supporter, know that only the main Monday episodes are Patreon sponsored episodes. The Minis and Applications are on the house.

Send to Kindle

No responses yet

JavaScript Audio Synthesis Part 3: Making Music

Oct 01 2013 Published by under JavaScript

Send to Kindle

First of all, I am not a musician by any stretch of the imagination. But that fact will become obvious all too soon. But if you’re going to make sound with code, you wind up either making sound effects or music. So let’s start with music. My goal here was to create a simple “tracker” application. You program in notes, it plays those notes back in progression to form a song. Of sorts.

I’m going to keep the song very simple. Mary Had a Little Lamb. It’s a song that you can play every note with one beat, so you don’t have to mess around with different length notes. Here’s a simple version of the song transcribed into notes and rests:

g f e f
g g g -
f f f -
g b b -
g f e f
g g g g
f f g f
e – - -

A quick search on the ‘net gives you the frequency values for the notes b, e, f and g, the only ones you’ll need for this song. Code that into an object:

scale = {
	g: 392,
	f: 349.23,
	e: 329.63,
	b: 493.88
}

And then you can just code the song as a string.

song = "gfefgg-fff-gbb-gfefggggffgfe---";

Now you can create an AudioContext and an oscillator and set an interval that runs at a certain speed. In the interval callback, get the next note, find its frequency and set the oscillator’s frequency to that value. Like this:

window.onload = function() {

	var audio = new window.webkitAudioContext(),
		osc = audio.createOscillator(),
		position = 0,
		scale = {
			g: 392,
			f: 349.23,
			e: 329.63,
			b: 493.88
		},
		song = "gfefgg-fff-gbb-gfefggggffgfe---";

		osc.connect(audio.destination);
		osc.start(0);

	setInterval(play, 1000 / 4);

	function play() {
		var note = song.charAt(position),
			freq = scale[note];
		position += 1;
		if(position >= song.length) {
			position = 0;
		}
		if(freq) {
			osc.frequency.value = freq;
		}
	}
};

Now this actually works and you should be able to recognize the melody somewhat. But it leaves a lot to be desired. The biggest thing is that there is no separation between notes. You have a single oscillator running and you’re just changing its frequency. This ends up creating a sort of slide between notes rather than distinct notes. And when there’s a rest, well, there is no rest. It just keeps playing the last note.

There are various ways to try to handle this. One would be to call stop() on the oscillator, then change its frequency, then call start() again. But, when you read the documentation, it turns out that start and stop are one time operations on an oscillator. Once you call stop, it’s done. That particular oscillator cannot be restarted. So what to do?

The suggested answer is actually to create a new oscillator for each note. Initially, this sounds like a horrible idea. Create and destroy a new object for every single note in the song??? Well, it turns out that it’s not so bad. There are some frameworks that create a sort of object pool of notes in the background and reuse them. But the downside to that is that every note you create and start continues playing even if you can’t hear it. It’s your choice, and I suppose you could do all sorts of profiling to see which is more performant. But for Mary Had a Little Lamb, I think you’ll be safe to create a new oscillator each time.

To do this, make a new function called createOscillator. This will create an oscillator, specify its frequency and start it. After a given time, it will stop and disconnect that oscillator. You can then get rid of the main osc variable in the code and call the createOscillator function when you want to play a note.

window.onload = function() {

	var audio = new window.webkitAudioContext(),
		position = 0,
		scale = {
			g: 392,
			f: 349.23,
			e: 329.63,
			b: 493.88
		},
		song = "gfefgg-fff-gbb-gfefggggffgfe---";

	setInterval(play, 1000 / 4);

	function createOscillator(freq) {
		var osc = audio.createOscillator();

		osc.frequency.value = freq;
		osc.type = "square";
		osc.connect(audio.destination);
		osc.start(0);
		
		setTimeout(function() {
			osc.stop(0);
			osc.disconnect(audio.destination);
		}, 1000 / 4)
	}


	function play() {
		var note = song.charAt(position),
			freq = scale[note];
		position += 1;
		if(position >= song.length) {
			position = 0;
		}
		if(freq) {
	 		createOscillator(freq);
		}
	}
};

This sounds better already. Each note is distinct, and when there is a rest, no note plays. But you can do even better.

The notes are just flat tones at this point. You can improve this by giving them a quick and dirty sound envelope. In real life, a sound doesn’t usually just start at full volume and cut out to silence when its time is up. The volume usually ramps up a bit first (the attack) and fades out quickly or slowly (the decay). Actually, sound envelopes can be much more complex than this (http://en.wikipedia.org/wiki/ADSR_envelope#ADSR_envelope) but a simple attack and decay to 0 will do fine for now and give the notes a much better sound.

As a sound envelope controls the volume of a sound, you’ll need to create a gain node. Do this inside the createOscillator function:

	function createOscillator(freq) {
		var attack = 10,
			decay = 250,
			gain = audio.createGain(),
			osc = audio.createOscillator();
...

The attack and decay values there are in milliseconds. This means that the sound will ramp up from 0 to full volume in 0.01 seconds and then back down to 0 in .25 seconds.

Next, the gain node will need to go between the oscillator’s output and the destination in order to control the volume of that oscillator.

		gain.connect(audio.destination);
		gain.gain.setValueAtTime(0, audio.currentTime);
		gain.gain.linearRampToValueAtTime(1, audio.currentTime + attack / 1000);
		gain.gain.linearRampToValueAtTime(0, audio.currentTime + decay / 1000);
...

First you set the gain to 0, which in essence sets the volume to 0. You do this with the setValueAtTime method, passing in the current time from the AudioContext object. In other words, set the volume to 0, NOW.

Then you use linearRampToValueAtTime to set the attack and decay. This says go from whatever value you are currently at and interpolate to this new value so that you arrive there at the specified time. Note that the values you pass in here are in seconds, so you’ll need to divide by 1000 when using millisecond values.

Finally, you connect the oscillator to the gain, set the frequency and start it. And of course, when you clean up, you’ll need to disconnect everything as well.

		osc.frequency.value = freq;
		osc.type = "square";
		osc.connect(gain);
		osc.start(0);
		
		setTimeout(function() {
			osc.stop(0);
			osc.disconnect(gain);
			gain.disconnect(audio.destination);
		}, decay)
}

The final code is below:

window.onload = function() {

	var audio = new window.webkitAudioContext(),
		position = 0,
		scale = {
			g: 392,
			f: 349.23,
			e: 329.63,
			b: 493.88
		},
		song = "gfefgg-fff-gbb-gfefggggffgfe---";

	setInterval(play, 1000 / 4);

	function createOscillator(freq) {
		var attack = 10,
			decay = 250,
			gain = audio.createGain(),
			osc = audio.createOscillator();

		gain.connect(audio.destination);
		gain.gain.setValueAtTime(0, audio.currentTime);
		gain.gain.linearRampToValueAtTime(1, audio.currentTime + attack / 1000);
		gain.gain.linearRampToValueAtTime(0, audio.currentTime + decay / 1000);

		osc.frequency.value = freq;
		osc.type = "square";
		osc.connect(gain);
		osc.start(0);
		
		setTimeout(function() {
			osc.stop(0);
			osc.disconnect(gain);
			gain.disconnect(audio.destination);
		}, decay)
	}

	function play() {
		var note = song.charAt(position),
			freq = scale[note];
		position += 1;
		if(position >= song.length) {
			position = 0;
		}
		if(freq) {
	 		createOscillator(freq);
		}
	}
};

Now the notes have a more bell-like sound. It’s not awesome, but it’s a whole lot better. Mess around with trying to create different envelopes to see how that changes the sound. Code in your own song strings too. Don’t forget to add any additional note frequencies that you might use. You might even want to do something with allowing more than one-beat notes, though that starts to get a bit more complex.

Anyway, this is pretty rough and dirty code. A whole lot that could be improved upon here, but it’s good for demonstration purposes and hopefully gives you a better understanding of the underlying fundamentals than a more complex structure would. Have fun with it.

Send to Kindle

3 responses so far

JavaScript Audio Synthesis Part 2: Interactive Sound

Sep 28 2013 Published by under JavaScript

Send to Kindle

In yesterday’s post I covered the bare bones basics of creating audio with the Web Audio API. In this post, I’ll demonstrate one way to start creating some interactivity.

One of the simplest and most dynamic ways to capture interactivity on a computer is by simply reading the mouse position. The strategy for this next experiment is to use the mouse’s y-position to control the frequency of a single oscillator. The code for this is super simple:

window.onload = function() {

	var context = new window.webkitAudioContext(),
		osc = context.createOscillator(),
		h = window.innerHeight;

	osc.connect(context.destination);
	osc.start(0);

	document.addEventListener("mousemove", function(e) {
		osc.frequency.value = e.clientY / h * 1000 + 300;
	});
};
 

Create an AudioContext and an oscillator, get the window dimensions, connect and start the oscillator and listen for mousemove events.

In the mousemove handler, e.clientY / h will be a number from 0 to 1. Multiply this by 1000 and add 300 and you’ll have a frequency from 300 to 1300. This gets assigned to the oscillator’s frequency value. Move your mouse around the screen and get different pitches. Simple.

Remember, the above has only been tested in the latest version of Chrome at the time of this writing. Other configurations may work; some may require some changes.

Now what about they x-axis? Yesterday you had two oscillators going. Let’s try to hook the mouse’s x-position to that second oscillator.

window.onload = function() {

	var context = new window.webkitAudioContext(),
		osc = context.createOscillator(),
		osc2 = context.createOscillator(),
		gain = context.createGain(),
		w = window.innerWidth,
		h = window.innerHeight;

	osc.frequency = 400;

	osc.connect(context.destination);
	osc.start(0);

	gain.gain.value = 100;
	gain.connect(osc.frequency);

	osc2.frequency.value = 5;
	osc2.connect(gain);
	osc2.start(0);

	document.addEventListener("mousemove", function(e) {
		osc.frequency.value = e.clientY / h * 1000 + 200;
		osc2.frequency.value = e.clientX / w * 30 + 5;
	});
};
 

This is much the same as the final code from yesterday, but now you’re using the mouse x- and y-positions to control the frequencies of both oscillators. Move your mouse all over the screen now and you’ll get all kinds of science-fictiony sounds. I picture a 1950′s flying saucer taking off, or maybe an alien ray gun. Mess with the frequency ranges of both oscillators and try changing the oscillator types for both – mix and match square, sawtooth and triangle waves for all kinds of interesting results.

Send to Kindle

Comments are off for this post

Audio Synthesis in JavaScript

Sep 27 2013 Published by under JavaScript

Send to Kindle

This is something I’ve wanted to play with for a long time. So the other day I buckled down and started searching around.

Yes, you can create sound in JavaScript. In some browsers. Supposedly, it works in Chrome 14, Firefox 23, Opera 15 and Safari 6. Not IE. But, I’ve only tested this in Chrome. So for now, consider this something experimental and fun to lay with, not for your super awesome works-in-every-browser game.

I found several sites that had build up complex libraries based on the Web Audio API. These weren’t the greatest things to learn the basics from, but I eventually was able to pare some of the code down to the bare minimum needed to create some sounds in the browser. There’s also the MDN documentation here: https://developer.mozilla.org/en-US/docs/Web_Audio_API, which is a great reference, but not a step-by-step tutorial for creating sounds. There are a few tutorials linked to from there as well, but none really covered what I was interested in.

So, to get down to it, let’s create some noise.

First you need to create an AudioContext object. This is similar in concept to HTML5′s 2D graphics context for canvas. The context is the overarching object that you’ll use to create all the pieces that will create the sound you’re going to make. For Webkit-based browsers, you get an AudioContext like so:


var context = 
    new window.webkitAudioContext();

The AudioContext has a few properties, the most important one being “destination”. The destination is basically the output of the context, where the sound goes. You can think of it as your speakers.

audiocontext

The next thing you need to know about the Web Audio API is that it is a node based system. You use the AudioContext to create various nodes that are used to create and shape sounds. Nodes have inputs and outputs that you can use to hook various nodes together into different configurations.

The most direct way to create a sound is to create an oscillator node. An oscillator node has zero inputs and one output. You can hook that output to the destination of your context. You’ll also need to specify a frequency for the oscillator. 440 hz will create the musical note, A. Here’s the code:

var context = new window.webkitAudioContext();

var osc = context.createOscillator();
osc.frequency.value = 440;
osc.connect(context.destination);
osc.start(0);
 

And here’s how this looks from a node view:

oscillator

Yeah, it says “frequency: 500″. My goof. Not changing it. Live with it.

You have an oscillator node with a frequency of 440 connected to the destination of the AudioContext. Call start(0) and you should get an annoying sound coming out of your speaker.

The oscillator node has a couple of other properties. One is “type”. This is the type of wave it uses to generate the sound. It defaults to “sine”. But, you can try “square”, “sawtooth” or “triangle” and see how they sound by doing this:

osc.type = "sawtooth";

There’s also a “custom” type, but that involves creating and setting a custom wave table. If you’re into it, go for it.

Anyway, wasn’t that easy? Let’s expand on it and create another oscillator that messes with the first one.

To do this, you’ll create two new nodes, an oscillator node and a gain node. A gain node is usually used to change the volume of a sound, but you’ll be using it here to alter the frequency of the original oscillator node. You’ll also create another, slower oscillator node. This new oscillator node’s output will be connected to the gain node. A gain node has a single input and a single output. As the new oscillator goes up and down at a frequency of 1 hz (once per second), it will affect the output of the gain node. A gain node also has a value property. If you set that to 100, then the gain node’s output will cycle from +100 to -100 as the new oscillator slowly cycles.

Now you need to hook this +/- 100 gain node output to the original oscillator. But remember that oscillator nodes don’t have any inputs, so you can’t connect it directly to the oscillator node. Instead, you connect it directly to the frequency property of the node. Now that gain output will change the original frequency of 440 hz + or – 100 hz as it cycles. A picture is worth several hundred words.

oscillator2

One oscillator is connected to the gain node, which is directly connected to the other oscillator’s frequency. That oscillator is connected to the destination. Here’s the code:

var context = new window.webkitAudioContext();

var osc = context.createOscillator();
osc.frequency.value = 440;
osc.connect(context.destination);
osc.start(0);

var gain = context.createGain();
gain.gain.value = 100;
gain.connect(osc.frequency);

var osc2 = context.createOscillator();
osc2.frequency.value = 1;
osc2.connect(gain);
osc2.start(0);

Run that and you should hear a siren like sound.

You can also change the type of the second oscillator. Try making that a square wave:

osc2.type = "square";

square

Now, instead of cycling smoothly from +100 to -100, the gain’s output will be exactly +100 for half the cycle than jump to exactly -100 for the second half. The result is more like a siren you’d hear in Europe or the UK. It also drives my dog crazy.

Anyway, that’s the bare minimum. Check out the API at the link mentioned previously. There’s a lot more you can do with it from here.

Send to Kindle

Comments are off for this post

Playing With Chaos is Published!

Sep 20 2013 Published by under JavaScript

Send to Kindle

At long last, the book is available for sale. It took a few days to get through all the copy edits and then a few last minute tweaks, then I hit the big old publish button. A few hours later, it was live … except in the US, Japan, India and Canada. I’m not sure if there is just some lag in the system for certain countries. I contacted support, they said they’d look into it and I never heard back, but the book soon went live on the US and Canadian stores. As of this writing it’s still listed as unavailable for purchase in India and Japan. It may resolve itself, but I’ll keep pushing on it anyway.

As mentioned previously, the whole process was a great experience and feels like a big accomplishment to have pulled it off from inception to being in the store, all under my own steam.

Anyway, go get it if this is the kind of thing you’re interested in. I hope you enjoy it. If so, it would be really nice to start seeing some good reviews stacking up there. :)

Send to Kindle

5 responses so far

Playing with Chaos – July Update

Jul 26 2013 Published by under JavaScript, Technology

Send to Kindle

Since my last post, I’ve been focusing almost all of my free time on writing this book. Mostly because I’m having so much fun writing it. I’ve finished a whopping six chapters since I last posted here. So yeah, it’s going pretty well. Here’s the current table of contents:

Chapter 1: Introduction
Chapter 2: What is a Fractal
Chapter 3: Symmetry and Regularity
Chapter 4: Fractal Dimensions
Chapter 5: Order from Chaos
Chapter 6: Diffusion-Limited Aggregation
Chapter 7: The Mandelbrot Set
Chapter 8: The Julia Set and Fatou Dust
Chapter 9: Strange Attractors
Chapter 10: L-Systems
Chapter 11: Cellular Automata
Chapter 12: Fractals in the Real World

I’m through Chapter 8 and heading into Chapter 9 now. Chapters 4 – 8 are first drafts, while 1 – 4 have been worked over a bit and are pretty close to final. I’d like to think I could be done with the writing by the end of August. Then another week or two for personal review and editing. After that I’ll need to have some other people review it and I’m considering how to handle copy editing – whether to hire someone or consider other alternatives.

One stroke of personal brilliance was that the utility library that is used in each example contains a method to pop out a bitmap image of the canvas that can be saved to disk. Built-in screenshots! So all the images for the book are easily created while I’m writing the text and code. Sometimes some cropping is needed, but I’ve got a good flow going for that as well. At this point, I’m up to 155 images. It’s a pretty graphics-heavy for a Kindle book, but I’ve been checking every image on a real Kindle and they all look decent.

If you want to get a feel for what’s coming, I’ve set up a site for the book at http://playingwithchaos.net. It’s got every image in the book, plus a video of the presentation I did at Beyond Tellerand/Play! that sparked my thoughts about writing this book.

Send to Kindle

2 responses so far

Older posts »