atelier:mitsuba

i love UI/UX, Blend, XAML, Behavior, P5, oF, Web, Tangible Bits and Physical computing. なにかあればお気軽にご連絡ください。atelier@c-mitsuba.com

Processingで毎秒違う内容に上書きされるcsvを作る

サンプルデータ作成用Sketch
時々必要になるたびに書き直してるので、メモ書き。

0列目は0-LineCountの値で、1列目以降は乱数

LineCountは行数
DataCountは列数
MaxValueは乱数の上限値
Secondは更新間隔
で、この辺いじくるといろいろできるはず。

int LineCount = 360;
int DataCount = 5;
int MaxValue = 100;
float Second = 1;

boolean Redraw = true;
void setup()
{
  frameRate(1/Second);
  size(300,300);
  background(0);
}

void draw()
{
  WriteFile();
  DrawView();
}

void WriteFile()
{
  String[] line = new String[LineCount];
  for(int l = 0; l<LineCount;l++){
    String data = "";
    for(int i = 0; i < DataCount; i++){      
      float d = l;
      if(i != 0){
        d = int(random(MaxValue));
      }    
      data += d;
      if(i != DataCount){
        data += ",";
      }
    }
    line[l] = data;
  }
  saveStrings("file.csv", line);
}

void DrawView()
{
  if(Redraw == true){
    background(255);
  }else{
    background(0);
  }
  Redraw = !Redraw; 
}

void stop()
{
}

できあがるCSVはこんな感じ
f:id:c-mitsuba:20151211113425p:plain

ファイル掴まないので使い勝手が良いのと、n秒おきっていうのが楽でいいかんじ。