[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();
};

[Javascript] Drawing Paths - Curves and Arcs的更多相关文章
- [Javascript] Drawing Paths - Lines and Rectangles
<!DOCTYPE html> <html> <head> <meta name="description" content=" ...
- JavaScript Learning Paths(ES5/ES6/ES-Next)
JavaScript Learning Paths(ES5/ES6/ES-Next) JavaScript Expert refs https://developer.mozilla.org/en-U ...
- [Javascript] Drawing Styles on HTML5 Canvas
window.onload = function() { var canvas = document.getElementById("canvas"), context = can ...
- 【Javascript】js图形编辑器库介绍
10个JavaScript库绘制自己的图表 jopen 2015-04-06 18:18:38 • 发布 摘要:10个JavaScript库绘制自己的图表 JointJS JointJS is a J ...
- HTML5资料
1 Canvas教程 <canvas>是一个新的用于通过脚本(通常是JavaScript)绘图的HTML元素.例如,他可以用于绘图.制作图片的组合或者简单的动画(当然并不那么简单).It ...
- leaflet地图库
an open-source JavaScript libraryfor mobile-friendly interactive maps Overview Tutorials Docs Downlo ...
- GDI+ Tutorial for Beginners
原文 GDI+ Tutorial for Beginners GDI+ is next evolution of GDI. Using GDI objects in earlier versions ...
- IGeometryCollection Interface
Come from ArcGIS Online IGeometryCollection Interface Provides access to members that can be used fo ...
- HTML <canvas> 学习笔记
Professional JavaScript for Web Developers P552 Basic Usage The <canvas> element requires a ...
随机推荐
- codeforces Winner
/* * Winner.cpp * * Created on: 2013-10-13 * Author: wangzhu */ /** * 先找出所有选手的分数和中最大的分数和,之后在所有选手的分数和 ...
- Nuget
Install-Package Microsoft.AspNet.WebApi.Cors
- 11个强大的Visual Studio调试小技巧(转)
简介 调试是软件开发周期中很重要的一部分.它具有挑战性,同时也很让人疑惑和烦恼.总的来说,对于稍大一点的程序,调试是不可避免的.最近几年,调试工具的发展让很多调试任务变的越来越简单和省时. 这篇文章总 ...
- How to: Define a Windows Communication Foundation Service Contract
This is the first of six tasks required to create a basic Windows Communication Foundation (WCF) app ...
- 【 D3.js 选择集与数据详解 — 3 】 绑定数据的顺序
data() 函数有两个参数,第一个是被绑定数据,第二个参数用于指定绑定的顺序.在数据需要更新的时候常常会用到. 默认的情况下,data()函数是按照索引号依次绑定数组各项的.第0个元素绑定数组的第0 ...
- HTTP请求中的缓存(cache)机制
http://www.chaorenmao.com/blog/?p=79 流程 当资源第一次被访问的时候,HTTP头部如下 (Request-Line) GET /a.html HTTP/1.1Ho ...
- Android 再按一次退出程序
实现代码: private long exitTime = 0; /** * 捕捉返回事件按钮 * * 因为此 Activity 继承 TabActivity 用 onKeyDown 无响应,所以改用 ...
- (转载)php array_merge 和 两数组相加区别
(转载)http://www.cnblogs.com/shistou/archive/2013/03/16/2963586.html PHP中两个数组合并可以使用+或者array_merge,但之间还 ...
- [Stephen]Android的adb无法启动
1.程序中运行收入cmd,打开dos命令窗口,在窗口中依次运行abd kill-server和 adb start-server 尝试重启adb服务 2.如果依然启动失败 dos命令窗口中键入 ...
- bat 批处理 字符串 截取
由于项目中配置项太多,经常有同事在配置xml的时候,讲 配置的路径搞错,先需要搞一个脚本,可以自动将路径截取出来, 晚上收集了点资料,暂时先上几个 bat 后面留着 ,具体实现. @echo off ...