Welcome to d3aday! If this is your first time, we recommend reading the about page before jumping in.
This exercise is a bit of a change-up. I thought it would be fun to occasionally play around with using D3.js to create generative art. In line with the core goals of the site, though, I’ve tried to keep it fairly simple.
The Inspiration
I came across this painting in a building in Charlotte, North Carolina. I’m not sure who the artist is (and please let me know if you know so I can give proper attribution).
I love the colors and the composition, and I’d be curious to know if the artist used any kind of data or generative system to create it. I think it’s a great inspiration piece for this first generative art exercise.
The Exercise
For this exercise, let’s try to recreate the essential elements of the piece: the grid, the semi-regularly-placed dots of varying sizes, and the color pallette.
The layout is very similar to a heat map or scatterplot - regularly placed SVG elements along 2 axes. One twist I added is some slight randomization of the positions and sizes of the circles, which is necessary to keep them from all stacking on top of each other.
For the data, we can once again reuse the Raleigh temperature dataset. We don’t need it all, though, so my recommendation is to narrow it down to just the number of data points you need. I’ve laid out the chart on a 12x12 grid, with the 12 months along the X-axis, and an arbitrary selection of 12 sets of years along the Y-axis. Each dot represents a particular month and year, and there are 4 dots per “cell,” so that translates to 4 x 12 = 48 years worth of data we need.
To recreate the color pallette, you can directly sample the colors from the image using a web eyedropper tool like ColorZilla. Colors are assigned as they would be in a heat map, with hotter temperatures getting one end of the color range and cooler temperatures getting the other. I’ve given the circles a little bit of transparency for added texture.
One totally optional feature that gives the result more depth, is an SVG gradient applied to the grid. I used a radial gradient similar to those described on the MDN page on SVG gradients.
A Solution
My solution is below, but I encourage you to attempt it first without peeking. The full code and working example can be found on codepen.