canvas

Skewing images individually using canvas

一个人想着一个人 提交于 2020-01-04 17:54:32
问题 I'm using an HTML5 canvas to create a series of trees and their corresponding shadows. I want each shadow to be based on the position of a light source. I can draw each tree and it's shadow as well as skew all the shadows at once, but trying to skew each shadow individually eludes me. Here's my code: var ctx = cvs[0].getContext('2d'); ctx.save(); //skew the canvas ctx.transform(1,0,0.3,-1,0,0); ctx.drawImage(tree1,74,-117,20,40); ctx.drawImage(tree1,126,-125,20,40); var imgd = ctx

How to draw the line in canvas

非 Y 不嫁゛ 提交于 2020-01-04 17:43:19
问题 I want to draw some lines inside a circle on a canvas, in the following manner. I have no idea how to draw the lines as showed below. But I have the basic knowledge to draw line and arcs on a canvas. How to proceed? 回答1: You can use a bezier curve as suggested in comments with control points, however, these can turn out to be hard to control (no pun) as they do not pass through the points you have defined and you always need to define two control points. In order to achieve a line through

构建Canvas矢量图形渲染器(三)—— 鼠标拖动平移、滚轮缩放

核能气质少年 提交于 2020-01-04 16:24:01
上次随笔实现了用button点击进行缩放,平移;用户操作感很差。本次随笔接着上次的内容进行鼠标拖拽、缩放。 先上demo,鼠标滚轮缩放、拖拽平移。 添加点 添加圆 放大 缩小 1.何为控制类?control 控制类是添加在图层类上用于控制图层的各种操作的类型,比如我们今天所讲了的鼠标滚轮缩放、鼠标拖拽就属于两个控制类。 1.首先看滚轮缩放 //CLASS: 缩放控制类 function Scale(layer) { this.layer = layer; this.div = layer.div; this.active(); } Scale.prototype.wheelChange = function(e) { var layer = this.layer; var delta = (e.wheelDelta / 120) * 30; var deltalX = layer.size.w/2 - (e.offsetX || e.layerX); var deltalY = (e.offsetY || e.layerY) - layer.size.h/2; var px = {x: (e.offsetX || e.layerX), y:(e.offsetY || e.layerY)}; var zoomPoint = this.layer.getPositionFromPx

Canvas drawImage is inexplicably offset by 1 Pixel

自古美人都是妖i 提交于 2020-01-04 13:45:30
问题 I'm working on a canvas game that's using a sprite sheet for the character. The dimensions of character is 64px wide and 128px high with 10 frames per animation. So the total width of a single animation is 640px wide and 128px high. However when I use the following code, The animation is offset by 1px, Sometimes flashing when I hold down a movement key. player.width = 64; player.height = 128; player.x = canvas.width / 2; player.y = canvas.height / 2; ctx.drawImage( LoadedImages.player_sprite,

Is it possible to add tooltips to image's drawn on an HTML5 canvas?

不打扰是莪最后的温柔 提交于 2020-01-04 11:39:31
问题 I would like to draw a line or bar graph using HTML5 canvas. I would like to take in data from an outside source (or hardcode it in for testing purposes) draw the graph Hover over a node/bar and have a tooltip appear displaying the number/relevant data. So my question is, it is possible to apply tooltips to individual images/lines/anything on a canvas? (I know that the canvas itself can have it's own tooltip) One solution that I'm sure would work would be to just make each node a separate

FabricJS: Vertical Align text center

做~自己de王妃 提交于 2020-01-04 09:09:46
问题 I am using fabricjs 1.5 and I am stuck on aligning the text in the middle of the line vertically. I am using this code to set the line height text.setProperty('lineHeight', $scope.lineHeight.current); It changes the line height of text on canvas but text always remains at the top. I want it to be in the vertically middle. Please help. 回答1: You need to use newer versions of fabricjs. 1.5 is too old. For alignment use fabric.Textbox textAlign property. DEMO var canvas = new fabric.Canvas(

Use Canvas to mask background

二次信任 提交于 2020-01-04 07:22:47
问题 i'm trying to blur a background, but I want to use a mask so not all of it is blurred. Is this possible? Basically I have got some code which adds rectangles to a canvas anywhere where there is a certain control, so this canvas would be the mask. This is the C# List<Rectangle> MaskBlocks = new List<Rectangle>(); foreach (StackPanel gr in FindVisualChildren<StackPanel>(Container)) if (gr.Tag != null && gr.Tag.ToString() == "Blur") { System.Windows.Point tmp = gr.TransformToAncestor(this)

Cavnas - Overlapping Radial Gradient Clears

送分小仙女□ 提交于 2020-01-04 06:52:08
问题 This is a follow up from Canvas - Clear Circular Gradient. Following Hardmath's advice, I was able to clear a radial gradient area in my canvas. However, a new problem has arisen: I can't clear multiple radial gradients next to each other; they end up covering up the previous one. The area what was cleared with the previous one gets covered up the with gradient fade of the current one. See the Fiddle below for an example. Fiddle http://jsfiddle.net/Dragonseer/gXTnM/ Code for(var i = 0; i <

HTML5 Canvas - Add image on mouse click, at mouse coordinates

て烟熏妆下的殇ゞ 提交于 2020-01-04 06:51:44
问题 Alright guys, I have been trying to get this for hours now, I cannot find anything. Can someone type up a quick script, or point me in the direction of a tutorial for this.. I want to have an image (imgObj) come up on the canvas when the user clicks on the canvas. I want the image to come up at the coordinates that the mouse is at when the user clicks. Any ideas? Thanks a lot! 回答1: You could start here: http://www.html5canvastutorials.com/ This is a tutorial on the HTML5 Canvas. KineticJS is

HTML5 CANVAS: How to save and reopen image from server

血红的双手。 提交于 2020-01-04 06:04:46
问题 I draw something with html5-canvas. then i want to save it, and when the page is loaded again, I want to load the image I saved back to the canvas. I succeed with saving the data into a file in the server, but for some reason it's a strange file that can't open by ant software, and ofcourse not by my canvas. I save it as png base64, but i tried other things that didn't work. javascript code: function save(){ //saves the canvas into a string as a base64 png image. jsvalue is sent to the server