【Processing】Processingで干支の犬をかく

f:id:osushi_94:20180102012304p:plain

 

年賀状出さないけど、きたものには返すことにしている。

今年も届いたので作るんだけど、せっかくなんでProcessingで犬を描くことにした。

Processingで作る意義として、色と顔とサイズがそれぞれ若干異なる犬を生成できるようにした。

 

void setup(){
size(1000,1000);
background(255);
}



void draw(){
pushMatrix();
translate(random(-100,width),random(-100,height));
scale(random(1));
dog();
popMatrix();

saveFrame("data/######.png");

}

void dog(){
color a = color(random(100,255),random(100,255),random(255));
color b = color(random(255),random(255),random(255));
color c = color(random(200,255),random(200,255),random(200,255));
color d = color(255,random(255),random(255));

stroke(0);
strokeWeight(2);
//犬の輪郭
fill(a);
beginShape();
vertex(20,30);//スタート
quadraticVertex(10,70,50,70); //あご左
quadraticVertex(90,70,80,30); //あご右
quadraticVertex(80,0,60,20); //右耳
quadraticVertex(50,15,40,20); //頭のボッコリ
quadraticVertex(20,0,20,30); //左耳
endShape(CLOSE);


//耳
fill(b);
beginShape();
vertex(25,28);//スタート
quadraticVertex(24,8,35,21); //頭のボッコリ
endShape(CLOSE);
beginShape();
vertex(75,28);//スタート
quadraticVertex(76,8,65,21); //頭のボッコリ
endShape(CLOSE);


//口の周り
noStroke();
fill(c);
ellipse(50,55,30,20);//口の周り

//ほほ
noStroke();
fill(d);
ellipse(30,50,10,5);//左
ellipse(70,50,10,5);//右


//目と鼻
stroke(0);
strokeWeight(2);
fill(0);
float eyesize = random(1,6);
float nosesize = random(5,10);


ellipse(40,40,eyesize,eyesize);//左め
ellipse(60,40,eyesize,eyesize);//右目
ellipse(50,50,nosesize,nosesize);//鼻


//口
stroke(0);
strokeWeight(2);
noFill();
beginShape();
vertex(40,60);
quadraticVertex(50,60,50,50);
quadraticVertex(50,60,60,60); 
endShape();
}