AI画像生成、拡散モデルじゃなくてLLM(エージェント)にやらせてみる
https://gyazo.com/9f678a496e507818c78326f541f368e8
生成されたコード
code:ts
import { createCanvas } from 'canvas';
import { writeFileSync } from 'fs';
// キャンバスの作成
const width = 800;
const height = 800;
const canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');
// 背景を白で塗りつぶす
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, width, height);
// 薔薇の描画
ctx.beginPath();
ctx.fillStyle = 'red';
ctx.strokeStyle = 'darkred';
ctx.lineWidth = 2;
// 薔薇の中心部分
const centerX = width / 2;
const centerY = height / 2;
const petalSize = 100;
// 花びらを描く(簡略化した表現)
for (let angle = 0; angle < Math.PI * 2; angle += Math.PI / 8) {
ctx.beginPath();
ctx.ellipse(
centerX + Math.cos(angle) * petalSize * 0.3,
centerY + Math.sin(angle) * petalSize * 0.3,
petalSize,
petalSize / 2,
angle,
0,
Math.PI * 2
);
ctx.fill();
ctx.stroke();
}
// 中心の円を描く
ctx.beginPath();
ctx.fillStyle = 'darkred';
ctx.arc(centerX, centerY, petalSize * 0.2, 0, Math.PI * 2);
ctx.fill();
// PNGファイルとして保存
const buffer = canvas.toBuffer('image/png');
writeFileSync('./rose.png', buffer);
console.log('画像が生成されました: rose.png');
結果
https://gyazo.com/80774e7a3e126ec3243e04ddb75f4bd1
結果はまぁさておき
とりあえずスクリプト生成→ファイル生成の流れで実現自体は可能ということがわかった