04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

428<br />

The radial gradient functions similarly to the linear one, except I used some trig functions.<br />

The way it works is that the radius keeps increasing each iteration of the outer for<br />

loop. The nested loop creates a circle of colored pixels at each radius length. A blend<br />

occurs between color 1 <strong>and</strong> color 2, as it did in the linear example. I had to add some<br />

minor “hacks,” however. Since the set() function only takes ints, not floats, I needed to<br />

explicitly convert the px <strong>and</strong> py variables to ints with the calls int(px) <strong>and</strong> int(py). In<br />

addition, as the pixels were drawn around each circle at the respective radii lengths, I<br />

noticed some small (<strong>and</strong> annoying) gaps in the gradient. To compensate, I created the<br />

gapFiller variable, which ensures that extra pixels are drawn to fill in the gaps. I look<br />

forward to hearing from one of you on how to more elegantly solve this problem—full<br />

bragging rights extended.<br />

Before moving on to another approach to writing pixels, let’s look at one more less “regular”<br />

example. This example, shown in Figure 10-19, also takes some time to render.<br />

/*<br />

Wave Gradient<br />

January 13, 2006<br />

*/<br />

size(600, 400);<br />

background(200,200,200);<br />

float angle = 0;<br />

float px = 0, py = 0;<br />

float amplitude = 30;<br />

float frequency = 0;<br />

float fillGap = 2.5;<br />

color c;<br />

for (int i=-50; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!