小编fun*_*ash的帖子

将createPattern()与画布一起使用

我想要一个重复的画布图案.可悲的是,我能找到的所有例子都重复一个图像.所以我试过这个:

function init() {
var canvas = document.getElementById("bg");
var ctx = canvas.getContext("2d");

//creating a new canvas  
var canvas = document.createElement('canvas');
canvas.width = 500;
canvas.height = 400;
var img = canvas.getContext("2d");

draw(img);
var objPattern = ctx.createPattern(img, "repeat");
ctx.fillStyle = objPattern;
ctx.fillRect(0, 0, document.body.clientHeight, document.body.clientWidth);
}

function draw(img) {
  //img.save();
  img.beginPath();
  img.moveTo(0.0, 40.0);
  img.lineTo(26.9, 36.0);
  img.bezierCurveTo(31.7, 36.0, 36.0, 32.1, 36.0, 27.3);
  img.lineTo(40.0, 0.0);
  img.lineTo(11.8, 3.0);
  img.bezierCurveTo(7.0, 3.0, 3.0, 6.9, 3.0, 11.7);
  img.lineTo(0.0, 40.0);
  img.closePath();
  img.fillStyle = "rgb(188, 222, 178)";
  img.fill();
  img.lineWidth = …
Run Code Online (Sandbox Code Playgroud)

javascript html5 design-patterns canvas repeat

3
推荐指数
1
解决办法
5990
查看次数

对由两点组成的线段进行排序

我如何为由起点和终点组成的线段实现运算符<。我想将线段插入地图中,因此顺序不需要是语义的,但它应该适用于所有情况。

c++ graphics operators line

0
推荐指数
1
解决办法
287
查看次数

标签 统计

c++ ×1

canvas ×1

design-patterns ×1

graphics ×1

html5 ×1

javascript ×1

line ×1

operators ×1

repeat ×1