Assignment 5.2

Post date: Jul 01, 2010 1:48:14 AM

I used the same Arduino code from assignment 5.1. Here's the processing code:

import processing.serial.*;

Serial myPort;

int val;

void setup() {

size(400,400);

String portName = Serial.list()[0];

myPort = new Serial(this, portName, 9600);

}

void draw() {

background(0); // set background to black

stroke(0); // set stroke color to black

if ( myPort.available() > 0) { // if data is available

val = myPort.read(); // read it and store it in val

}

if (val == 1) {

fill(225, 0, 0); // sets fill color to bright red

ellipse(width/2, height/2, 400, 400); // draws ellipse centered with diameter 400

fill(225, 225, 0); // sets fill color to bright yellow

rect(25, 25, 350, 350); // draws rectangle from corner (25, 25) with width of 350

fill(180, 0, 0); // sets fill color to a darker red

ellipse(width/2, height/2, 350, 350); // draws ellipse centered with diameter 350

fill(168.75, 168.75, 0); // sets fill color to a darker yellow

rect(50, 50, 300, 300); // draws rectangle from corner (50, 50) with width of 300

fill(135, 0, 0); // sets fill color to a medium red

ellipse(width/2, height/2, 300, 300); // draws ellipse centered with diameter 300

fill(112.5, 112.5, 0); // sets fill color to a medium yellow

rect(75, 75, 250, 250); // draws rectangle from corner (75, 75) with width of 250

fill(90, 0, 0); // sets fill color to dark red

ellipse(width/2, height/2, 250, 250); // draws ellipse centered with diameter 250

fill(56.25, 56.25, 0); // sets fill color to dark yellow

rect(100, 100, 200, 200); // draws rectangle with corner at (100, 100) and width of 200

fill(45, 0, 0); // sets fill color to very dark red

ellipse(width/2, height/2, 200, 200); // draws ellipse centered with diameter 200

fill(0); // sets fill color to black

rect(125, 125, 150, 150); // draws rectangle with corner at (125, 125) and width of 150

stroke(0, 225, 0); // sets stroke color to bright green

line(200, 125, 125, 200); // draws line from (200, 125) to (125, 200)

line(200, 125, 275, 200); // draws line from (200, 125) to (275, 200)

line(125, 200, 200, 275); // draws line from (125, 200) to (200, 175)

line(275, 200, 200, 275); // draws line from (275, 200) to (200, 275)

fill(0, 0, 0, 0); // sets fill to transparent black

rect(145, 145, 110, 110); // draws rectangle with corner at (145, 145) and width 110

stroke(0); // sets stroke color to black

fill(0, 0, 25); // sets fill color to a very dark blue

ellipse(width/2, height/2, 100, 100); // draws ellipse with center at middle and diameter of 100

fill(0, 0, 75); // sets fill color to dark blue

ellipse(width/2, height/2, 80, 80); // draws ellipse centered with diameter 80

fill(0, 0, 125); // sets fill color to blue

ellipse(width/2, height/2, 60, 60); // draws ellipse centered with diameter 60

fill(0, 0, 175); // sets fill color to bright blue

ellipse(width/2, height/2, 40, 40); // draws ellipse centered with diameter 40

fill(0, 0, 225); // sets fill color to a very bright blue

ellipse(width/2, height/2, 20, 20); // draws ellipse centered with diameter 20

stroke(0, 0, 125); // sets stroke color to bright blue

line(25, 25, 375, 375); // draws line from (0, 0) to (400, 400)

line(375, 25, 25, 375); // draws line from (400, 0) to (0, 400)

line(200, 0, 200, 400); // draws line from (200, 0) to (200, 400)

line(0, 200, 400, 200); // draws line from (0, 200) to (400, 200)

}

else if (val == 0) {

fill(225, 225, 0); // sets fill color to bright yellow

ellipse(width/2, height/2, 400, 400); // draws ellipse centered with diameter 400

fill(225, 0, 0); // sets fill color to bright red

rect(25, 25, 350, 350); // draws rectangle from corner (25, 25) with width of 350

fill(180, 180, 0); // sets fill color to a darker yellow

ellipse(width/2, height/2, 350, 350); // draws ellipse centered with diameter 350

fill(168.75, 0, 0); // sets fill color to a darker red

rect(50, 50, 300, 300); // draws rectangle from corner (50, 50) with width of 300

fill(135, 135, 0); // sets fill color to a medium yellow

ellipse(width/2, height/2, 300, 300); // draws ellipse centered with diameter 300

fill(112.5, 0, 0); // sets fill color to a medium red

rect(75, 75, 250, 250); // draws rectangle from corner (75, 75) with width of 250

fill(90, 90, 0); // sets fill color to dark yellow

ellipse(width/2, height/2, 250, 250); // draws ellipse centered with diameter 250

fill(56.25, 0, 0); // sets fill color to dark red

rect(100, 100, 200, 200); // draws rectangle with corner at (100, 100) and width of 200

fill(45, 45, 0); // sets fill color to very dark yellow

ellipse(width/2, height/2, 200, 200); // draws ellipse centered with diameter 200

fill(0); // sets fill color to black

rect(125, 125, 150, 150); // draws rectangle with corner at (125, 125) and width of 150

stroke(225, 0, 225); // sets stroke color to bright magenta

line(200, 125, 125, 200); // draws line from (200, 125) to (125, 200)

line(200, 125, 275, 200); // draws line from (200, 125) to (275, 200)

line(125, 200, 200, 275); // draws line from (125, 200) to (200, 175)

line(275, 200, 200, 275); // draws line from (275, 200) to (200, 275)

fill(0, 0, 0, 0); // sets fill to transparent black

rect(145, 145, 110, 110); // draws rectangle with corner at (145, 145) and width 110

stroke(0); // sets stroke color to black

fill(0, 25, 25); // sets fill color to a very dark cyan

ellipse(width/2, height/2, 100, 100); // draws ellipse with center at middle and diameter of 100

fill(0, 75, 75); // sets fill color to dark cyan

ellipse(width/2, height/2, 80, 80); // draws ellipse centered with diameter 80

fill(0, 125, 125); // sets fill color to cyan

ellipse(width/2, height/2, 60, 60); // draws ellipse centered with diameter 60

fill(0, 175, 175); // sets fill color to bright cyan

ellipse(width/2, height/2, 40, 40); // draws ellipse centered with diameter 40

fill(0, 225, 225); // sets fill color to a very bright cyan

ellipse(width/2, height/2, 20, 20); // draws ellipse centered with diameter 20

stroke(225, 0, 225); // sets stroke color to bright magenta

line(25, 25, 375, 375); // draws line from (0, 0) to (400, 400)

line(375, 25, 25, 375); // draws line from (400, 0) to (0, 400)

line(200, 0, 200, 400); // draws line from (200, 0) to (200, 400)

line(0, 200, 400, 200); // draws line from (0, 200) to (400, 200)

}

else if (val == 10)

{

fill(45, 45, 0); // sets fill color to bright yellow

ellipse(width/2, height/2, 400, 400); // draws ellipse centered with diameter 400

fill(56.25, 0, 0); // sets fill color to bright red

rect(25, 25, 350, 350); // draws rectangle from corner (25, 25) with width of 350

fill(90, 90, 0); // sets fill color to a darker yellow

ellipse(width/2, height/2, 350, 350); // draws ellipse centered with diameter 350

fill(112.5, 0, 0); // sets fill color to a darker red

rect(50, 50, 300, 300); // draws rectangle from corner (50, 50) with width of 300

fill(135, 135, 0); // sets fill color to a medium yellow

ellipse(width/2, height/2, 300, 300); // draws ellipse centered with diameter 300

fill(168.75, 0, 0); // sets fill color to a medium red

rect(75, 75, 250, 250); // draws rectangle from corner (75, 75) with width of 250

fill(180, 180, 0); // sets fill color to dark yellow

ellipse(width/2, height/2, 250, 250); // draws ellipse centered with diameter 250

fill(225, 0, 0); // sets fill color to dark red

rect(100, 100, 200, 200); // draws rectangle with corner at (100, 100) and width of 200

fill(225, 225, 0); // sets fill color to very dark yellow

ellipse(width/2, height/2, 200, 200); // draws ellipse centered with diameter 200

fill(0); // sets fill color to black

rect(125, 125, 150, 150); // draws rectangle with corner at (125, 125) and width of 150

stroke(0, 225, 0); // sets stroke color to bright green

line(200, 125, 125, 200); // draws line from (200, 125) to (125, 200)

line(200, 125, 275, 200); // draws line from (200, 125) to (275, 200)

line(125, 200, 200, 275); // draws line from (125, 200) to (200, 175)

line(275, 200, 200, 275); // draws line from (275, 200) to (200, 275)

fill(0, 0, 0, 0); // sets fill to transparent black

rect(145, 145, 110, 110); // draws rectangle with corner at (145, 145) and width 110

stroke(0); // sets stroke color to black

fill(0, 0, 225); // sets fill color to a very bright blue

ellipse(width/2, height/2, 100, 100); // draws ellipse with center at middle and diameter of 100

fill(0, 0, 175); // sets fill color to bright blue

ellipse(width/2, height/2, 80, 80); // draws ellipse centered with diameter 80

fill(0, 0, 125); // sets fill color to blue

ellipse(width/2, height/2, 60, 60); // draws ellipse centered with diameter 60

fill(0, 0, 75); // sets fill color to dark blue

ellipse(width/2, height/2, 40, 40); // draws ellipse centered with diameter 40

fill(0, 0, 25); // sets fill color to a very dark blue

ellipse(width/2, height/2, 20, 20); // draws ellipse centered with diameter 20

stroke(0, 0, 125); // sets stroke color to bright blue

line(25, 25, 375, 375); // draws line from (0, 0) to (400, 400)

line(375, 25, 25, 375); // draws line from (400, 0) to (0, 400)

line(200, 0, 200, 400); // draws line from (200, 0) to (200, 400)

line(0, 200, 400, 200); // draws line from (0, 200) to (400, 200)

}

else

{

fill(225, 225, 0); // sets fill color to bright yellow

ellipse(width/2, height/2, 400, 400); // draws ellipse centered with diameter 400

fill(225, 0, 0); // sets fill color to bright red

rect(25, 25, 350, 350); // draws rectangle from corner (25, 25) with width of 350

fill(180, 180, 0); // sets fill color to a darker yellow

ellipse(width/2, height/2, 350, 350); // draws ellipse centered with diameter 350

fill(168.75, 0, 0); // sets fill color to a darker red

rect(50, 50, 300, 300); // draws rectangle from corner (50, 50) with width of 300

fill(135, 135, 0); // sets fill color to a medium yellow

ellipse(width/2, height/2, 300, 300); // draws ellipse centered with diameter 300

fill(112.5, 0, 0); // sets fill color to a medium red

rect(75, 75, 250, 250); // draws rectangle from corner (75, 75) with width of 250

fill(90, 90, 0); // sets fill color to dark yellow

ellipse(width/2, height/2, 250, 250); // draws ellipse centered with diameter 250

fill(56.25, 0, 0); // sets fill color to dark red

rect(100, 100, 200, 200); // draws rectangle with corner at (100, 100) and width of 200

fill(45, 45, 0); // sets fill color to very dark yellow

ellipse(width/2, height/2, 200, 200); // draws ellipse centered with diameter 200

fill(0); // sets fill color to black

rect(125, 125, 150, 150); // draws rectangle with corner at (125, 125) and width of 150

stroke(0, 225, 0); // sets stroke color to bright green

line(200, 125, 125, 200); // draws line from (200, 125) to (125, 200)

line(200, 125, 275, 200); // draws line from (200, 125) to (275, 200)

line(125, 200, 200, 275); // draws line from (125, 200) to (200, 175)

line(275, 200, 200, 275); // draws line from (275, 200) to (200, 275)

fill(0, 0, 0, 0); // sets fill to transparent black

rect(145, 145, 110, 110); // draws rectangle with corner at (145, 145) and width 110

stroke(0); // sets stroke color to black

fill(0, 0, 25); // sets fill color to a very dark blue

ellipse(width/2, height/2, 100, 100); // draws ellipse with center at middle and diameter of 100

fill(0, 0, 75); // sets fill color to dark blue

ellipse(width/2, height/2, 80, 80); // draws ellipse centered with diameter 80

fill(0, 0, 125); // sets fill color to blue

ellipse(width/2, height/2, 60, 60); // draws ellipse centered with diameter 60

fill(0, 0, 175); // sets fill color to bright blue

ellipse(width/2, height/2, 40, 40); // draws ellipse centered with diameter 40

fill(0, 0, 225); // sets fill color to a very bright blue

ellipse(width/2, height/2, 20, 20); // draws ellipse centered with diameter 20

stroke(0, 0, 125); // sets stroke color to bright blue

line(25, 25, 375, 375); // draws line from (0, 0) to (400, 400)

line(375, 25, 25, 375); // draws line from (400, 0) to (0, 400)

line(200, 0, 200, 400); // draws line from (200, 0) to (200, 400)

line(0, 200, 400, 200); // draws line from (0, 200) to (400, 200)

}

}

When the button connected to pin 5 is pressed, the inner group of circles change from blue hues to cyan hues, and the diamond, square, and lines running through the middle change color to magenta. When the button connected to pin 4 is pressed, the outer ring of yellow hued circles change to red hues and the red hued squares change to yellow hues. When both buttons are pressed, the outer yellow circles and red squares change from dark to light to light to dark, and the inner blue circles change from dark to light to light to dark as well. A short video is attached.