Back to Parent

//PROCESSING CODE

import processing.serial.*;

Serial mySerial;

String myString = null;

int image_num=6;
int image2_num=7;   
float max_potval=256;  
int screen_width=2736; 
int screen_height=1824;
int image_width=1000;
int image_height=1000;
int image_separation=100;
int pin_number=6;
int timelineentry_num=5;

PImage[] imgs=new PImage[image_num];
PImage[] imgs2=new PImage[image2_num];

float seg_length=max_potval/timelineentry_num; //=max potentiometer value/ # of images 

float seg2_length=max_potval/pin_number; //=max potentiometer value/ # of images

float ratio=(5*image_width+5*image_separation)/max_potval; //=width of screen/ max potentiometer value 

int[][] image_pos={{screen_width/2,screen_height/2},
{-3*image_width-4*image_separation,screen_height/2},
{-2*image_width-3*image_separation,screen_height/2},
{-1*image_width-1*image_separation,screen_height/2},
{0*image_width-0*image_separation,screen_height/2},
{1*image_width+1*image_separation,screen_height/2},
{2*image_width+2*image_separation,screen_height/2}};
int[][] image2_pos={{screen_width/2,screen_height/2},
{300,screen_height/2-500},
{450,screen_height/2-250},
{610,screen_height/2-500},
{1000,screen_height/2-320},
{1900,screen_height/2-350},
{1950,screen_height/2-300}};  
float position=0;
float oldposition;
String[] image_file={"City.PNG","Facebook.PNG","Marriage.PNG","Family.PNG","Graduation.PNG","Congress.PNG"};  
String[] image2_file={"City.PNG","PIN.png","PIN.png","PIN.png","PIN.png","PIN.png","PIN.png"};  
int translate_switch=0;
String[] txt1= {"February 4, 2004"," May 19, 2012","December 1, 2015","May 28, 2017","April 10 & 11, 2018"};
String[] txt2= {"",
"",
"Mark Zuckerberg and wife Dr. Priscilla Chans 2-year-old daughter Maxima hit a milestone this week: her first day of preschool-January 19, 2018",  
"",
"",
"Facebook stands with many technology companies to protect you and your information. Facebook post (March 2016)", 
""};
float dif_pos=0.0;
   //______________________________________________________________________________________________________________________________



void setup()
{
//size(screen_width,screen_height);

//background(59,89,152);

String myPort= Serial.list() [2];
mySerial=new Serial(this, myPort, 9600);
fullScreen();
for(int k=0;k<image_num;k++)
{
imgs[k]=loadImage(image_file[k]);
}
for(int p=0;p<image2_num;p++)
{
imgs2[p]=loadImage(image2_file[p]);
}
imgs[0].resize(screen_width,screen_height);
imgs2[0].resize(screen_width,screen_height);
}

   //______________________________________________________________________________________________________________________________

void draw()
{
  imageMode(CENTER);
  rectMode(CENTER);
  int[] myArray=new int[3];
  myString=null;
  mySerial.write("1\n");
  while (mySerial.available()>0)
  {
   myString= mySerial.readStringUntil('\n');
   trim(myString);
   int j=0;
   myArray[1]=0;
   if (myString!=null)
   {
    for (int i=0; myString.charAt(i)!='\n'; i++)
    {
      if (myString.charAt(i)==',')
      {
        j++;
      }
      else if( myString.charAt(i)!='\r')
      {
        myArray[j]=myArray[j]*10+(myString.charAt(i)-48);
      }
    }

       
   //______________________________________________________________________________________________________________________________

    
    
    if (translate_switch==0)
    {
      //background(59,89,152);

      image(imgs[0],image_pos[0][0],image_pos[0][1]);
     // oldposition=position;

      position= -myArray[1]*ratio;
      //dif_pos=dif_pos+position-oldposition;

     // println(dif_pos);

      int photo_index= abs(4-int(myArray[1]/seg_length));   // goes from 0 to image_num-1

      //println(photo_index);

     // translate(-dif_pos,0);

     // println(photo_index);

      for(int i=1;i<image_num;i++)
      {
        image(imgs[i],image_pos[i][0]-position,image_pos[i][1],image_width,image_height); 
        fill(0);
        textAlign(CENTER);        
        textSize(60);
        text(txt1[i-1],image_pos[i][0]-position,image_pos[i][1]-image_height/2-100,1000,200);
      }
      
      if (myArray[0]==1 && photo_index==4)
      {
        translate_switch=1;
       }
      else if (myArray[0]==1 && photo_index!=4)
      {
        translate_switch=2;
      }
    }

   //_____________________________________________________________________________________________________________________________ 

    
    else if (translate_switch==1)
    {

      background(imgs2[0]);
      int photo2_index= int(myArray[1]/seg2_length)+1;
      println(photo2_index);
      for(int i=1;i<7;i++)
      { if(i!=photo2_index)
        {
        pushMatrix();
        translate(image2_pos[i][0],image2_pos[i][1]);
        scale(0.075);
        translate(-image2_pos[i][0],-image2_pos[i][1]);
        image(imgs2[1],image2_pos[i][0],image2_pos[i][1]); 
        popMatrix();
        }
      }
     
      pushMatrix();
      translate(image2_pos[photo2_index][0],image2_pos[photo2_index][1]-30);
      scale(2);
      translate(-(image2_pos[photo2_index][0]),-(image2_pos[photo2_index][1]+30));
      image(imgs2[photo2_index],image2_pos[photo2_index][0],image2_pos[photo2_index][1],200,200);
      popMatrix();
      if (myArray[0]==1)
      {
        translate_switch=3;
      }
      if (myArray[2]==1)
      {
        translate_switch=0;
      }
    
    }
    
    else if (translate_switch==2)
    {
    background(0);
    textSize(40);
    textAlign(CENTER);
    text("Sorry, this page is still under construction.",screen_width/2,screen_height/2);
    if (myArray[2]==1)
    {
    translate_switch=0;
    }
    }
    else if (translate_switch==3)
    {
    int photo2_index= int(myArray[1]/seg2_length);
     println(photo2_index);
    // rect(screen_width/2,screen_height/2+750,screen_width,300);

     textSize(40);
     //stroke(0);

     //

    fill(250); 
    textAlign(CENTER);
    text(txt2[photo2_index],screen_width/2,screen_height/2+750,screen_width,300);
    // strokeWeight(0);

     if (myArray[2]==1)
    {
    translate_switch=1;
    }
    
    }
   //_____________________________________________________________________________________________________________________________ 

  
   } 
   
  }
  
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0