[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>
</head>
<body>
<canvas id="canvas" width="600" height="600"></canvas>
<script src="app.js"></script>
</body>
</html>
/**
 * Created by Answer1215 on 3/19/2015.
 */
window.onload = function() {

    //var canvas = $("#canvas")[0];
    //var canvas = document.getElmenetByTagName("canvas")[0];
    var canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");
        canvas.width = 400;
        canvas.height = 700;

    //context.fillRect(10, 10, 100, 200);
/**/
   context.beginPath();
    context.moveTo(100,100); //without draw any line;
    context.lineTo(300, 100);
    context.lineTo(300, 200);
    context.lineTo(100, 200);
    context.lineTo(100, 100);

    context.closePath();
    context.stroke();

    //context.fill();  //fill() will also close the path for you
                    //so if you use fill(), you don‘t need closePath(); but in case you forgot
                    //to close the path later, just remember to close it every times.
/**/

/**/
    context.rect(100,100,100,300);            //make a rect and stroke it
    context.stroke();

    context.fillRect(100,100,100,300);        //fill rect
    context.strokeRect(100,100,100,300);      //draw rect
    context.clearRect(100,100,100,300);       //clean the canvas*/
};
时间: 2024-10-10 20:51:32

[Javascript] Drawing Paths - Lines and Rectangles的相关文章

[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

[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

【转】Multithreaded Python Tutorial with the “Threadworms” Demo

The code for this tutorial can be downloaded here: threadworms.py or from GitHub. This code works with Python 3 or Python 2, and you need Pygame installed as well in order to run it. Click the animated gif to view a larger version. This is a tutorial

Drawing Shapes Using B&#233;zier Paths

Drawing Shapes Using Bézier Paths In iOS 3.2 and later, you can use the UIBezierPath class to create vector-based paths. The UIBezierPath class is an Objective-C wrapper for the path-related features in the Core Graphics framework. You can use this c

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

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

应用于横线的抗锯齿算法

摘自:http://sourceforge.net/p/vector-agg/mailman/vector-agg-general/?viewmonth=200308 First of all, let me thank you for the suggestions perfectly explained. The other thing is that the "rectangle" optimization doesn't make much sense in compariso