メインコンテンツへスキップ

タツキ爆発真のつもりがChatGPTには黄金螺旋をレイヤーとして扱う発想が苦手っぽい

    <!DOCTYPE html>
    <html lang="ja">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
      <title>グリッド&黄金螺旋レイヤー回転・反転対応</title>
      <style>
        body {
          font-family: sans-serif;
          text-align: center;
          margin: 0;
          padding: 20px;
        }
        header {
          background-color: #f2f2f2;
          padding: 10px;
          margin-bottom: 10px;
        }
        h1 {
          margin: 0;
        }
        .control-panel {
          display: flex;
          flex-wrap: wrap;
          justify-content: center;
          gap: 10px;
          margin-bottom: 10px;
        }
        .button-row {
          display: flex;
          justify-content: center;
          gap: 10px;
          margin-bottom: 10px;
        }
        canvas {
          border: 1px solid #ccc;
          max-width: 90%;
          height: auto;
        }
        .error {
          color: red;
          font-weight: bold;
        }
      </style>
    </head>
    <body>
      <header>
        <h1>黄金螺旋を縦・横・反転など自在に配置</h1>
      </header>
    
      <div class="control-panel">
        <!-- 画像アップロード -->
        <label>
          画像:
          <input type="file" id="imageInput" accept="image/*" />
        </label>
    
        <!-- グリッドタイプ -->
        <label>
          グリッド:
          <select id="gridType">
            <option value="none">なし</option>
            <option value="square">正方形マス</option>
            <option value="golden">黄金比グリッド</option>
            <option value="silver">白銀比グリッド</option>
            <option value="bronze">青銅比グリッド</option>
          </select>
        </label>
    
        <!-- 分割数(グリッド用) -->
        <label>
          分割数:
          <input type="number" id="division" min="1" max="100" value="8" />
        </label>
    
        <!-- 黄金螺旋表示チェック -->
        <label>
          <input type="checkbox" id="spiralCheckbox" />
          螺旋レイヤー表示(フィボナッチ)
        </label>
    
        <!-- 螺旋の向き -->
        <label>
          螺旋の向き:
          <select id="spiralOrientation">
            <option value="normal">Normal</option>
            <option value="rotate90">Rotate90</option>
            <option value="rotate180">Rotate180</option>
            <option value="rotate270">Rotate270</option>
            <option value="flipH">FlipH(水平反転)</option>
            <option value="flipV">FlipV(垂直反転)</option>
          </select>
        </label>
    
        <!-- 線の色 -->
        <label>
          線の色:
          <input type="color" id="lineColor" value="#ff0000" />
        </label>
    
        <!-- 線の太さ -->
        <label>
          線の太さ:
          <input type="number" id="lineWidth" min="1" max="10" value="1" />
        </label>
      </div>
    
      <div class="button-row">
        <button id="drawBtn">描画</button>
        <button id="downloadBtn">ダウンロード</button>
      </div>
    
      <canvas id="canvas"></canvas>
      <div id="errorMsg" class="error"></div>
    
      <script>
        const image = new Image();
        let isImageLoaded = false;
    
        const imageInput = document.getElementById('imageInput');
        const gridTypeSelect = document.getElementById('gridType');
        const divisionInput = document.getElementById('division');
        const spiralCheckbox = document.getElementById('spiralCheckbox');
        const spiralOrientationSelect = document.getElementById('spiralOrientation');
        const lineColorInput = document.getElementById('lineColor');
        const lineWidthInput = document.getElementById('lineWidth');
        const drawBtn = document.getElementById('drawBtn');
        const downloadBtn = document.getElementById('downloadBtn');
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');
        const errorMsg = document.getElementById('errorMsg');
    
        // 画像ファイルが選択された場合
        imageInput.addEventListener('change', (e) => {
          const file = e.target.files[0];
          if (!file) return;
    
          const reader = new FileReader();
          reader.onload = (event) => {
            image.src = event.target.result;
          };
          reader.readAsDataURL(file);
        });
    
        // 画像読み込み完了
        image.onload = () => {
          isImageLoaded = true;
          resetCanvasSize();
          drawBaseImage();
        };
    
        // 描画ボタン
        drawBtn.addEventListener('click', () => {
          if (!isImageLoaded) {
            showError('画像を選択してください。');
            return;
          }
          resetCanvasSize();
          drawAll();
        });
    
        // ダウンロードボタン
        downloadBtn.addEventListener('click', () => {
          if (!isImageLoaded) {
            showError('画像を選択してからダウンロードしてください。');
            return;
          }
          const link = document.createElement('a');
          link.download = 'grid_overlay.png';
          link.href = canvas.toDataURL('image/png');
          link.click();
        });
    
        // キャンバスサイズを画像に合わせる
        function resetCanvasSize() {
          hideError();
          const maxWidth = window.innerWidth * 0.9;
          const maxHeight = window.innerHeight * 0.7;
          let w = image.width;
          let h = image.height;
    
          // 幅がオーバー
          if (w > maxWidth) {
            const ratio = maxWidth / w;
            w = maxWidth;
            h *= ratio;
          }
          // 高さがオーバー
          if (h > maxHeight) {
            const ratio = maxHeight / h;
            h = maxHeight;
            w *= ratio;
          }
          canvas.width = w;
          canvas.height = h;
        }
    
        // 画像のみ描画
        function drawBaseImage() {
          ctx.clearRect(0, 0, canvas.width, canvas.height);
          ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
        }
    
        // まとめて描画
        function drawAll() {
          drawBaseImage();
    
          // グリッド(必要なら)
          const gridType = gridTypeSelect.value;
          if (gridType !== 'none') {
            drawGrid(gridType);
          }
    
          // 螺旋レイヤー(チェックがONなら)
          if (spiralCheckbox.checked) {
            const orientation = spiralOrientationSelect.value;
            drawFibonacciSpiralLayer(orientation);
          }
        }
    
        // グリッド描画
        function drawGrid(type) {
          const division = parseInt(divisionInput.value, 10);
          let cols = division;
          let rows = division;
    
          switch (type) {
            case 'golden':
              rows = Math.round(cols * 1.618);
              break;
            case 'silver':
              rows = Math.round(cols * 1.414);
              break;
            case 'bronze':
              rows = Math.round(cols * 1.309);
              break;
            // square (正方形) は cols=rows=division, none は描画しない
          }
    
          const color = lineColorInput.value;
          const thickness = parseInt(lineWidthInput.value, 10);
    
          ctx.strokeStyle = color;
          ctx.lineWidth = thickness;
    
          const cellW = canvas.width / cols;
          const cellH = canvas.height / rows;
    
          for (let i = 1; i < cols; i++) {
            ctx.beginPath();
            ctx.moveTo(i * cellW, 0);
            ctx.lineTo(i * cellW, canvas.height);
            ctx.stroke();
          }
          for (let j = 1; j < rows; j++) {
            ctx.beginPath();
            ctx.moveTo(0, j * cellH);
            ctx.lineTo(canvas.width, j * cellH);
            ctx.stroke();
          }
        }
    
        /**
         * 黄金螺旋(フィボナッチ式)を「レイヤー」として描画
         * orientation: Normal / rotate90 / rotate180 / rotate270 / flipH / flipV
         */
        function drawFibonacciSpiralLayer(orientation) {
          const w = canvas.width;
          const h = canvas.height;
          const color = lineColorInput.value;
          const thickness = parseInt(lineWidthInput.value, 10);
    
          ctx.save(); // 変換前の状態を保存
    
          // キャンバス中心に移動し、そこを基準に回転・反転させる
          ctx.translate(w / 2, h / 2);
    
          // orientationに応じて座標変換
          switch (orientation) {
            case 'rotate90':
              ctx.rotate(Math.PI / 2);
              break;
            case 'rotate180':
              ctx.rotate(Math.PI);
              break;
            case 'rotate270':
              ctx.rotate((3 * Math.PI) / 2);
              break;
            case 'flipH':
              ctx.scale(-1, 1);
              break;
            case 'flipV':
              ctx.scale(1, -1);
              break;
            // normalの場合は何もしない
          }
    
          // 螺旋を描く
          // ただし、今の原点(0,0)はキャンバスの中央になっているため、
          // 左下から描き始めるフィボナッチ螺旋を、中央から少し下にずらすなどの補正が必要。
          // ここでは「螺旋全体が中央近くに収まるように」適当に調整します。
    
          // ステップ数など
          const steps = 10;
          const fibo = [1, 1];
          for (let i = 2; i < steps; i++) {
            fibo[i] = fibo[i-1] + fibo[i-2];
          }
          const sumFibo = fibo.reduce((a, b) => a + b, 0);
          let scale = Math.min(w / sumFibo, h / sumFibo);
          if (scale < 0.01) scale = 0.01;
    
          // ここで「螺旋を少し左下に配置する」のが一般的ですが、
          // 中心(0,0)基準で描きたいので、下に向かってh/2相当ずらす等、
          // お好みで調整してください。
          let offsetX = - (sumFibo * scale * 0.5); // 全体幅の半分を左へ
          let offsetY = (h * 0.3);                 // 少し上へ(回転状態次第)
    
          ctx.strokeStyle = color;
          ctx.lineWidth = thickness;
    
          let x = offsetX;
          let y = offsetY;
    
          for (let i = 0; i < fibo.length; i++) {
            const side = fibo[i] * scale;
    
            ctx.beginPath();
            if (i % 2 === 0) {
              // 横方向
              y -= side;
              ctx.arc(x, y, side, 0, 0.5 * Math.PI, false);
            } else {
              // 縦方向
              x += side;
              ctx.arc(x, y, side, Math.PI, 1.5 * Math.PI, false);
            }
            ctx.stroke();
          }
    
          ctx.restore(); // 座標変換をリセット
        }
    
        function showError(msg) {
          errorMsg.textContent = msg;
        }
        function hideError() {
          errorMsg.textContent = '';
        }
      </script>
    </body>
    </html>


    <!DOCTYPE html>
    <html lang="ja">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>黄金螺旋オーバーレイ (画像選択)</title>
        <style>
            body {
                font-family: sans-serif;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                min-height: 100vh;
                background-color: #f0f0f0;
                margin: 20px;
            }
    
            /* ファイル選択エリア */
            .file-chooser {
                margin-bottom: 20px;
                padding: 15px;
                background-color: #fff;
                border-radius: 5px;
                box-shadow: 0 2px 5px rgba(0,0,0,0.1);
                text-align: center;
            }
            .file-chooser label {
                display: block; /* ラベルをブロック要素にして改行させる */
                margin-bottom: 10px;
                font-weight: bold;
            }
            /* 見た目上のボタン */
            .custom-file-button {
                display: inline-block;
                padding: 8px 15px;
                cursor: pointer;
                background-color: #007bff;
                color: white;
                border: none;
                border-radius: 4px;
                transition: background-color 0.2s ease;
            }
            .custom-file-button:hover {
                background-color: #0056b3;
            }
            /* 実際のファイル入力は非表示 */
            #image-upload {
                display: none;
            }
            #file-name {
                margin-left: 10px;
                font-style: italic;
                color: #555;
            }
    
    
            /* 画像とSVGを重ねるためのコンテナ */
            .image-container {
                position: relative;
                display: inline-block;
                max-width: 90%;
                border: 1px solid #ccc;
                margin-bottom: 20px;
                 /* 画像が読み込まれるまで最小高さを設定 (任意) */
                min-height: 200px;
                background-color: #e9e9e9; /* 画像がないときの背景 */
                display: flex; /* 中の要素を中央揃え */
                justify-content: center;
                align-items: center;
                overflow: hidden; /* 画像がコンテナからはみ出ないように */
            }
    
            /* 画像表示エリアがない場合のメッセージ */
            .image-placeholder-text {
                color: #888;
                text-align: center;
            }
    
            /* 表示する画像 */
            .image-container img {
                display: block;
                max-width: 100%;
                height: auto;
                vertical-align: bottom;
                /* 画像が読み込まれたらプレースホルダーテキストは不要になる */
            }
            .image-container img.loaded + .image-placeholder-text {
                 display: none;
            }
    
    
            /* 黄金螺旋を描画するSVGレイヤー */
            .image-container svg {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                pointer-events: none;
                visibility: hidden; /* 初期状態では非表示 */
            }
            /* 画像が読み込まれたらSVGを表示 */
            .image-container img.loaded ~ svg {
                visibility: visible;
            }
    
            #spiral-path {
                fill: none;
                stroke: yellow;
                stroke-width: 1; /* viewBox基準 */
                vector-effect: non-scaling-stroke;
            }
    
            /* --- 操作用コントロール --- */
            .controls {
                background-color: #fff;
                padding: 15px;
                border-radius: 5px;
                box-shadow: 0 2px 5px rgba(0,0,0,0.1);
                text-align: center;
                max-width: 90%;
                visibility: hidden; /* 初期状態では非表示 */
            }
             /* 画像が読み込まれたらコントロールを表示 */
            .controls.visible {
                visibility: visible;
            }
            .controls button,
            .controls label,
            .controls input,
            .controls select {
                 margin: 5px 8px;
                 padding: 5px 10px;
            }
            #stroke-width-label {
                margin-left: 15px;
            }
            #color-picker {
                vertical-align: middle;
                cursor: pointer;
            }
    
        </style>
    </head>
    <body>
    
        <h1>黄金螺旋オーバーレイ (画像選択)</h1>
    
        <!-- ファイル選択エリア -->
        <div class="file-chooser">
            <label for="image-upload" class="custom-file-button" id="custom-button">画像ファイルを選択...</label>
            <!-- accept="image/*" で画像ファイルのみ選択可能に -->
            <input type="file" id="image-upload" accept="image/*">
            <span id="file-name">選択されていません</span>
        </div>
    
        <!-- 画像表示エリア -->
        <div class="image-container" id="image-container">
            <!-- 画像はここに読み込まれる -->
            <img id="main-image" src="" alt="選択された画像">
            <!-- 画像がない場合のプレースホルダー -->
            <span class="image-placeholder-text">ここに画像が表示されます</span>
    
            <!-- 黄金螺旋SVG -->
            <svg id="golden-spiral-svg" viewBox="0 0 100 100" preserveAspectRatio="none">
                 <path id="spiral-path"
                      d="M 45,50 A 5,5 0 0 1 50,55 A 8.09,8.09 0 0 1 41.91,60 A 13.09,13.09 0 0 1 35,46.91 A 21.18,21.18 0 0 1 56.18,40 A 34.27,34.27 0 0 1 65,74.27 A 55.45,55.45 0 0 1 9.55,80"
                      />
            </svg>
        </div>
    
        <!-- 操作コントロール -->
        <div class="controls" id="controls">
             <button onclick="transformSpiral('flipX')">左右反転</button>
             <button onclick="transformSpiral('flipY')">上下反転</button>
             <button onclick="transformSpiral('rotate')">90度回転</button>
             <label for="stroke-width-slider" id="stroke-width-label">線の太さ:</label>
             <input type="range" id="stroke-width-slider" min="0.1" max="5" step="0.1" value="1" oninput="changeStyle('strokeWidth', this.value)">
             <span id="stroke-width-value">1</span>
             <label for="color-picker">線の色:</label>
             <input type="color" id="color-picker" value="#ffff00" oninput="changeStyle('strokeColor', this.value)">
         </div>
    
        <script>
            const imageUploadInput = document.getElementById('image-upload');
            const mainImage = document.getElementById('main-image');
            const fileNameSpan = document.getElementById('file-name');
            const svgElement = document.getElementById('golden-spiral-svg');
            const pathElement = document.getElementById('spiral-path');
            const strokeWidthValueSpan = document.getElementById('stroke-width-value');
            const strokeWidthSlider = document.getElementById('stroke-width-slider');
            const colorPicker = document.getElementById('color-picker');
            const controlsDiv = document.getElementById('controls');
            const customButton = document.getElementById('custom-button'); // 見た目上のボタン
    
            let currentRotation = 0;
            let scaleX = 1;
            let scaleY = 1;
    
            // --- ファイル選択処理 ---
            // 見た目上のボタンがクリックされたら、実際のinputをクリック
            customButton.addEventListener('click', () => {
                imageUploadInput.click();
            });
    
            // ファイルが選択されたときの処理
            imageUploadInput.addEventListener('change', (event) => {
                const file = event.target.files[0];
    
                if (file && file.type.startsWith('image/')) {
                    const reader = new FileReader();
    
                    reader.onload = (e) => {
                        // 画像を表示
                        mainImage.src = e.target.result;
                        mainImage.classList.add('loaded'); // 画像読み込み完了クラスを追加
                        fileNameSpan.textContent = file.name; // ファイル名を表示
    
                        // コントロールを表示状態にする
                        controlsDiv.classList.add('visible');
    
                        // 画像読み込み後にSVGの初期化を行う
                        resetSpiralTransform(); // 変換をリセット
                        applyTransform();       // スタイルを適用
                        changeStyle('strokeWidth', strokeWidthSlider.value); // 初期スタイルを再適用
                        changeStyle('strokeColor', colorPicker.value);
                    }
    
                    reader.onerror = (e) => {
                        console.error("ファイルの読み込みに失敗しました:", e);
                        fileNameSpan.textContent = "読み込みエラー";
                        mainImage.src = ""; // エラー時は画像をクリア
                        mainImage.classList.remove('loaded');
                        controlsDiv.classList.remove('visible'); // コントロールを非表示に
                    }
    
                    // ファイルをData URLとして読み込む
                    reader.readAsDataURL(file);
    
                } else if (file) {
                    // 画像ファイル以外が選択された場合
                    fileNameSpan.textContent = "画像ファイルを選択してください";
                    mainImage.src = ""; // 画像をクリア
                    mainImage.classList.remove('loaded');
                    controlsDiv.classList.remove('visible'); // コントロールを非表示に
                    // inputの値をリセットして同じファイルを選択できるようにする
                    imageUploadInput.value = '';
                } else {
                    // ファイル選択がキャンセルされた場合
                    // fileNameSpan.textContent = "選択されていません"; // そのまま or 何もしない
                }
            });
    
    
            // --- 螺旋の操作 ---
    
            // 螺旋の変形(反転、回転)を適用する関数
            function applyTransform() {
                svgElement.style.transform = `scale(${scaleX}, ${scaleY}) rotate(${currentRotation}deg)`;
            }
    
            // 変換をリセットする関数 (新しい画像が読み込まれたときに呼ぶ)
            function resetSpiralTransform() {
                currentRotation = 0;
                scaleX = 1;
                scaleY = 1;
                // スタイルはリセットしない(ユーザーが設定した色や太さは維持)
            }
    
            // ボタンクリックで呼び出される関数
            function transformSpiral(type) {
                if (!mainImage.classList.contains('loaded')) return; // 画像がない場合は何もしない
    
                if (type === 'flipX') {
                    scaleX *= -1;
                } else if (type === 'flipY') {
                    scaleY *= -1;
                } else if (type === 'rotate') {
                    currentRotation = (currentRotation + 90) % 360;
                }
                applyTransform();
            }
    
            // スタイル(線の太さ、色)を変更する関数
            function changeStyle(styleType, value) {
                if (styleType === 'strokeWidth') {
                    pathElement.style.strokeWidth = value;
                    strokeWidthValueSpan.textContent = parseFloat(value).toFixed(1);
                    pathElement.style.vectorEffect = 'non-scaling-stroke'; // 念のため再適用
                } else if (styleType === 'strokeColor') {
                    pathElement.style.stroke = value;
                }
            }
    
            // --- 初期化 ---
            // 初期状態ではコントロールは非表示、スタイルはデフォルト値にしておく
            // スタイルコントロールの初期値を設定しておく(表示されるときに反映される)
            changeStyle('strokeWidth', strokeWidthSlider.value);
            changeStyle('strokeColor', colorPicker.value);
    
        </script>
    
    </body>
    </html>


    ChatGPTよりはマシくらいGemini

    之を代替に使ってくれ

    あなたへのおすすめ