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

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

AIお絵かきイラスト stable-diffusion-webui を使う

++導入方法

githubのページに書かれてる通りにやればいい。

anacondaやcudaを入れてる解説があるが入れなくてもちゃんと動いた。

zipで落としたやつだとエラーが出たのでgit cloneしたものを使用すること

GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI

 

4GB以上あってメモリが不足する場合はwebui-user.batの

set COMMANDLINE_ARGS=

set COMMANDLINE_ARGS=--medvram --opt-split-attention

に書き換えればよい、4GB未満の場合は以下にしたがってオプションを付与する

Troubleshooting · AUTOMATIC1111/stable-diffusion-webui Wiki · GitHub

int row = 256//rowとclnをいじる。rowは1024の約数にする
int cln = 8;
int ma = new int[row][cln];
int mb = new int[cln][cln];
int mc = new int[cln][row];
int mp = new int[row][row];

float cell_size;
int repeat = 1;
int mass_cell_size;
boolean sym = true;


void setup(){
  size(1024,1024);
  noStroke();  

  cell_size = height/row/repeat;
  mass_cell_size = height/repeat;
}

void draw(){
  ma = ziguzagu_mtx(ma);
  mb = initialize_mtx(mb);
  mc = trMtx(ma);
  mp = multMtx(multMtx(ma,trMtx(mb)),mc);   
  draw_p(mp,0,0,color(0),color(255));
  noLoop();
}

int ziguzagu_mtx(int m){
  m = new int[m.length][m[0].length];//0で初期化

  for(int i=0;i<row;i++){
    int z;
    if(int(i/cln)%2 == 0){
      z = i% cln;      
    }else{
      z = cln-(i%cln)-1;
    }
    m[i][z] = 1;
  }
  return m;
}

void keyPressed(){

  if(keyCode==ENTER){
    String fname = str(day())+str(minute())+str(second())+str(millis())+".png";
    save(fname);
    PGraphics pg = createGraphics(width,height);
    pg.beginDraw();
    pg.tint(0,0);
    PImage img = loadImage(fname);
    img.loadPixels();
    for(int j=0;j<width;j++){
      for(int k=0;k<height;k++){
        int c = img.get(j,k);
        if(!compare_color(c,color(0))){
          pg.fill(c);
          pg.stroke(c);
          pg.square(j,k,1);
        }          
      }
    }
    pg.endDraw();      
    pg.save("trans"+fname);
  }
  if(key=='n'){
    loop();
  }

  if(key=='s'){
    sym = sym ? false : true;
  }
}

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

void print_mtx(int m) {
  for(int i=0;i<m.length;i++){
    for(int j=0;j<m[0].length;j++){
      print(m[i][j]);
    }
    println("");
  }
}

int initialize_mtx(int m){ 
  for(int i=0;i<m.length;i++){
    for(int j=0;j<m[0].length;j++){
      m[i][j] = round(random(0,1));      
    }
  }

  if(sym){
    for(int i=0;i<m.length;i++){
      for(int j=0;j<m[0].length;j++){
        m[j][i] = m[i][j];
      }
    }
  }
  return m;
}

void draw_p(int m,float sx,float sy,color c1,color c2){
  float y = sy;
  for(int i =0;i<m.length;i++){
    float x = sx;
    for(int j = 0; j < m[0].length;j++){
      if(m[i][j] == 0){
        fill(c1);
      }else{
        fill(c2);
      }
      square(x,y,cell_size);
      x += cell_size;
    }
    y += cell_size;
  }
}


//転置行列
int trMtx(int a){
  int b = new int[a[0].length][a.length];
  for(int i=0;i<a.length;i++){
    for(int j=0;j<a[0].length;j++){
      b[j][i] = a[i][j];
    }
  }
  return b;
}

//行列の掛け算
int multMtx(int a,int b){
  int c = new int[a.length][b[0].length];
  for(int i=0;i<a.length;i++){
    for(int j=0;j<b[0].length;j++){
      int sum=0;
      for(int k=0;k<b.length;k++){
        sum += a[i][k] * b[k][j];
      }
      c[i][j] = sum;
    }
  }
  return c;
}

織り機

int row = 20;
int cln = 4;
int ma = new int[row][cln];
int mb = new int[cln][cln];
int mc = new int[cln][row];
int mp = new int[row][row];

float cell_size;
int repeat = 10;
int mass_cell_size;
void setup(){
  size(1024,1024);
  noStroke();  
  cell_size = height/row/repeat;
  mass_cell_size = height/repeat;
}

void draw(){
  ma = initialize_mtx(ma);  
  mb = initialize_mtx(mb);
  mc = initialize_mtx(mc);
  mp = multMtx(multMtx(ma,trMtx(mb)),mc);
 
  for(int i=0;i<repeat;i++){
    for(int j=0;j<repeat;j++){
      draw_p(mp,i*mass_cell_size,j*mass_cell_size,color(0),color(255));
    }
  }
  noLoop();
}
void keyPressed(){

  if(keyCode==ENTER){
    String fname = str(day())+str(minute())+str(second())+str(millis())+".png";
    save(fname);
    PGraphics pg = createGraphics(width,height);
    pg.beginDraw();
    pg.tint(0,0);
    PImage img = loadImage(fname);
    img.loadPixels();
    for(int j=0;j<width;j++){
      for(int k=0;k<height;k++){
        int c = img.get(j,k);
        if(!compare_color(c,color(0))){
          pg.fill(c);
          pg.stroke(c);
          pg.square(j,k,1);
        }          
      }
    }
    pg.endDraw();      
    pg.save("trans"+fname);
  }
  if(key=='n'){
    loop();
  }
}

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

void print_mtx(int m) {
  for(int i=0;i<m.length;i++){
    for(int j=0;j<m[0].length;j++){
      print(m[i][j]);
    }
    println("");
  }
}

int initialize_mtx(int m){ 
  for(int i=0;i<m.length;i++){
    for(int j=0;j<m[0].length;j++){
      m[i][j] = round(random(0,1));      
    }
  }
  return m;
}

void draw_p(int m,float sx,float sy,color c1,color c2){
  float y = sy;
  for(int i =0;i<m.length;i++){
    float x = sx;
    for(int j = 0; j < m[0].length;j++){
      if(m[i][j] == 0){
        fill(c1);
      }else{
        fill(c2);
      }
      if(j==m[0].length-1 || i==m.length-1){ //なぜか入る線,というか微妙に描画されない場所対策
        square(x,y,cell_size*2);
      }else{
        square(x,y,cell_size);
      }
        
      x += cell_size;
    }
    y += cell_size;
  }
}

//転置行列
int trMtx(int a){
  int b = new int[a[0].length][a.length];
  for(int i=0;i<a.length;i++){
    for(int j=0;j<a[0].length;j++){
      b[j][i] = a[i][j];
    }
  }
  return b;
}

//行列の掛け算
int multMtx(int a,int b){
  int c = new int[a.length][b[0].length];
  for(int i=0;i<a.length;i++){
    for(int j=0;j<b[0].length;j++){
      int sum=0;
      for(int k=0;k<b.length;k++){
        sum += a[i][k] * b[k][j];
      }
      c[i][j] = sum;
    }
  }
  return c;
}

二次元セル・オートマトン

//二次元セル・オートマトン mod変更で模様変えられる
int num = 128;
int mod = 8;
int state = new int[num][num];
int g_black = color(0);

void setup(){
  frameRate(10);
  size(1024,1024);
  background(g_black);  
  colorMode(HSB,100);
  initializeState();
  noStroke();
}

void draw(){
  drawcall();  
  updateState();
}

void drawcall(){
  for(int i=0;i<num;i++){
    for(int j=0;j<num;j++){
      int val = state[i][j];
      fill*1*val,100,100);
      int len = 1024/num;
      square(i*len,j*len,len);
    }
  }
}

int transition(int i,int j){
  int nextC;
  nextC = state[(i-1+num)%num][j] + 
          state[i][(j-1+num)%num] + 
          state[i][j] + 
          state[i][(j+1)%num] + 
          state[(i+1)%num][j];
  return nextC % mod;
}

void updateState(){
  int nextState = new int[num][num];
  for(int i=0;i<num;i++){
    for(int j=0;j<num;j++){
      nextState[i][j] = transition(i,j);
    }
  }
  state = nextState;
}

void initializeState(){
  for(int i=0;i<num;i++){
    for(int j=0;j<num;j++){
      if(i==num/2 && j==num/2){
        state[i][j] = 1;
      }else{
        state[i][j] = 0;
      }
    }
  }
}

*1:100/(mod+1

Processing 正六角形

int g_w = 1024;
//int g_h = 1024;
int g_h = 1024;
int g_black = color(0);
int g_white = color(255);
int g_red = color(255,0,0);
int g_green = color(0,255,0);
int g_blue = color(0,0,255);
//int g_cx = rp(0,g_w-1);
//int g_cy = rp(0,g_h-1);
int g_r = round(g_w/16);
int g_cx = 0;
int g_cy = 0;
int g_limit = 100;
int g_cnt = 0;



void setup(){
  //size(1024,1024);
  //size(1181,1024);
  size(1178,1024);//適宜サイズ調整

  noSmooth();
  background(g_black);
  //frameRate(0.5);
  //background(g_white);
  stroke(g_white);
  strokeWeight(3);
  //noStroke();
  noFill();
  //fill(g_black);
  //fill(g_white);
}

void draw(){ 
  background(g_black);
  
  int r_leng = round(g_w/(2+2*sqrt(1-sq(cos(to_rad(30))))))/2;

  int num = 100;

  int sr_leng = round(r_leng*cos(to_rad(30))) ;
  int tr_leng = round(sqrt(sq(r_leng)-sq(sr_leng)));
  for(int i=0;i<num+6;i++){
    for(int j=0;j<num+4;j++){
      if(i%2==0){
        hexagon(r_leng,sr_leng*j*2,i*(r_leng+tr_leng),30);
      }else{
        hexagon(r_leng,sr_leng*j*2-sr_leng,i*(r_leng+tr_leng),30);
      }
    }
  }

void hexagon(int leng,int x,int y,float deg){ //中点から頂点への距離,中点座標,角度
  int ax = leng*1 ;
  int ay = 0;
  int bx = round(leng*0.5);
  int by = round(leng*0.866);
  int cx = round(leng*(-0.5));
  int cy = round(leng*0.866);
  int dx = leng*(-1);
  int dy = 0;
  int ex = round(leng*(-0.5));
  int ey = round(leng*(-0.866));
  int fx = round(leng*0.5);
  int fy = round(leng*(-0.866));

  int rax = rot_x(ax,ay,deg); int ray = rot_y(ax,ay,deg);
  int rbx = rot_x(bx,by,deg); int rby = rot_y(bx,by,deg);
  int rcx = rot_x(cx,cy,deg); int rcy = rot_y(cx,cy,deg);
  int rdx = rot_x(dx,dy,deg); int rdy = rot_y(dx,dy,deg);
  int rex = rot_x(ex,ey,deg); int rey = rot_y(ex,ey,deg);
  int rfx = rot_x(fx,fy,deg); int rfy = rot_y(fx,fy,deg);
  
  rax += x;ray += y;
  rbx += x;rby += y;
  rcx += x;rcy += y;
  rdx += x;rdy += y;
  rex += x;rey += y;
  rfx += x;rfy += y;

  line(rax,ray,rbx,rby);
  line(rbx,rby,rcx,rcy);
  line(rcx,rcy,rdx,rdy);
  line(rdx,rdy,rex,rey);
  line(rex,rey,rfx,rfy);
  line(rfx,rfy,rax,ray);
}

int rot_x(int x,int y,float deg){
  float rad = to_rad(deg);
  return round( x*cos(rad) - y*sin(rad));
}

int rot_y(int x,int y,float deg){
  float rad = to_rad(deg);
  return round( x*sin(rad) + y*cos(rad));
}

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 draw_triangle(int cx,int cy,int r,int deg){
  //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 keyPressed(){
  if(keyCode==ENTER){
    String fname = str(day())+str(minute())+str(second())+str(millis())+".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