記録

勉強したことに関するのノート。見返して分かるようにしてます。

矢印がバラバラに

int[] x = new int[9];
int[] y = new int[9];
float[]speedX = new float[9];
float[]speedY = new float[9];
color[]c=new color[9];
int a=5;
int b=5;

void setup()
{
  size(700, 800);
  colorMode(HSB, 360, 100, 100);
  background(0, 0, 0);
  x[0] = 0; 
  y[0] = 0;
  x[1] = 20; 
  y[1] = 20;
  x[2] = 40; 
  y[2] = 40;
  x[3] = 60; 
  y[3] = 60;
  x[4] = 80; 
  y[4] = 80;
  x[5] = 60; 
  y[5] = 80;
  x[6] = 40; 
  y[6] = 80;
  x[7] = 80; 
  y[7] = 60;
  x[8] = 80; 
  y[8] = 40;
  speedX[0]=a;
  speedY[0]=b;
  speedX[1]=a;
  speedY[1]=b;
  speedX[2]=a;
  speedY[2]=b;
  speedX[3]=a;
  speedY[3]=b;
  speedX[4]=a;
  speedY[4]=b;
  speedX[5]=a;
  speedY[5]=b;
  speedX[6]=a;
  speedY[6]=b;
  speedX[7]=a;
  speedY[7]=b;
  speedX[8]=a;
  speedY[8]=b;
  c[0]=color(random(360), 100, 100);
  c[1]=color(random(360), 100, 100);
  c[2]=color(random(360), 100, 100);
  c[3]=color(random(360), 100, 100);
  c[4]=color(random(360), 100, 100);
  c[5]=color(random(360), 100, 100);
  c[6]=color(random(360), 100, 100);
  c[7]=color(random(360), 100, 100);
  c[8]=color(random(360), 100, 100);
  stroke(0, 0, 100);
}

void draw() 
{ 
  int i;
  //background(0, 0, 0);
  //fill(0, 0, 0, 5);
  //rect(0, 0, width, height);

  for (i = 0; i < 9; ++i) {
    x[i] += speedX[i]; 
    y[i] += speedY[i];

    if (x[i] <= 0 || x[i] >= width) {
      speedX[i] *= -1;
      //speedX[i] *= random(0.3, 1.1);
      speedX[i]=random(-5, 5);
      //speedY[i] *= speedY[i]+random(0.9, 1);
    }

    if (y[i] <= 0 || y[i] >= height) {
      speedY[i] *= -1;
      //speedX[i] =speedX[i]+random(0.9, 1);
      speedY[i]=random(-5, 5);
      //speedY[i]*=random(0.3, 1.1);
    }

    //if (x[i] > width) {
    //  x[i]=width;
    //  speedX[i]=speedX[i]+1;
    //}
    //if (x[i] <0) {
    //  x[i]=0;
    //  speedY[i]=speedY[i]+1;
    //}
    //if (y[i] > height) {
    //  y[i]=height;
    //  speedX[i]=speedX[i]+1;
    //}
    //if (y[i] < 0) {
    //  y[i]=0;
    //  speedX[i]=speedX[i]+1;
    //}

    fill(c[i]);
    ellipse(x[i], y[i], 20, 20);
  }
}

昨日は矢印がそのまま動いていったが、今回は矢印で動いていくけどぶつかるとバラバラになる。あと、矢印の方向に進ませることにもした。しかし、size(a,a)の正方形になると、左端から右端から移動するだけなので長方形にしてます。
また、昨日からの改善点はifの条件分岐に=を足した。他はアンコメントしてたところをコメント化したり。ずっとx=0の一直線やy=0の一直線の所をうろうろしていて改善したいと思っていたらこうなった。ちょっとしたことで変わるんだなぁ。シンプルだけどしばらく悩んでたところだから、ちょっと悔しい。

矢印が動く

int[] x = new int[9];
int[] y = new int[9];
float[]speedX = new float[9];
float[]speedY = new float[9];
color[]c=new color[9];
int a=1;
int b=5;

void setup()
{
  size(800, 800);
  colorMode(HSB, 360, 100, 100);
  x[0] = 0; 
  y[0] = 0;
  x[1] = 20; 
  y[1] = 20;
  x[2] = 40; 
  y[2] = 40;
  x[3] = 60; 
  y[3] = 60;
  x[4] = 80; 
  y[4] = 80;
  x[5] = 60; 
  y[5] = 80;
  x[6] = 40; 
  y[6] = 80;
  x[7] = 80; 
  y[7] = 60;
  x[8] = 80; 
  y[8] = 40;
  speedX[0]=a;
  speedY[0]=b;
  speedX[1]=a;
  speedY[1]=b;
  speedX[2]=a;
  speedY[2]=b;
  speedX[3]=a;
  speedY[3]=b;
  speedX[4]=a;
  speedY[4]=b;
  speedX[5]=a;
  speedY[5]=b;
  speedX[6]=a;
  speedY[6]=b;
  speedX[7]=a;
  speedY[7]=b;
  speedX[8]=a;
  speedY[8]=b;
  c[0]=color(random(360), 100, 100);
  c[1]=color(random(360), 100, 100);
  c[2]=color(random(360), 100, 100);
  c[3]=color(random(360), 100, 100);
  c[4]=color(random(360), 100, 100);
  c[5]=color(random(360), 100, 100);
  c[6]=color(random(360), 100, 100);
  c[7]=color(random(360), 100, 100);
  c[8]=color(random(360), 100, 100);
}
void draw() 
{ 
  int i;
  background(0, 0, 0);
  //fill(0, 0, 0, 5);
  //rect(0, 0, width, height);

  for (i = 0; i < 9; ++i) {
    x[i] += speedX[i]; 
    y[i] += speedY[i];

    if (x[i] < 0 || x[i] > width) {
      speedX[i] *= -1;
      //speedX[i] *= random(0.3, 1.1);
      //speedX[i]=random(-5, 5);
      //speedY[i] *= speedY[i]+random(0.9, 1);
    }
    if (y[i] < 0 || y[i] > height) {
      speedY[i] *= -1;
      //speedX[i] =speedX[i]+random(0.9, 1);
      //speedY[i]=random(-5, 5);
      //speedY[i]*=random(0.3, 1.1);
    }

    ////if (x[i] > width) {
    //x[i]=width;
    //speedX[i]=speedX[i]+1;
    //}
    //  //if (x[i] <0) {
    //x[i]=0;
    //speedY[i]=speedY[i]+1;
    //}
    //  //if (y[i] > height) {
    //y[i]=height;
    //speedX[i]=speedX[i]+1;
    //}
    //  //if (y[i] < 0) {
    //y[i]=0;
    //speedX[i]=speedX[i]+1;
    //}
    //

    fill(c[i]);
    ellipse(x[i], y[i], 20, 20);
  }
}

Processing入門9 の下から2番目を使った。
アンコメントしたのを見てわかってくれ…。明日もこれ頑張ってみようかな。

丸い虹

int n=10;

void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100);
}

void draw() {
  for (int a=0; a<height+20; a=a+n) {
    for (int i=0; i<width+20; i=i+n) {
      fill(i%360, 100, 100);
      ellipse(i, a, n, n);
    }
  }
}

15行スケッチ。
メディアアート・プログラミング Ⅰ – 東京藝術大学 | yoppa org第3回47/62,48/62をellipseに変えたりstrokeつけたり円の大きさをnの値を変えると円の大きさが変わります。
今までこういうことをうまくできなかったと思う。

綺麗な柄

float d=width*2.5;

void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100);
  background(0, 0, 0);
  noStroke();
  fill(200, 100, 100, 30);
}
void draw() {
  translate(width/2, height/2);
  rotate(PI/4);
  for (int i=0; i<256; i=i+1) {
    ellipse(d/-2, 0, d, d);
    ellipse(d/2, 0, d, d);
    d=d/1.05;
    rotate(PI/24.0*4);
  }
}

参考【メディアアート・プログラミング Ⅰ – 東京藝術大学 | yoppa org第3回39/62,40/62】

ほぼコピー。voidsetupとか使うと何故か元のスケッチより小さく描画されるのを直したりしてた。あとちょっといじって違う感じにした。綺麗な柄になりました。でも全部どうなってるか理解してないのでまた勉強します。

hOI!!!

クリックしてテミ意で満たされよう!

int x=1;

void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100);
  background(180, 100, 100);
}

void draw() {
  fill(0, 0, 0);
  textAlign(CENTER);
  PFont f;
  f=createFont("MS-Gothic", 50);
  textFont(f, 40);
  text("テミ意度", width/2, 340);
}

void mousePressed() {
  noStroke();
  fill(180, 100, 100);
  rect(0, 0, 500, height/4+30);
  fill(0, 0, 0);
  int n=(int)random(3);
  if (n==0) {
    text("hOI!!!!! i'm tEMMIE!", width/2, height/4);
  }
  if (n==1) {
    text("ほい!temmieさんだよ!", width/2, height/4);
  }
  if (n==2) {
    text("ホィ!!あちし手ミーだぉ!!", width/2, height/4);
  }
  fill(180, 100, 100);
  rect(0, 350, 500, 300);
  fill(0, 0, 0);
  text(x, width/2, 400);
  x=x+1;
}

UNDERTALEというゲームの中のキャラクターのテミさんが好きです。あとゲーム音楽も頭溶けそうな曲で作業用BGMに重宝してます。無限ループです。
ランダムに表示されるのは「英語版」、「非公式日本語版」、最近出たという公式の「日本語版」でのテミさんのあいさつ文です。Open Processingでは文字が小さいですが、コピペして自分のProcessingでやると普通に見れます。

www.nicovideo.jp

www.nicovideo.jp

更新のお知らせ

更新しました。

今日は楽しかったけどとても疲れた。新しいことをすることはとても楽しい。金と時間が欲しい!!!そして最後に現在の状況の整理。

http://yetirom.hatenadiary.com/entry/2017/08/30/233314