ウェブサイトのアイコンを作れるペイントのようなサイトを作ってください
- User
ウェブサイトのアイコンを作れるペイントのようなサイトを作ってください
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
ウェブサイトのアイコンを作れるペイントのようなサイトを作ってください
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
シンプルなオンラインペイントツールを作成するためのHTMLとJavaScriptのコードを提案します。このツールでは16x16ピクセルのアイコンを作成できます。
<!DOCTYPE html>
<html>
<head>
<title>アイコンメーカー</title>
<style>
#canvas {
border: 1px solid black;
}
.color-picker {
margin: 10px 0;
}
.tools {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="tools">
<input type="color" id="colorPicker" class="color-picker">
<button onclick="clearCanvas()">クリア</button>
<button onclick="downloadIcon()">保存</button>
</div>
<canvas id="canvas" width="160" height="160"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const colorPicker = document.getElementById('colorPicker');
let isDrawing = false;
const pixelSize = 10; // 1ピクセルを10倍に拡大表示
// グリッド線を描画
function drawGrid() {
ctx.strokeStyle = '#ddd';
for(let i = 0; i <= canvas.width; i += pixelSize) {
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i, canvas.height);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, i);
ctx.lineTo(canvas.width, i);
ctx.stroke();
}
}
// キャンバスをクリア
function clearCanvas() {
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
drawGrid();
}
// アイコンを保存
function downloadIcon() {
const link = document.createElement('a');
link.download = 'icon.png';
link.href = canvas.toDataURL();
link.click();
}
// マウスイベントの処理
canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);
canvas.addEventListener('mouseleave', stopDrawing);
function startDrawing(e) {
isDrawing = true;
draw(e);
}
function draw(e) {
if (!isDrawing) return;
const rect = canvas.getBoundingClientRect();
const x = Math.floor((e.clientX - rect.left) / pixelSize) * pixelSize;
const y = Math.floor((e.clientY - rect.top) / pixelSize) * pixelSize;
ctx.fillStyle = colorPicker.value;
ctx.fillRect(x, y, pixelSize, pixelSize);
}
function stopDrawing() {
isDrawing = false;
}
// 初期化
clearCanvas();
</script>
</body>
</html>
このコードで作成されるツールには以下の機能があります:
使い方:
このコードをHTMLファイルとして保存して開くと、すぐに使用できます。必要に応じて機能を追加したり、UIをカスタマイズしたりできます。
一括でダウンロードさせてください
以下のコードは、作成したアイコンを異なるサイズ(16x16, 32x32, 48x48)で一括ダウンロードできるように改良したバージョンです。ZIPファイルとしてダウンロードするために、JSZipライブラリを使用します。
<!DOCTYPE html>
<html>
<head>
<title>アイコンメーカー</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
<style>
#canvas {
border: 1px solid black;
}
.color-picker {
margin: 10px 0;
}
.tools {
margin-bottom: 10px;
}
#preview-container {
display: flex;
gap: 10px;
margin-top: 10px;
}
.preview-canvas {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="tools">
<input type="color" id="colorPicker" class="color-picker">
<button onclick="clearCanvas()">クリア</button>
<button onclick="downloadAllSizes()">全サイズをダウンロード</button>
</div>
<canvas id="canvas" width="160" height="160"></canvas>
<div id="preview-container">
<div>
<p>16x16</p>
<canvas id="preview16" width="16" height="16" class="preview-canvas"></canvas>
</div>
<div>
<p>32x32</p>
<canvas id="preview32" width="32" height="32" class="preview-canvas"></canvas>
</div>
<div>
<p>48x48</p>
<canvas id="preview48" width="48" height="48" class="preview-canvas"></canvas>
</div>
</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const colorPicker = document.getElementById('colorPicker');
let isDrawing = false;
const pixelSize = 10;
// プレビューキャンバスの取得
const preview16 = document.getElementById('preview16');
const preview32 = document.getElementById('preview32');
const preview48 = document.getElementById('preview48');
function drawGrid() {
ctx.strokeStyle = '#ddd';
for(let i = 0; i <= canvas.width; i += pixelSize) {
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i, canvas.height);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, i);
ctx.lineTo(canvas.width, i);
ctx.stroke();
}
}
function clearCanvas() {
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
drawGrid();
updatePreviews();
}
// プレビューの更新
function updatePreviews() {
const sizes = [
{ canvas: preview16, size: 16 },
{ canvas: preview32, size: 32 },
{ canvas: preview48, size: 48 }
];
sizes.forEach(({canvas, size}) => {
const ctx = canvas.getContext('2d');
ctx.imageSmoothingEnabled = false;
ctx.clearRect(0, 0, size, size);
ctx.drawImage(canvas, 0, 0, 160, 160, 0, 0, size, size);
});
}
// 全サイズのアイコンをZIPファイルでダウンロード
async function downloadAllSizes() {
const zip = new JSZip();
const sizes = [16, 32, 48];
// 一時キャンバスを作成
const tempCanvas = document.createElement('canvas');
const tempCtx = tempCanvas.getContext('2d');
tempCtx.imageSmoothingEnabled = false;
// 各サイズのアイコンを生成してZIPに追加
for (const size of sizes) {
tempCanvas.width = size;
tempCanvas.height = size;
tempCtx.drawImage(canvas, 0, 0, 160, 160, 0, 0, size, size);
const blob = await new Promise(resolve => {
tempCanvas.toBlob(resolve, 'image/png');
});
zip.file(`icon_${size}x${size}.png`, blob);
}
// ZIPファイルを生成してダウンロード
const content = await zip.generateAsync({type: 'blob'});
const link = document.createElement('a');
link.href = URL.createObjectURL(content);
link.download = 'icons.zip';
link.click();
URL.revokeObjectURL(link.href);
}
canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);
canvas.addEventListener('mouseleave', stopDrawing);
function startDrawing(e) {
isDrawing = true;
draw(e);
}
function draw(e) {
if (!isDrawing) return;
const rect = canvas.getBoundingClientRect();
const x = Math.floor((e.clientX - rect.left) / pixelSize) * pixelSize;
const y = Math.floor((e.clientY - rect.top) / pixelSize) * pixelSize;
ctx.fillStyle = colorPicker.value;
ctx.fillRect(x, y, pixelSize, pixelSize);
updatePreviews();
}
function stopDrawing() {
isDrawing = false;
}
clearCanvas();
</script>
</body>
</html>
この改良版には以下の機能が追加されています:
リアルタイムプレビュー
一括ダウンロード機能
icon_16x16.png、icon_32x32.png、icon_48x48.png となります使い方:
注意点:
必要に応じて、さらにサイズを追加したり、UIをカスタマイズしたりできます。