【Processing】画用紙とペン

 

float x, y, x2, y2;
float xpow, ypow, rpow, xpow2, ypow2, rpow2;
float r,r2;

color clr,clr2;
int num = 1500;
float[] dpx = new float[num];
float[] dpy = new float[num];
float[] dpx2 = new float[num];
float[] dpy2 = new float[num];

void setup() {
  size(500, 500);
  x = width/2;
  y = 0;
  xpow = random(1,3);
  ypow = random(1,3);
  rpow = random(1,3);
  clr = color(250, 90, 90);
  x2 = width/2;
  y2 = 0;
  xpow2 = random(-1,-3);
  ypow2 = random(1,3);
  rpow2 = random(1,3);
  clr2 = color(90, 250, 200);
}

void draw() {
  background(250, 250, 180);

  for (int i = 0; i < num; i++) {
    strokeWeight(3);
    stroke(clr,map(i,0,num,255,0));
    point(dpx[i], dpy[i]);
    stroke(clr2,map(i,0,num,255,0));
    point(dpx2[i], dpy2[i]);    
  }

  x+= xpow;
  y+= ypow;
  r+= rpow;
  x2+= xpow2;
  y2+= ypow2;
  r2+= rpow2;
  
  
  if ( x > width + 50) {
    x = -50;
    xpow = random(1,5);
    rpow*=-1;  }
    
  if (y > height + 50) {
    y = -50; 
    ypow = random(5);
    rpow = random(0,5);
  } 
  pen(x,y,r,clr);
  
    if ( x2 < -50) {
    x2 = width + 50;
    xpow2 = random(-1,-3);
    rpow2*=-1;
  }
  
  if (y2 > height + 50) {
    y2 = -50;
    ypow2 = random(1,5);
    rpow2 = random(0,5);
  } 
  pen(x2,y2,r2,clr2);
  
  dpx[0] = x+38*sin(radians(r));
  dpy[0] = y-40*cos(radians(r));
  dpx2[0] = x2+38*sin(radians(r2));
  dpy2[0] = y2-40*cos(radians(r2));

  for (int i = num-1; i > 0; i--) {
    dpx[i] = dpx[i -1];
    dpy[i] = dpy[i -1];
    dpx2[i] = dpx2[i -1];
    dpy2[i] = dpy2[i -1];    
  }
  
}


void pen(float penx , float peny,float penr,color ccc) {

  color c = ccc;
  float _x = penx;
  float _y = peny;
  float _r = penr;

  strokeWeight(1);
  strokeCap(ROUND);
  stroke(c);

  
  pushMatrix();
  translate(_x, _y);
  rotate(radians(_r));

  fill(255);
  triangle(0, -40, 
    -10, -20, 
    10, -20);
  fill(c);
  triangle(0, -40, 
    -4, -30, 
    4, -30); 
  rectMode(CENTER);
  rect(0, 10, 20, 60);
  
  popMatrix();
}