canvas

Checking for multiple images loaded

妖精的绣舞 提交于 2020-01-13 08:18:30
问题 I'm using the canvas feature of html5. I've got some images to draw on the canvas and I need to check that they have all loaded before I can use them. I have declared them inside an array, I need a way of checking if they have all loaded at the same time but I am not sure how to do this. Here is my code: var color = new Array(); color[0] = new Image(); color[0].src = "green.png"; color[1] = new Image(); color[1].src = "blue.png"; Currently to check if the images have loaded, I would have to

Checking for multiple images loaded

本秂侑毒 提交于 2020-01-13 08:18:12
问题 I'm using the canvas feature of html5. I've got some images to draw on the canvas and I need to check that they have all loaded before I can use them. I have declared them inside an array, I need a way of checking if they have all loaded at the same time but I am not sure how to do this. Here is my code: var color = new Array(); color[0] = new Image(); color[0].src = "green.png"; color[1] = new Image(); color[1].src = "blue.png"; Currently to check if the images have loaded, I would have to

Make “ball” follow mouse on canvas

时光总嘲笑我的痴心妄想 提交于 2020-01-13 05:39:51
问题 I'm trying to make a ball follow the mouse around inside a canvas area. But the ball only get the first position when mouse enter the canvas area (so on the edges). What is wrong since the ball doesn't follow mouse when moving around inside canvas? window.onload = startup; var ballX = 400; var ballY = 400; var mouseX = 0; var mouseY = 0; function startup() { document.getElementById("drawingArea").onmouseover = mouseMove; setInterval("moveBall()",100); } function mouseMove(evt) { mouseX = evt

How to create jigsaw puzzle from an image using javascript

三世轮回 提交于 2020-01-13 05:33:08
问题 I googled it but didn't find a good answer. Specifically, I want to learn: to slice an image into curved pieces to create individual objects from those pieces (i assume that i need this to reassemble) thanks. 回答1: There are several pieces to this puzzle. :) The first piece is SVG and its Canvas. That's what you'll need to draw, because otherwise you can't make a curved piece out of a picture. Only rectangles are possible with standard HTML/CSS. The second piece is an algorithm for generating

Draw line from html element id to another html element with jquery and canvas

与世无争的帅哥 提交于 2020-01-13 04:42:05
问题 Is it possible to draw a line with html and jquery just by refering to the element id? I have an important word in a text and want to draw a line between this word and an image that describes it. I have seen that that it is possible to draw between elements with canvas but they have style position set to absolute. Since my element is a word in a text I can't set it to absolute. Example <p>This is my text with this very <span id="important_word">important</span> word</p> ... <img src=

巧用canvas实现画板功能,使用画笔在图片上涂画,橡皮擦可擦除涂画,并保存

家住魔仙堡 提交于 2020-01-13 03:26:05
canvas 是HTML5的元素,使用JavaScript 在网页上绘制图像。 canvas 拥有多种绘制路径、矩形、圆形、字符以及添加图像的方法。 而如果想实现画笔在画板涂画画笔在图片上涂画,橡皮擦可擦除涂画,就需要两个canvas画布配合。 原理就是两个一样大小的canvas画布重叠放置,并且都绘制这个图画,这样只在上面的canvas涂画、擦除,擦除时把下层canvas内容替换上层的canvas内容,达到模仿橡皮擦效果。 下面就是具体实现代码: 1、先准备画布和工具: <canvas id="canvas1" width="600" height="500"></canvas> <canvas id="canvas2" width="600" height="500"></canvas> <div class="tooltip-pen"> <b> <i class="ico ico-pen" title="铅笔" onclick="changeTools('pen');"></i> <i class="ico ico-eraser" title="橡皮檫" onclick="changeTools('eraser');"></i> <i class="ico ico-save" title="保存" onclick="downloadImg();"></i> </b> <

【canvas】实现多种形状的烟花

匆匆过客 提交于 2020-01-12 17:30:31
canvas做烟花效果,已经烂大街了。可搬别人的代码,不如自己动手更有意思。 虽然自己做的效果并不是很出众,但完成这一特效整个过程,也算是一种收获。 在做烟花特效之前,我还做了 【canvas】网易云音乐鲸云特效『水晶音波』的简单实现 【canvas】网易云音乐鲸云动效『孤独星球』的简单实现 相比之下,烟花特效要复杂一点。 爆炸 刚开始,从简单的来,先做爆炸的单个碎片。 同样,在这过程中,我会先把重复用到的常量定义好,减少重复计算。 const PI2 = Math . PI * 2 ; const PI7_8 = Math . PI * 7 / 8 ; const PI15_32 = Math . PI * 15 / 32 ; const PI_16 = Math . PI / 16 ; 先定义“碎片” 为了构造一个碎片。需要知道 参数 含义 size 碎片的大小 lightness 碎片的亮度 color 碎片的颜色 angle 碎片移动的方向(角度) speed 碎片移动的速度 shape 碎片所 "遵循" 的形状,用于修正碎片的速度 frame 帧数 帧数,没错。你没有看错,这里我用了帧数,目的是为了告诉一个碎片最多只能渲染多少次(帧)。可以理解为碎片 Shard 的生存周期。 同时,烟花爆炸的位置,烟花一爆炸,碎片 Shard 开始执行 render() 函数绘制

Canvas lineTo() drawing y coordinate in wrong place

时间秒杀一切 提交于 2020-01-12 17:23:49
问题 I'm trying to draw some rectangles on a canvas using ctx.lineTo(). They get drawn but the y coordinate is never right. The rectangles become too tall and on the wrong place on the y axis. When I step through with the debugger it shows the y coordinates within the lineTo() methods as being correct, but I made a canvas.click event to alert the coordinates (which are correct as I click in the top left and it alerts (0,0)). The click event shows that the y coordinate is not actually where it

Canvas lineTo() drawing y coordinate in wrong place

耗尽温柔 提交于 2020-01-12 17:23:05
问题 I'm trying to draw some rectangles on a canvas using ctx.lineTo(). They get drawn but the y coordinate is never right. The rectangles become too tall and on the wrong place on the y axis. When I step through with the debugger it shows the y coordinates within the lineTo() methods as being correct, but I made a canvas.click event to alert the coordinates (which are correct as I click in the top left and it alerts (0,0)). The click event shows that the y coordinate is not actually where it

Drawing an svg containing html in a canvas with safari

社会主义新天地 提交于 2020-01-12 14:16:24
问题 I'm trying to create some thumbnails of dynamically created pages for a website, i have found a solution by adding the html in a svg which I then draw on an image inside a canvas that I resize after the image has been drawn. This solution works in firefox and chrome but not in safari, the svg doesn't seem to be drawn I just get a blank page. I don't get any error even if i put some try catch and I couldn't find a solution on the web. My html is just a basic test page with a canvas, I tried to