Assignment 3.1
Post date: Jun 24, 2010 4:5:49 AM
I used the following code to recreate and expand upon mr. dickie's image. The image is drawn in all 4 corners with a grayscale radial gradient in the center, and the line's stroke color is set to the x or y value of the line, resulting in a rainbow type pattern.
Here is the image:
Here is the code:
void setup() {
size(400, 400); //set size to 400 x 400 pixels
background(0,0,0); //set initial background color to black
}
//function to create radial gradient emanating from point (centerx, centery)
void createGSRadialGradient(int centerx, int centery)
{
colorMode(RGB, width); //set mode to rgb from 0 - 400 (screen width)
for(int i = width; i >= 0; i-=1) { //set up for loop, decrement from outside-in
stroke(width-i); //set stroke color to increase as diameter decreases
fill(0,0,0,0); //no fill color
ellipseMode(CENTER); //elipses are declared by centerpoint
ellipse(centerx, centery, i, i); //draw the ellipse
}
}
void draw() {
createGSRadialGradient(width/2, width/2); //create gradient centered on screen
colorMode(HSB, width); //set color mode to HSB so that hue is defined by just 1 variable
int j = width; //declare extra enumeration variable
/* the following code works first by setting up a loop to either
decrease or increase the 2 enumeration variables, setting the
hue to one of them so the color gradually changes (rainbow style),
then drawing a line. The points are each comprised of 2 scalars,
one being one of the enumeration variables, and the other being
a boundary (0 or width). which is which will depend on the corner
being drawn */
//draw mesh object in top-left corner
for(int i = 0; i <= width; i += 10) {
stroke(400-i, 400, 200); //rainbow color, 100% saturation, 50% brightness
line(i, 0, 0, j);
j -= 10;
}
//draw mesh object in bottom-right corner
for(int i = width; i>= 0; i -= 10) {
stroke(i, 400, 200);
line(width, j, i, width);
j += 10;
}
j = 0; //reset enumeration
//draw mesh object in top-right
for(int i = 0; i <= width; i += 10) {
stroke(400-i, 400, 200);
line(width, i, j, 0);
j += 10;
}
//draw mesh object in bottom left
for(int i = width; i >= 0; i -= 10) {
stroke(i, 400, 200);
line(0, i, j, width);
j -= 10;
}
}
void mousePressed() {
//save screenshot when mouse is pressed
saveFrame("screenshot-##.png");
}