const w=400;
const N=9;
const d=w/N;
const col = ["#52b788", "#333"];
function setup() {
createCanvas(w, w);
noStroke();
noLoop();
}
function draw() {
for(let i=0;i<N;i++){
const x = d*i;
for(let j=0;j<N;j++){
const y = d*j;
push();
translate(x, y);
fill(col[(i+j)%2]);
rect(0, 0, d);
pop();
}
}
}
ギンガムチェック
function setup() {
createCanvas(400, 400);
}
function draw(){
background(255);
noStroke();
const step = 20;
for (let y = 0; y <= height; y += step) {
if(y % (step*2) == 0){
for (let x = 0 ; x <= width; x += step) {
if(x % (step*2) == 0){
fill('rgba(153,204,255,1)');
rect(x, y, step, step);
}else{
fill('rgba(153,204,255,0.65)');
rect(x, y, step, step);
}
}
}else{
for (let x = 0; x <= width; x += step*2) {
fill('rgba(153,204,255,0.65)');
rect(x, y, step, step);
}
}
}
}
ハートマーク
const w = 500;
const h = 500;
const size = 20;
const space = 40;
const color1 = "#eac7cd";
const color2 = "#dd9dbf";
function setup() {
createCanvas(w, h);
background(color1);
}
function draw() {
noStroke();
for (x = 0; x <= width; x += space) {
for (y = 0; y <= height; y += space) {
fill(color2);
heart(x, y, size);
}
}
}
function heart(x, y, size) {
beginShape();
vertex(x, y);
bezierVertex(x - size / 2, y - size / 2, x - size, y + size / 3, x, y + size); //ベジェ曲線 描画
bezierVertex(x + size, y + size / 3, x + size / 2, y - size / 2, x, y); //ベジェ曲線 描画
endShape(CLOSE);
}
コメント