[Javascript] Drawing Paths - Curves and Arcs

window.onload = function() {

    var canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");

    context.beginPath();
    context.moveTo(0,300);

    for(var x = 1; x < 300; x++){
        var y = 300 + Math.sin(x * 0.02) *100;
        context.lineTo(x,y);
    }

    context.stroke();
};

quadraticCurveTo() & bezierCurveTo():

 

window.onload = function() {

    var canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");

    var p0 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    var p1 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    var p2 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    context.beginPath();
    context.moveTo(p0.x, p0.y);
    context.quadraticCurveTo(p1.x, p1.y, p2.x, p2.y);
    context.stroke();
    context.closePath();

    drawPoint(p0);
    drawPoint(p1);
    drawPoint(p2);

    function drawPoint(p) {
        context.fillRect(p.x - 4, p.y - 4, 8, 8);
    }

};

window.onload = function() {

    var canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");

    var p0 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    var p1 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    var p2 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    var p3 = {
        x: Math.random() * 600,
        y: Math.random() * 600
    };

    context.beginPath();
    context.moveTo(p0.x, p0.y);
    context.bezierCurveTo( p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
    context.stroke();
    context.closePath();

    drawPoint(p0);
    drawPoint(p1);
    drawPoint(p2);
    drawPoint(p3);

    function drawPoint(p) {
        context.fillRect(p.x - 4, p.y - 4, 8, 8);
    }

};

window.onload = function() {

    var canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");

    context.beginPath();
    context.arc(200,200,100,0,2);
    context.stroke();
    context.closePath();

    context.beginPath();
    context.arc(400,400,100,0,2, true);
    context.stroke();
    context.closePath();

};

window.onload = function() {

    var canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");

    context.beginPath();
    context.arc(300,300,100,0, Math.PI * 2);
    context.stroke();
    context.closePath();

};

时间: 2024-08-11 09:43:37

[Javascript] Drawing Paths - Curves and Arcs的相关文章

[Javascript] Drawing Paths - Lines and Rectangles

<!DOCTYPE html> <html> <head> <meta name="description" content="HTML5 Canvas Graphics and Animation Video 1" /> <meta charset="utf-8"> <title>HTML5 Canvas Graphics and Animation</title&g

[LeetCode][JavaScript]Unique Paths

Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked

[LeetCode][JavaScript]Unique Paths II

Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obsta

[Javascript] Drawing Styles on HTML5 Canvas

window.onload = function() { var canvas = document.getElementById("canvas"), context = canvas.getContext("2d"), width = canvas.width = 600, height = canvas.height = 600; context.lineCap = "round"; context.lineJoin = "mit

iOS Drawing Concepts[iOS 绘画概念]

iOS Drawing Concepts https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html High-quality graphics are an important part of your app’s user interface. Providin

Canvas学习

好久不碰前端了,好多都忘了,但是一直很想学canvas. https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes 一:基本代码 html5 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Canvas<

IGeometryCollection Interface

Come from ArcGIS Online IGeometryCollection Interface Provides access to members that can be used for accessing, adding and removing individual geometries of a multi-part geometry (Multipoint, Polyline, Polygon, MultiPatch, and GeometryBag). Product

HTML &lt;canvas&gt; 学习笔记

Professional JavaScript for Web Developers    P552 Basic Usage The <canvas> element requires at least its width and height attributes to be set in order to indicate the size of the drawing to be created. Any content appearing  between the opening an

Problem of ANISOTROPIC mode

>  I am beginner for AGG. I just tried simple drawing of curves, lines, texts,  > image in MM_TEXT mode. > But when i used MM_ANISOTROPIC mode with viewpoet extent as (1,-1), it gave  > wrong result. > Is there any solution for this???  >