Assignment 5.2

posted Aug 15, 2010, 12:25 PM by Unknown user
I used the arduino code from assignment 5.1 (with a few minor adjustments)

I modified the sketch from assignment 3.1

Here is the code:

import processing.serial.*;

Serial myPort;
int val;

void setup(){
  size(400, 400);  // sets the window size to 400x400
  background(0);  //sets the window background to black
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600); 
}

void draw(){
  if (myPort.available() > 0) {
    val = myPort.read();
  }
  
  if(val == 1){
  stroke(252, 138, 145);      // sets outline color to salmon
  fill(252, 138, 145);        //sets fill color to salmon
  rect(50, 50, 300, 300);   // draws 300x300 rectanlge at (50,50)
  
  stroke(255, 0, 0);        //sets outline color to a darker red
  fill(255, 0, 0);          //sets the fill color to a darker red
  rect(75, 75, 250, 250);  //draws a 250x250 retangle at (75,75)
  
  stroke(167, 2, 13);     //sets the outline color to an even darker red
  fill(167, 2, 13);       //sets the fill color to a even darker red
  rect(100, 100, 200, 200); //draws a 200x200 rectangle at (100,100) 
  
  stroke(118, 1, 9);      //sets the outline color to a still darker red
  fill(118, 1, 9);       //sets the fill color to a still darker red
  rect(125, 125, 150, 150); //draws a 150x150 rectangle at (125,125) 
  
  stroke(70, 1, 1);           //sets the outline color to the darkest red
  fill(70, 1, 1);            // sets the fill color to the darkeset red
  rect(150, 150, 100,100); //draws a 100x100 rectangle at (150,150)
  
  stroke(0, 0, 255);        //sets outline color to blue
  fill(0, 0, 255);          //sets fill color to blue
  ellipse(50, 50, 100,100);  //draws 100x100 circle at (50,50)
  ellipse(350, 50, 100, 100);  //draws 100x100 circle at (350,50)
  ellipse(50, 350, 100, 100);// draws 100x100 cirlce at (50,350)
  ellipse(350, 350, 100, 100); //draws 100x100 circle at (350,350)
  
  stroke(250, 240, 40);          //sets the outline color to light yellow
  line(50, 50, 350, 350);     //draws a line from (50,50) to (350,350)
  line(50, 350, 350, 50);    //draws a line from (50, 350) to (350,350)
  fill(250, 240, 40);          // sets the fill color to light yellow
  ellipseMode (CENTER);    //sets the ellipse draw mode to CENTER
  ellipse(200, 200, 100, 100); //draws a 100x100 cirlce at (200,200)
  ellipse(50, 50, 50, 50);  //draws a 50x50 circle at (50,50)
  
  stroke(160, 152, 3);     //sets the outline color to a darker yello
  fill(160, 152, 3);      //sets the fill color to a darker yellow
  ellipse(50, 50, 25, 25);  //draws a 25x25 circle at (50,50)
  
  stroke(250, 240, 40);       //sets the outline color to bright yellow
  fill (250, 240, 40);       //sets the fill color to a bright yellow
  ellipse(350, 50, 50, 50); //draws a 50x50 circle at (350,50)
  ellipse(50, 350, 50, 50); //draws a 50x50 circle at (50,350)
  ellipse(350, 350, 50, 50); //draws a 50x50 circle at (350,350)
  
  stroke(160, 152, 3);    //sets the outline color to a darker yellow
  fill(160, 152, 3);      // sets the fill color to a darker yellow
  ellipse(350, 50, 25, 25); //draws a 25x25 circle at (350,50)
  ellipse(50, 350, 25, 25); //draws a 25x25 circle at (50,350)
  ellipse(350, 350, 25, 25); //draws a 25x25 circle at (350,350)
  ellipse(200, 200, 50, 50); //draws a 50x50 circle at (200,200)
  
  stroke(72, 66, 1);       //sets the outline color to an even darker yellow
  fill(72, 66, 1);         //sets the fill color to an even darker yellow
  ellipse(200, 200, 25, 25); //draws a 25x25 circle at (200,200)
  
  stroke(160, 152, 3); //sets the outline color to the medium yellow
  line(50, 50, 200, 0); //draws a line from (50,50) to (200,0)
  line(200, 0, 350, 50); //draws a line from (200,0) to (350,50)
  line(350, 50, 400, 200); //draws a line from (350,50) to (400,200)
  line(400, 200, 350, 350); //draws a line from (400,200) to (350,350)
  line(350, 350, 200, 400); //draws a line from (350,350) to (200,400)
  line(200, 400, 50, 350);  //draws a line from (200,400) to (50, 350)
  line(50, 350, 0, 200);   //draws a lime from (50,350) to (0,200) 
  line(0, 200, 50, 50);   //draws a line from (0,200) to (50,50)
  
  stroke(250, 240, 40);   //sets the outline color to bright yellow
  fill(250, 240, 40);     //sets the fill color to bright yellow
  ellipse(200, 0, 25, 25);  //draws a 25x25 circle at (200,0)
  ellipse(400, 200, 25, 25); //draws a 25x25 circle at (400,200)
  ellipse(200, 400, 25, 25); //draws 25x25 circle at (200,400)
  ellipse(0, 200, 25, 25); //draws a 25x25 circle at (0,200)
  
  stroke(171, 9, 180);    //sets the outline color to dark green
  line(200, 150, 250, 200);  // draws a line from (200,150) to (250,200)
  line(250, 200, 200, 250);  //draws a line from (250,200) to (200,250)
  line(200, 250, 150, 200); //draws a line from (200,250) to (150,200)
  line(150, 200, 200, 150); //draws a line from (150,200) to (200,150)
}
else if (val ==2){
  stroke(0, 255, 255);        // sets outline color to cyan
  fill(0, 255, 255);          //sets fill color to cyan
  rect(50, 50, 300, 300);   // draws 300x300 rectanlge at (50,50)
  
  stroke(2, 160, 156);       //sets outline color to a darker cyan
  fill(2, 160, 156);        //sets the fill color to a darker cyan
  rect(75, 75, 250, 250);  //draws a 250x250 retangle at (75,75)
  
  stroke(0, 0, 255);        //sets the outline color to blue
  fill(0, 0, 255);         //sets the fill color to blue
  rect(100, 100, 200, 200); //draws a 200x200 rectangle at (100,100) 
  
  stroke(17, 2, 167);       //sets the outline color to a darker blue
  fill(17, 2, 167);        //sets the fill color to a darker blue
  rect(125, 125, 150, 150); //draws a 150x150 rectangle at (125,125) 
  
  stroke(12, 2, 106);        //sets the outline color to an even darker blue
  fill(12, 2, 106);         // sets the fill color to an even darker blue
  rect(150, 150, 100,100); //draws a 100x100 rectangle at (150,150)
  
  stroke(255, 0, 255);        //sets outline color to purple
  fill(255, 0, 255);          //sets fill color to purple
  ellipse(50, 50, 100,100);  //draws 100x100 circle at (50,50)
  ellipse(350, 50, 100, 100);  //draws 100x100 circle at (350,50)
  ellipse(50, 350, 100, 100);// draws 100x100 cirlce at (50,350)
  ellipse(350, 350, 100, 100); //draws 100x100 circle at (350,350)
  
  stroke(255, 0, 0);          //sets the outline color to red
  line(50, 50, 350, 350);     //draws a line from (50,50) to (350,350)
  line(50, 350, 350, 50);    //draws a line from (50, 350) to (350,350)
  fill(255, 0, 0);          // sets the fill color to bright red
  ellipseMode (CENTER);    //sets the ellipse draw mode to CENTER
  ellipse(200, 200, 100, 100); //draws a 100x100 cirlce at (200,200)
  ellipse(50, 50, 50, 50);  //draws a 50x50 circle at (50,50)
  
  stroke(149, 3, 8);     //sets the outline color to a darker red
  fill(65, 129, 29);      //sets the fill color to a darker red
  ellipse(50, 50, 25, 25);  //draws a 25x25 circle at (50,50)
  
  stroke(255 ,0 , 0);       //sets the outline color to red
  fill (255, 0, 0);       //sets the fill color to red
  ellipse(350, 50, 50, 50); //draws a 50x50 circle at (350,50)
  ellipse(50, 350, 50, 50); //draws a 50x50 circle at (50,350)
  ellipse(350, 350, 50, 50); //draws a 50x50 circle at (350,350)
  
  stroke(149, 3, 8);    //sets the outline color to a darker red
  fill(149, 3, 8);      // sets the fill color to a darker red
  ellipse(350, 50, 25, 25); //draws a 25x25 circle at (350,50)
  ellipse(50, 350, 25, 25); //draws a 25x25 circle at (50,350)
  ellipse(350, 350, 25, 25); //draws a 25x25 circle at (350,350)
  ellipse(200, 200, 50, 50); //draws a 50x50 circle at (200,200)
  
  stroke(80, 1, 3);       //sets the outline color to an even darker red
  fill(80, 1, 3);         //sets the fill color to an even darker red
  ellipse(200, 200, 25, 25); //draws a 25x25 circle at (200,200)
  
  stroke(149, 3, 8); //sets the outline color to the medium red
  line(50, 50, 200, 0); //draws a line from (50,50) to (200,0)
  line(200, 0, 350, 50); //draws a line from (200,0) to (350,50)
  line(350, 50, 400, 200); //draws a line from (350,50) to (400,200)
  line(400, 200, 350, 350); //draws a line from (400,200) to (350,350)
  line(350, 350, 200, 400); //draws a line from (350,350) to (200,400)
  line(200, 400, 50, 350);  //draws a line from (200,400) to (50, 350)
  line(50, 350, 0, 200);   //draws a lime from (50,350) to (0,200) 
  line(0, 200, 50, 50);   //draws a line from (0,200) to (50,50)
  
  stroke(255, 0, 0);   //sets the outline color to red
  fill(255, 0, 0);     //sets the fill color to red
  ellipse(200, 0, 25, 25);  //draws a 25x25 circle at (200,0)
  ellipse(400, 200, 25, 25); //draws a 25x25 circle at (400,200)
  ellipse(200, 400, 25, 25); //draws 25x25 circle at (200,400)
  ellipse(0, 200, 25, 25); //draws a 25x25 circle at (0,200)
  
  stroke(0, 255, 225);    //sets the outline color to cyan
  line(200, 150, 250, 200);  // draws a line from (200,150) to (250,200)
  line(250, 200, 200, 250);  //draws a line from (250,200) to (200,250)
  line(200, 250, 150, 200); //draws a line from (200,250) to (150,200)
  line(150, 200, 200, 150); //draws a line from (150,200) to (200,150)
  
  stroke(149, 2, 8);  //sets the outline color to medium red
  fill(149, 3, 8);   //sets the fill color to medium red
  ellipse(50, 50, 25, 25); //draws a 25x25 circle at (50,50)
}

else if (val == 3) {
  stroke(0, 255, 0);         // sets outline color to green
  fill(0, 255, 0);           //sets fill color to green
  rect(50, 50, 300, 300);   // draws 300x300 rectanlge at (50,50)
  
  stroke(14, 193, 2);      //sets outline color to a darker green
  fill(14, 193, 2);       //sets the fill color to a darker green
  rect(75, 75, 250, 250);  //draws a 250x250 retangle at (75,75)
  
  stroke(9, 144, 0);       //sets the outline color to an even darker green
  fill(9, 144, 0);         //sets the fill color to a even darker green
  rect(100, 100, 200, 200); //draws a 200x200 rectangle at (100,100) 
  
  stroke(7, 103, 1);        //sets the outline color to a still darker green
  fill(7, 103, 1);          //sets the fill color to a still darker green
  rect(125, 125, 150, 150); //draws a 150x150 rectangle at (125,125) 
  
  stroke(4, 62, 0);           //sets the outline color to the darkest green
  fill(4, 62, 0);            // sets the fill color to the darkeset green
  rect(150, 150, 100,100); //draws a 100x100 rectangle at (150,150)
  
  stroke(255, 146, 3);        //sets outline color to orange
  fill(255, 146, 3);          //sets fill color to orange
  ellipse(50, 50, 100,100);  //draws 100x100 circle at (50,50)
  ellipse(350, 50, 100, 100);  //draws 100x100 circle at (350,50)
  ellipse(50, 350, 100, 100);// draws 100x100 cirlce at (50,350)
  ellipse(350, 350, 100, 100); //draws 100x100 circle at (350,350)
  
  stroke(0, 225, 255);          //sets the outline color to cyan
  line(50, 50, 350, 350);     //draws a line from (50,50) to (350,350)
  line(50, 350, 350, 50);    //draws a line from (50, 350) to (350,350)
  fill(0, 225, 255);          // sets the fill color to cyan
  ellipseMode (CENTER);    //sets the ellipse draw mode to CENTER
  ellipse(200, 200, 100, 100); //draws a 100x100 cirlce at (200,200)
  ellipse(50, 50, 50, 50);  //draws a 50x50 circle at (50,50)
  
  stroke(3, 170, 130);     //sets the outline color to teal
  fill(65, 129, 29);      //sets the fill color to teal
  ellipse(50, 50, 25, 25);  //draws a 25x25 circle at (50,50)
  
  stroke(0, 255, 255);       //sets the outline color to cyan
  fill (0, 255, 255);       //sets the fill color to cyan
  ellipse(350, 50, 50, 50); //draws a 50x50 circle at (350,50)
  ellipse(50, 350, 50, 50); //draws a 50x50 circle at (50,350)
  ellipse(350, 350, 50, 50); //draws a 50x50 circle at (350,350)
  
  stroke(3, 170, 130);    //sets the outline color to teal
  fill(3, 170, 130);      // sets the fill color to teal
  ellipse(350, 50, 25, 25); //draws a 25x25 circle at (350,50)
  ellipse(50, 350, 25, 25); //draws a 25x25 circle at (50,350)
  ellipse(350, 350, 25, 25); //draws a 25x25 circle at (350,350)
  ellipse(200, 200, 50, 50); //draws a 50x50 circle at (200,200)
  
  stroke(0, 95, 72);       //sets the outline color to a darker teal
  fill(0, 95, 72);         //sets the fill color to a darker teal
  ellipse(200, 200, 25, 25); //draws a 25x25 circle at (200,200)
  
  stroke(3, 170, 130); //sets the outline color to teal
  line(50, 50, 200, 0); //draws a line from (50,50) to (200,0)
  line(200, 0, 350, 50); //draws a line from (200,0) to (350,50)
  line(350, 50, 400, 200); //draws a line from (350,50) to (400,200)
  line(400, 200, 350, 350); //draws a line from (400,200) to (350,350)
  line(350, 350, 200, 400); //draws a line from (350,350) to (200,400)
  line(200, 400, 50, 350);  //draws a line from (200,400) to (50, 350)
  line(50, 350, 0, 200);   //draws a lime from (50,350) to (0,200) 
  line(0, 200, 50, 50);   //draws a line from (0,200) to (50,50)
  
  stroke(0, 225, 255);   //sets the outline color cyan
  fill(0, 225, 255);     //sets the fill color to cyan
  ellipse(200, 0, 25, 25);  //draws a 25x25 circle at (200,0)
  ellipse(400, 200, 25, 25); //draws a 25x25 circle at (400,200)
  ellipse(200, 400, 25, 25); //draws 25x25 circle at (200,400)
  ellipse(0, 200, 25, 25); //draws a 25x25 circle at (0,200)
  
  stroke(255, 0, 0);    //sets the outline color to red
  line(200, 150, 250, 200);  // draws a line from (200,150) to (250,200)
  line(250, 200, 200, 250);  //draws a line from (250,200) to (200,250)
  line(200, 250, 150, 200); //draws a line from (200,250) to (150,200)
  line(150, 200, 200, 150); //draws a line from (150,200) to (200,150)
}

else {
  stroke(209);               // sets outline color to light gray
  fill(209);                 //sets fill color to light gray
  rect(50, 50, 300, 300);   // draws 300x300 rectanlge at (50,50)
  stroke(162);              //sets outline color to a darker gray
  fill(162);               //sets the fill color to a darker gray
  rect(75, 75, 250, 250);  //draws a 250x250 retangle at (75,75)
  stroke(87);             //sets the outline color to an even darker gray
  fill(87);               //sets the fill color to a even darker gray
  rect(100, 100, 200, 200); //draws a 200x200 rectangle at (100,100) 
  stroke(50);            //sets the outline color to a still darker gray
  fill(50);              //sets the fill color to a still darker gray
  rect(125, 125, 150, 150); //draws a 150x150 rectangle at (125,125) 
  stroke(25);           //sets the outline color to the darkest gray
  fill(25);            // sets the fill color to the darkeset gray
  rect(150, 150, 100,100); //draws a 100x100 rectangle at (150,150)
  stroke(200, 0, 0);        //sets outline color to red
  fill(200, 0, 0);          //sets fill color to red
  ellipse(50, 50, 100,100);  //draws 100x100 circle at (50,50)
  ellipse(350, 50, 100, 100);  //draws 100x100 circle at (350,50)
  ellipse(50, 350, 100, 100);// draws 100x100 cirlce at (50,350)
  ellipse(350, 350, 100, 100); //draws 100x100 circle at (350,350)
  stroke(0, 225, 0);          //sets the outline color to bright green
  line(50, 50, 350, 350);     //draws a line from (50,50) to (350,350)
  line(50, 350, 350, 50);    //draws a line from (50, 350) to (350,350)
  fill(0, 225, 0);          // sets the fill color to bright green
  ellipseMode (CENTER);    //sets the ellipse draw mode to CENTER
  ellipse(200, 200, 100, 100); //draws a 100x100 cirlce at (200,200)
  ellipse(50, 50, 50, 50);  //draws a 50x50 circle at (50,50)
  stroke(65, 129, 29);     //sets the outline color to a darker green
  fill(65, 129, 29);      //sets the fill color to a darker green
  ellipse(50, 50, 25, 25);  //draws a 25x25 circle at (50,50)
  stroke(0, 255, 0);       //sets the outline color to bright green
  fill (0, 255, 0);       //sets the fill color to a bright green
  ellipse(350, 50, 50, 50); //draws a 50x50 circle at (350,50)
  ellipse(50, 350, 50, 50); //draws a 50x50 circle at (50,350)
  ellipse(350, 350, 50, 50); //draws a 50x50 circle at (350,350)
  stroke(65, 129, 29);    //sets the outline color to a darker green
  fill(65, 129, 29);      // sets the fill color to a darker green
  ellipse(350, 50, 25, 25); //draws a 25x25 circle at (350,50)
  ellipse(50, 350, 25, 25); //draws a 25x25 circle at (50,350)
  ellipse(350, 350, 25, 25); //draws a 25x25 circle at (350,350)
  ellipse(200, 200, 50, 50); //draws a 50x50 circle at (200,200)
  stroke(21, 57, 1);       //sets the outline color to an even darker green
  fill(21, 57, 1);         //sets the fill color to an even darker green
  ellipse(200, 200, 25, 25); //draws a 25x25 circle at (200,200)
  stroke(65, 129, 29); //sets the outline color to the medium green
  line(50, 50, 200, 0); //draws a line from (50,50) to (200,0)
  line(200, 0, 350, 50); //draws a line from (200,0) to (350,50)
  line(350, 50, 400, 200); //draws a line from (350,50) to (400,200)
  line(400, 200, 350, 350); //draws a line from (400,200) to (350,350)
  line(350, 350, 200, 400); //draws a line from (350,350) to (200,400)
  line(200, 400, 50, 350);  //draws a line from (200,400) to (50, 350)
  line(50, 350, 0, 200);   //draws a lime from (50,350) to (0,200) 
  line(0, 200, 50, 50);   //draws a line from (0,200) to (50,50)
  stroke(0, 225, 0);   //sets the outline color to bright green
  fill(0, 225, 0);     //sets the fill color to bright green
  ellipse(200, 0, 25, 25);  //draws a 25x25 circle at (200,0)
  ellipse(400, 200, 25, 25); //draws a 25x25 circle at (400,200)
  ellipse(200, 400, 25, 25); //draws 25x25 circle at (200,400)
  ellipse(0, 200, 25, 25); //draws a 25x25 circle at (0,200)
  stroke(0, 0, 225);    //sets the outline color to blue
  line(200, 150, 250, 200);  // draws a line from (200,150) to (250,200)
  line(250, 200, 200, 250);  //draws a line from (250,200) to (200,250)
  line(200, 250, 150, 200); //draws a line from (200,250) to (150,200)
  line(150, 200, 200, 150); //draws a line from (150,200) to (200,150)
}
}
Comments