• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Copilot rysowanie

+2 głosów
256 wizyt
pytanie zadane 26 listopada 2024 w Offtop przez TOWaD Mądrala (6,630 p.)
Czy komuś udało się narysować czarny prostokąt na białym tle przy pomocy copilot lub innego AI. Bo jakoś u mnie to się nie udaje. Jakieś tylko jakieś  rysunki nie wiadomo czego.
komentarz 26 listopada 2024 przez TOWaD Mądrala (6,630 p.)

Jednak potrafi, co prawda niebieski ale ok.

<!DOCTYPE html>
<html lang="pl">
<head>
    <meta charset="UTF-8">
    <title>Kształty w SVG</title>
    <style>
        .icon {
            cursor: pointer;
            margin: 10px;
        }
        #drawingArea {
            border: 1px solid black;
            width: 400px;
            height: 400px;
        }
    </style>
</head>
<body>
    <h1>Kliknij ikonę, aby narysować kształt</h1>
    <div>
        <!-- Ikony -->
        <svg class="icon" id="rectangleIcon" width="50" height="50">
            <rect width="50" height="50" fill="none" stroke="blue" />
        </svg>
        <svg class="icon" id="circleIcon" width="50" height="50">
            <circle cx="25" cy="25" r="20" fill="none" stroke="green" />
        </svg>
        <svg class="icon" id="triangleIcon" width="50" height="50">
            <polygon points="25,5 45,45 5,45" fill="none" stroke="red" />
        </svg>
        <svg class="icon" id="iBeamIcon" width="50" height="50">
            <polyline points="10,10 40,10 40,20 30,20 30,40 40,40 40,50 10,50 10,40 20,40 20,20 10,20 10,10" fill="none" stroke="orange" />
        </svg>
    </div>
    <button id="saveButton">Zapisz jako PNG</button>
    <div id="drawingArea">
        <!-- Obszar do rysowania -->
    </div>
    <script>
        function drawShape(type) {
            const width = prompt("Podaj szerokość:", 100);
            const height = prompt("Podaj wysokość:", 100);
            const svgNS = "http://www.w3.org/2000/svg";
            const drawingArea = document.getElementById("drawingArea");
            drawingArea.innerHTML = ''; // Wyczyść poprzednie rysunki
            const svg = document.createElementNS(svgNS, "svg");
            svg.setAttribute("width", 400);
            svg.setAttribute("height", 400);
            svg.setAttribute("viewBox", "0 0 400 400");

            if (type === 'rectangle') {
                const rect = document.createElementNS(svgNS, "rect");
                rect.setAttribute("x", 150);
                rect.setAttribute("y", 150);
                rect.setAttribute("width", width);
                rect.setAttribute("height", height);
                rect.setAttribute("fill", "none");
                rect.setAttribute("stroke", "blue");
                svg.appendChild(rect);
            } else if (type === 'circle') {
                const circle = document.createElementNS(svgNS, "circle");
                const radius = width / 2;
                circle.setAttribute("cx", 200);
                circle.setAttribute("cy", 200);
                circle.setAttribute("r", radius);
                circle.setAttribute("fill", "none");
                circle.setAttribute("stroke", "green");
                svg.appendChild(circle);
            } else if (type === 'triangle') {
                const triangle = document.createElementNS(svgNS, "polygon");
                const points = `200,${200 - height / 2} ${200 + width / 2},${200 + height / 2} ${200 - width / 2},${200 + height / 2}`;
                triangle.setAttribute("points", points);
                triangle.setAttribute("fill", "none");
                triangle.setAttribute("stroke", "red");
                svg.appendChild(triangle);
            } else if (type === 'iBeam') {
                const iBeam = document.createElementNS(svgNS, "polyline");
                const points = `
                    ${200 - width / 2},${200 - height / 2} 
                    ${200 + width / 2},${200 - height / 2} 
                    ${200 + width / 2},${200 - height / 4} 
                    ${200 + width / 4},${200 - height / 4} 
                    ${200 + width / 4},${200 + height / 4} 
                    ${200 + width / 2},${200 + height / 4} 
                    ${200 + width / 2},${200 + height / 2} 
                    ${200 - width / 2},${200 + height / 2} 
                    ${200 - width / 2},${200 + height / 4} 
                    ${200 - width / 4},${200 + height / 4} 
                    ${200 - width / 4},${200 - height / 4} 
                    ${200 - width / 2},${200 - height / 4}`;
                iBeam.setAttribute("points", points);
                iBeam.setAttribute("fill", "none");
                iBeam.setAttribute("stroke", "orange");
                svg.appendChild(iBeam);
            }

            drawingArea.appendChild(svg);
        }

        function saveAsPNG() {
            const drawingArea = document.getElementById("drawingArea");
            const svg = drawingArea.querySelector("svg");
            const serializer = new XMLSerializer();
            const source = serializer.serializeToString(svg);

            const img = new Image();
            img.src = 'data:image/svg+xml;base64,' + btoa(source);

            img.onload = function() {
                const canvas = document.createElement("canvas");
                canvas.width = 400;
                canvas.height = 400;
                const ctx = canvas.getContext("2d");
                ctx.drawImage(img, 0, 0);

                const a = document.createElement("a");
                a.download = "shape.png";
                a.href = canvas.toDataURL("image/png");
                a.click();
            };
        }

        document.getElementById("rectangleIcon").onclick = function() { drawShape('rectangle'); };
        document.getElementById("circleIcon").onclick = function() { drawShape('circle'); };
        document.getElementById("triangleIcon").onclick = function() { drawShape('triangle'); };
        document.getElementById("iBeamIcon").onclick = function() { drawShape('iBeam'); };
        document.getElementById("saveButton").onclick = saveAsPNG;
    </script>
</body>
</html>

komentarz 28 listopada 2024 przez Distracted_bez_hasła Początkujący (370 p.)

@TOWaD, Znam to

Zaloguj lub zarejestruj się, aby odpowiedzieć na to pytanie.

Podobne pytania

–1 głos
0 odpowiedzi 143 wizyt
pytanie zadane 11 października 2019 w Java przez Rafin Nowicjusz (160 p.)
0 głosów
1 odpowiedź 790 wizyt
pytanie zadane 8 grudnia 2017 w HTML i CSS przez bulgotnik86 Gaduła (3,040 p.)
0 głosów
0 odpowiedzi 267 wizyt
pytanie zadane 10 grudnia 2019 w Algorytmy przez maonthe Początkujący (270 p.)

93,631 zapytań

142,553 odpowiedzi

323,056 komentarzy

63,139 pasjonatów

Advent of Code 2025

Top 15 użytkowników

  1. 2900p. - dia-Chann
  2. 2870p. - DziarnowskiJ
  3. 2827p. - Łukasz Piwowar
  4. 2783p. - raydeal
  5. 2713p. - rucin93
  6. 2579p. - Łukasz Eckert
  7. 2529p. - Adrian Wieprzkowicz
  8. 2459p. - CC PL
  9. 2184p. - Maurycy W
  10. 2082p. - Michal Drewniak
  11. 1885p. - robwarsz
  12. 1811p. - rafalszastok
  13. 1600p. - Rafał Trójniak
  14. 1588p. - Tomasz Bielak
  15. 1494p. - ssynowiec
Szczegóły i pełne wyniki

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Kursy INF.02 i INF.03
...