Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
<head>
    <title>Рисование параметрических кривых</title>

</head>
<body>
    <canvas id="myCanvas" width="800" height="800"></canvas>
</body>
</html>
              
            
!

CSS

              
                canvas {
            border: 1px solid black;
        }
              
            
!

JS

              
                  const canvas = document.getElementById('myCanvas');
        const ctx = canvas.getContext('2d');

        // Параметрическое уравнение окружности
        function drawCircle(centerX, centerY, radius) {
            ctx.beginPath();
            for (let t = 0; t <= 2 * Math.PI; t += 0.01) {
                const x = centerX + radius * Math.sin(t);
                const y = centerY + radius * Math.cos(t);
                if (t === 0) {
                    ctx.moveTo(x, y);
                } else {
                    ctx.lineTo(x, y);
                }
            }
            ctx.closePath();
            ctx.stroke();
        }

       // Параметрическое уравнение окружности
        function drawCircle_fill(centerX, centerY, radius) {
            ctx.beginPath();
            for (let t = 0; t <= 2 * Math.PI; t += 0.01) {
                const x = centerX + radius * Math.sin(t);
                const y = centerY + radius * Math.cos(t);
                if (t === 0) {
                    ctx.moveTo(x, y);
                } else {
                    ctx.lineTo(x, y);
                }
            }
            ctx.closePath();
            ctx.fill();
        }
      
        // Параметрическое уравнение спирали
        function drawSpiral(centerX, centerY, maxT) {
            ctx.beginPath();
            for (let t = 0; t <= maxT; t += 0.01) {
                const x = centerX + t * Math.sin(t);
                const y = centerY + t * Math.cos(t);
                if (t === 0) {
                    ctx.moveTo(x, y);
                } else {
                    ctx.lineTo(x, y);
                }
            }
            ctx.stroke();
        }

       

        // Рисование координатной сетки
        function drawGrid() {
            ctx.strokeStyle = 'lightgray';
            for (let i = 0; i < canvas.width; i += 50) {
                ctx.beginPath();
                ctx.moveTo(i, 0);
                ctx.lineTo(i, canvas.height);
                ctx.stroke();
            }
            for (let i = 0; i < canvas.height; i += 50) {
                ctx.beginPath();
                ctx.moveTo(0, i);
                ctx.lineTo(canvas.width, i);
                ctx.stroke();
            }
            // Рисование осей X и Y
            ctx.strokeStyle = 'black';
            ctx.beginPath();
            ctx.moveTo(canvas.width / 2, 0);
            ctx.lineTo(canvas.width / 2, canvas.height);
            ctx.stroke(); // ось Y
            ctx.beginPath();
            ctx.moveTo(0, canvas.height / 2);
            ctx.lineTo(canvas.width, canvas.height / 2);
            ctx.stroke(); // ось X
        }

      // Функция бета-сплайна
      function betaSpline(coor){
    ctx.beginPath();
    for(let i = 1; i < coor.length - 2; i++){
        // Коэффициенты
        let a0 = (coor[i - 1].x + 4 * coor[i].x + coor[i + 1].x) / 6;
        let a1 = (-coor[i-1].x + coor[i+1].x) / 2;
        let a2 = (coor[i - 1].x - 2 * coor[i].x + coor[i + 1].x) / 2;
        let a3 = (-coor[i - 1].x + 3 * coor[i].x - 3 * coor[i + 1].x + coor[i + 2].x) / 6;
        let b0 = (coor[i - 1].y + 4 * coor[i].y + coor[i + 1].y) / 6;
        let b1 = (-coor[i - 1].y + coor[i + 1].y) / 2;
        let b2 = (coor[i - 1].y - 2 * coor[i].y + coor[i + 1].y) / 2;
        let b3 = (-coor[i - 1].y + 3 * coor[i].y - 3 * coor[i + 1].y + coor[i + 2].y) / 6;
        let t = 0;
        ctx.moveTo(a0, b0);
        while (t <= 1){
            let x = ((a3 * t + a2) * t + a1) * t + a0;
            let y = ((b3 * t + b2) * t + b1) * t + b0;
            ctx.lineTo(x, y);
            t += 0.01;
        }
        ctx.stroke();
    }
    ctx.closePath();
}

// Кривая Безье

function bezier_fill(x1, y1, x2, y2, x3, y3, color) {
  ctx.strokeStyle = "red";
  ctx.beginPath();
  for (var t = 0; t <= 1; t += 0.05)
    ctx.lineTo(
      (1 - t) * (1 - t) * x1 + 2 * t * (1 - t) * x2 + t * t * x3,
      (1 - t) * (1 - t) * y1 + 2 * t * (1 - t) * y2 + t * t * y3
    );
  ctx.stroke();
             ctx.fillStyle = color;
  ctx.fill();
}

      
function bezier(x1, y1, x2, y2, x3, y3) {
  ctx.beginPath();
  for (var t = 0; t <= 1; t += 0.05)
    ctx.lineTo(
      (1 - t) * (1 - t) * x1 + 2 * t * (1 - t) * x2 + t * t * x3,
      (1 - t) * (1 - t) * y1 + 2 * t * (1 - t) * y2 + t * t * y3
    );
  ctx.stroke();
}

      
      
        // Рисование фигур с использованием параметрических уравнений
        function draw() {
            // Рисование координатной сетки
            drawGrid();

            // Установка толщины линии и цвета
            ctx.lineWidth = 6;
            ctx.strokeStyle = 'red';

            // Рисование фигур с использованием параметрических уравнений
            drawCircle(canvas.width / 2.5, canvas.height / 2, 250);
          
            ctx.lineWidth = 3;
            drawSpiral(canvas.width / 2.5, canvas.height / 2, 80 * Math.PI);
            
            let  head = [
          {x: 500, y: 400},
          {x: 500, y: 300},
          {x: 550, y: 300}, 
          {x: 550, y: 400}, 
          {x: 600, y: 450}, 
          {x: 700, y: 300},
          {x: 720, y: 300},
          {x: 680, y: 450},
          {x: 720, y: 650},
          {x: 720, y: 650},
          {x: 32, y: 650},
          {x: 32, y: 650},
          {x: 300, y: 630},
          {x: 607, y: 224},
              {x: 350, y: 300},
        ];
        
              
          
          ctx.lineWidth = 8;
          bezier(520,305,500,180,550,200);
          bezier(700,305,700,180,720,200);
          
          
            bezier(510, 170, 560, 100, 600, 180);
            bezier(660, 170, 700, 100, 730, 180);
          ctx.fillStyle = 'green';
          drawCircle_fill(540, 200, 30);
          drawCircle_fill(700, 200, 30);
          bezier_fill(570, 120, 600, 60, 680, 120, 'red');

          ctx.moveTo(550, 120);
          ctx.lineTo(700, 117);
          ctx.stroke();
          
           ctx.fillStyle = 'red';
          ctx.moveTo(50, 650);
          ctx.lineTo(690, 650);
          ctx.lineTo(710, 645);
          ctx.lineTo(716, 640);
          ctx.lineTo(692, 500);
          ctx.lineTo(695, 400);
          ctx.lineTo(715, 305);
          ctx.lineTo(700, 310);
          ctx.lineTo(607, 420);
          ctx.lineTo(595, 423);
          ctx.lineTo(580, 424);
          ctx.lineTo(563, 400);
          ctx.lineTo(552, 340);
          ctx.lineTo(543, 309);
          ctx.lineTo(515, 310);
          ctx.lineTo(470, 400);
          ctx.lineTo(329, 553);
          ctx.lineTo(205, 626);
          ctx.lineTo(50, 650);
          ctx.fill();
          
          
          ctx.strokeStyle='red';
          betaSpline(head);

          
        
          
          
        }

        // Вызов функции рисования
        draw();
              
            
!
999px

Console