アートワーク2
let penThickness = 3; // ペンの太さを設定
function setup() {
createCanvas(800, 800); // キャンバスのサイズを1600x1600に変更
noLoop();
textAlign(CENTER, CENTER); // テキストの配置を中央に設定
textSize(32); // テキストのサイズを設定
}
function draw() {
background(255);
let start = createVector(100, 400); // 開始位置を調整
let end = createVector(700, 400); // 終了位置を調整
drawKochLine(start, end, 5);
// テキストを描画
fill(0); // テキストの色を黒に設定
text('Plain Music', 200, 500); // テキストをキャンバスの中央上部に描画
}
function drawKochLine(start, end, depth) {
if (depth == 0) {
drawCrayonLine(start.x, start.y, end.x, end.y);
} else {
let v = p5.Vector.sub(end, start);
v.div(5);
let a = start.copy();
let b = start.copy().add(v);
let c = b.copy().add(p5.Vector.fromAngle(-PI / 3).mult(v.mag()));
let d = start.copy().add(v.mult(2));
let e = end.copy();
drawKochLine(a, b, depth - 1);
drawKochLine(b, c, depth - 1);
drawKochLine(c, d, depth - 1);
drawKochLine(d, e, depth - 1);
}
}
function drawCrayonLine(x1, y1, x2, y2) {
let steps = dist(x1, y1, x2, y2) / 2;
strokeWeight(penThickness); // ペンの太さを設定
for (let i = 0; i < steps; i++) {
let x = lerp(x1, x2, i / steps) + random(-1, 1);
let y = lerp(y1, y2, i / steps) + random(-1, 1);
point(x, y);
}
}
function mousePressed() {
saveCanvas('koch_curve', 'png');
}
よろしければサポートお願いします!