일전에 핸드폰에 있는 통화기록으로 만들어 볼 수 있는게 없을까 생각해 보았는데,

각각의 원을 통화한 전화번호로 놓고 원의 크기는 통화량, 원이 움직이는 속도는 통화 횟수에 비례하도록

하여 화면안에서 움직이면 재밌을 것 같아 만들어 본 것입니다만, 직장에 있을 때 해보던 거라 시간이 없어서

완성은 못하고 '이런 정도의 움직이 나오지 않을까' 하는 정도에서 그만두었습니다. ^^;;

이것에다가 지난 시간 배웠던  잔상이 남는 움직임을 추가해 본 것입니다.

저희가 배우지 않은 class란 것을 사용했습니다만, 기본적으로 지난 시간 배운 배열을 사용해서 각각의 원들을

만들고 원의 움직임에 필요한 함수를 따로 만들어 제작하였습니다.

(실행후 마우스로 화면을 클릭하면 원들이 움직이고 enter를 누르면 원들이 다시 배열됩니다. )
코드를 정리 못해서 좀 지저분 합니다;;


사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지

 Pcircle[] r ;
 int dn = int(random(10,50)); //decide pnumbers received and sent
 int keypad = 200;   //keypad size
 int keycheck = 1;


 void setup()
 {
  //size(147.196);
 size(147,196+keypad);
 background(255);
  smooth();
 
  float v;          // default speed
  int total = 250;   // sum of calls
 // int stotal = 3600; //sum of sec
  r = new Pcircle[dn]; // declare r of class Pcircle
 
  for(int i = 0; i<dn ; i++){
    r[i] = new Pcircle(width/2, (height-keypad)/2, i+1, int(random(1, total-(dn-i))), int(random(80, 3600)),int(random(80,220)),int(random(80,200)),int(random(20,220)),1,1,1,1);
    total = total - r[i].call;
   // stotal = stotal - r[i].sec;
  }
//framerate(70); 
/*for mouseaction(stop & go)*/
  noLoop();
/*for mouseaction(stop & go)*/ 
 }
//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
 void draw(){
   fill(255, 12);
   rect(0,0,width,height);
   //background(255);
   if(keycheck == 1){
    for(int i = 0; i<dn ;i++){
     r[i].posUpdate();
    
    }
    for(int i = 0; i<dn ;i++){
     r[i].display();
    }
    basepad();
   }
   if(keycheck == -1){                    
     for(int i = 0; i<dn ;i++){
     r[i].lineUp();
    
    }
    for(int i = 0; i<dn ;i++){
     r[i].display();
    }
    basepad();
   }
  
 }
 ////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////
/*    mouseaction(stop & go)    */  
int lpcheck = 1;  // loop check variable
void mousePressed(){
  if(lpcheck == 1){
    loop();
   frameRate(70);
    lpcheck = lpcheck * (-1);
  }
  else{
    noLoop();
    lpcheck = lpcheck * (-1);
  }
}
/*    mouseaction(stop & go)        */


 class Pcircle
 {
     float xpos;   //x position of the circle
     float ypos;   //y position of the circle
     int   num;    // phone number
     int   call;   // number of calls
     int   sec ;   // total call time
     int tr,g,b;   // color of the circle
     int xdirection, ydirection;
     float v;      //velocity of the circle
     float cxpos;
     float cypos;
    
 
     Pcircle(float ixpos, float iypos, int inum, int icall, int isec, int itr, int ig, int ib,int ixdirection, int iydirection,float icxpos,float icypos) {
       xpos = ixpos;
       ypos = iypos;
       num = inum;
       call = icall;
       sec = isec;
       tr =itr;
       g = ig;
       b = ib;
       xdirection = ixdirection;
       ydirection = iydirection;
       cxpos = icxpos;
       cypos = icypos;
     
     }
   
     void display(){
       noStroke();
       fill(tr,g,b,190);
       //ellipse(xpos, ypos, 2*sqrt(sec), 2*sqrt(sec));  
       ellipse(xpos, ypos, sec/90, sec/90);
    
     }
     void posUpdate(){
      // float v = 50/sqrt(sec);      // velocity of the each circle
       float v = sqrt(call)/4;
       xpos = xpos + v*cos(360/dn*num)*xdirection;
       cxpos = xpos;
       ypos = ypos + v*sin(360/dn*num)*ydirection;
       cypos = ypos;
      
       if(xpos > (width-(sec/90)/2) || xpos<(sec/90)/2){
         xdirection *= -1;
       }
       if(ypos >((height-keypad)-(sec/90)/2) || ypos<(sec/90)/2){
         ydirection *= -1;
       }
     }
    
     void lineUp(){
       float a = (width/2)+60*cos(TWO_PI/dn*num);
       float b = ((height-keypad)/2)+60*sin(TWO_PI/dn*num);
       float ax = a - cxpos;
       float ay = b - cypos;
       if((abs(a-xpos)<=abs(ax/80)) && (abs(b-ypos)<=abs(ay/80))){
         xpos = a;
         ypos = b;
         }
         else{
           xpos = xpos+ax/80;
           ypos = ypos+ay/80;
           }
        }     
         
 }
 
 void keyPressed(){
   if(keyCode == ENTER){
     keycheck = -1;
   }
 }
        
    
      
 


  

Posted by 알 수 없는 사용자