canvas(一) 基本线条绘制

var dom = document.getElementById(‘canvasItem‘),
    ctx = dom.getContext(‘2d‘);

    //坐标位置默认基于 浏览器窗口(0,0),此时居中,基于 当前坐标系
    //x轴 向右,y轴向下
    ctx.beginPath();
    ctx.moveTo(100,350); //只是将坐标移到某点
    ctx.lineTo(500,350); //将两个点之间连接起来
    ctx.lineTo(500,200);
    ctx.lineTo(600,350); //基于状态绘制图像 此时,状态设置

    ctx.moveTo(600,450);
    ctx.lineTo(600,500);
    ctx.lineWidth=10;
    ctx.strokeStyle=‘red‘;

    ctx.stroke();

    /*绘制不同 属性的 线条,使用beginPath 重新开启一条全新的路径*/
    ctx.beginPath();
    //ctx.moveTo(100,520);
    ctx.lineTo(100,520); //使用lineTo 相当于 moveTo,当使用了beginPath
    ctx.lineTo(600,520);
    ctx.lineWidth=3;
    ctx.strokeStyle=‘blue‘;
    ctx.stroke();

    ctx.beginPath();

    ctx.moveTo(100,560);
    ctx.lineTo(600,560);
    ctx.lineWidth=30;
    ctx.strokeStyle=‘yellow‘;

    ctx.stroke(); //绘制
时间: 2024-08-24 01:44:17

canvas(一) 基本线条绘制的相关文章

Canvas:橡皮筋线条绘制

Canvas:橡皮筋线条绘制 效果演示 实现要点 事件监听 [说明]: 在Canvas中检测鼠标事件是非常简单的,可以在canvas中添加一个事件监听器,当事件发生时,浏览器就会调用这个监听器. 我们可以使用绑定事件属性: canvas.onmousedown = function(e) { //..... } 此外,也可以使用更为通用的addEventListener()方法来注册监听器: canvas.addEventListener('mousedown',function(e){ //.

Quartz2D简介及基本线条绘制

* Quartz2D简介 1.什么是Quartz2D? 他是一个二维的绘图引擎,同时支持iOS和Mac系统 2.Quartz2D能完成的工作 画基本线条,绘制文字,图片,截图,自定义UIView. 3.Quartz2D在开发中的价值 当我们的控件样式极其复杂时,可以把控件内部的结构给画出画,就是自定义控件. 5.什么是图形上下文,上下文的类型有哪些? 图形上下文是用来保存用户绘制的内容状态,并决定绘制到哪个地方的. 用户把绘制好的内容先保存到图形上下文, 然后根据选择的图形上下文的不同,绘制的内

canvas的一些简单绘制方法

绘画矩形.矩形框.圆.圆环.圆圈~ <canvas class="myCanvas" width="500" height="500"></canvas><!--定义宽高只能在行内定义,否则画的图会与你想象的不一样哦,不信可以试试--> <script> var c = document.getElementsByClassName('myCanvas')[0];//获取节点 var ctx = c

HTML5 Canvas ( 填充图形的绘制 ) closePath, fillStyle, fill

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>canvas</title> <script type="text/javascript" src="../js/jQuery.js"></script> <style type="text/css">

使用canvas元素-art方法绘制圆弧

最近在学习HTML5,发现canvas真的很棒,canvas元素是一种可供绘图的平面,我们用JavaScript对它进行配置和操作.我这里说一下arc方法绘制圆弧,顺便提一下涉及到的基础知识. 首先看这段代码: var ctx=document.getElementById("canvas").getContext("2d"); /*这是调用HTMLCanvasElement对象的getContex方法,为画布返回绘图上下文,这里是采用2d上下文 ctx.fillS

canvas学习笔记(1)-绘制时钟

html代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8" /> <title>canvas clock</title> <style type="text/css"> div{ text-align: center; margin-top: 150px; } </styl

用canvas实现鼠标拖动绘制矩形框

需要用到jCanvas插件和jQuery. jCanvas下载:https://raw.githubusercontent.com/caleb531/jcanvas/master/jcanvas.min.js 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>鼠标拖动绘制矩形框(canvas)</ti

canvas.drawRoundRect方法,绘制圆角矩形

public void drawRoundRect (RectF rect, float rx, float ry, Paint paint) Draw the specified round-rect using the specified paint. The roundrect will be filled or framed based on the Style in the paint. Parameters rect The rectangular bounds of the rou

JavaScript+canvas 利用贝塞尔曲线绘制曲线

效果图: <body> <canvas id="test" width="800" height="300"></canvas> <script type="text/javascript"> //一个工具函数,用于将角度从角度制转化成弧度制 function rads(x){ return Math.PI*x/180;} var canvas = document.getEle