塵芥回顧録

なるべく更新していきたいが、ネタがない。

斜めに流れる虹(processing)

斜めに流れる虹(processing)
f:id:nupepon:20220128134448p:plain

int countcolor = 0;
int hsb_range = 360;
int hsb_speed = 11;

void setup()
{
  frameRate(30);
  stroke(0);
  noFill();
  strokeWeight(2);
  size(400, 400);
  surface.setResizable(true);
  colorMode(HSB, hsb_range, 100, 100);
}

void draw()
{
  background(0);
  int xs, ys, xd, yd;
  int linecolor;
  for(int i = 0; i < width+height; i++) {
    linecolor = (i + hsb_range - countcolor) % hsb_range; //i+countcolorだと右下から左上へと流れる
    stroke(linecolor, 50, 50);
    xs=0; ys=i; xd=i; yd=0;
    if (ys>height) {
      ys = height;
      xs = i - height;
    }
    if (xd>width) {
      xd = width;
      yd = i - width;
    }
    line(xs, ys, xd, yd);
  }
  countcolor = (countcolor + hsb_speed) % hsb_range;
}