イラスト、モデリング、Unity、VR関連

unityとかblenderとかvr関連の作業メモ

Processing 自作関数

void draw_inside_circle(int cx,int cy,float r,int cnt){//外側のサークルの中心と半径
  cnt--;
  if(cnt<0return;
  float r_comp = 2*sqrt(3)/3;
  float nr = (r_comp/(1+r_comp))*r;
  float kr = r-nr;
  float rad = 30*PI/180;
  int nx,ny;
  for(int j=0;j<3;j++){
    rad += 120*PI/180;
    nx = round(cx + cos(rad)*(nr));
    ny = round(cy + sin(rad)*(nr));
    circle(nx,ny,kr*2);
    draw_inside_circle(nx,ny,kr,cnt);
  }
}
 

void draw_triangle(int cx,int cy,int r){
  float deg = 180;
  triangle(cx+r*cos*1,r*sin*2+cy,
           cx+r*cos*3,cy+r*sin*4,
           cx+r*cos*5,cy+r*sin*6
          );
}

 

void center_square(float x,float y,float len,float deg){
  float ax=len ,ay=len;
  float bx=-len,by=len;
  float cx=-len,cy=-len;
  float dx=len,dy=-len;

  float eax = rot_x(ax,ay,deg), eay = rot_y(ax,ay,deg);
  float ebx = rot_x(bx,by,deg), eby = rot_y(bx,by,deg);
  float ecx = rot_x(cx,cy,deg), ecy = rot_y(cx,cy,deg);
  float edx = rot_x(dx,dy,deg), edy = rot_y(dx,dy,deg);

  eax+=x;eay+=y;
  ebx+=x;eby+=y;
  ecx+=x;ecy+=y;
  edx+=x;edy+=y;

  line(eax,eay,ebx,eby);
  line(ebx,eby,ecx,ecy);
  line(ecx,ecy,edx,edy);
  line(edx,edy,eax,eay);

}

 

斜め網目

  rot_at_center(45);

  int line_num = 20;
  int f = 400;
  for(int i=1;i<=line_num+20;i++){
    int sx = 0-f;
    int sy = (g_h/line_num)*i-f;
    int ex = g_w+f;
    int ey = sy;
    line(sx,sy,ex,ey);
  }

  for(int i=1;i<=line_num+20;i++){
    int sx = (g_w/line_num)*i-f;
    int sy = 0-f;
    int ex = sx;
    int ey = g_h+f;
    line(sx,sy,ex,ey);  
  }

  noLoop();
}

void rot_at_center(int deg){
  translate(g_w/2,g_h/2);
  rotate(to_rad(deg));
  translate(-g_w/2,-g_h/2);
}

float to_rad(float deg){
  return deg*(PI/180);
}

float to_deg(float rad){
  return rad*(180/PI);
}

 

void keyPressed(){
  if(keyCode==ENTER){
    String fname = str(day())+str(hour())+str(minute())+str(second())+".png";
    save(fname);

    PGraphics pg = createGraphics(g_w,g_h);
    pg.beginDraw();
    pg.tint(0,0);
    PImage img = loadImage(fname);
    img.loadPixels();
    for(int j=0;j<g_w;j++){
      for(int k=0;k<g_h;k++){
        int c = img.get(j,k);
        if(!compare_color(c,g_black)){
          pg.fill(c);
          pg.stroke(c);
          pg.square(j,k,1);
        }          
      }
    }
    pg.endDraw();      
    pg.save("trans"+fname);
  }
}

 

boolean compare_color(int a,int b){
  return (red(a)==red(b) && green(a)==green(b) && blue(a)==blue(b));
}

*1:90+deg)*(PI/180

*2:90+deg)*(PI/180

*3:210+deg)*(PI/180

*4:210+deg)*(PI/180

*5:330+deg)*(PI/180

*6:330+deg)*(PI/180