canvas

Drawing to canvas using JSON file

谁说胖子不能爱 提交于 2020-01-17 12:14:54
问题 I am trying to call line info from a json object into a canvas using ajax. I'm new to json, so I'm not entirely sure how to go about doing this. Here's what I have so far. JSON { "line": { "width": 3, "stroke": "#FFFFFF", "x1": "640.386", "y1": "258.163", "x2": "816.364", "y2": "258.163" } } JS $(document).ready(function(){ var canvas = document.getElementById("schematic_holder"); var ctx = canvas.getContext("2d"); $.ajax({ type: "GET", dataType: "json", url: "js/app/json/nst.json", success:

实现一个可定制化的TabFlowLayout(四) -- 与ViewPager 结合,实现炫酷效果

倾然丶 夕夏残阳落幕 提交于 2020-01-17 09:07:20
效果图 FlowHelper工程源码 最后就来实现 跟着 viewpager 的效果,如下: 可以看到 ,上面实现了几个效果: 1、子控件的背景跟着自身大小自动变化 2、背景跟着viewpager的滚动自动滑动 3、当移动到中间,如果后面有多余的数据,则让背景保持在中间,内容移动 一、自定义背景 首先,实现一个红色背景框框;首先,思考一下,在 viewgroup 实现 canvas , 是在 onDraw(Canvas canvas) 绘制,还是在 dispatchDraw(Canvas canvas) 呢? 答案肯定是 dispatchDraw 绘制了,为什么呢?这里解释几个概念: onDraw 绘制内容 onDraw 为实际要关心的东西,即所有绘制都在这里。 dispatchDraw 只对ViewGroup有意义 dispatchDraw 通常来讲,可以解释成绘制 子 View View 继承drawable,view 组件的绘制会先调用 draw(Canvas canvas) 方法,然后先绘制 Drawable背景,接着才是调用 onDraw ,然后调用 dispatchDraw方法。dispatchDraw 会分发给组件去绘制。 不过 View 是没有子 view 的,所以dispatchDraw对它来说没意义。 所以,当自定义 ViewGroup 时,加入

Canvas change lineWidth on drawing after it has been drawn

微笑、不失礼 提交于 2020-01-17 06:03:56
问题 In canvas, is it possible to change the lineWidth of a drawing? Example: var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.moveTo(0,0); ctx.lineWidth = 15; ctx.lineTo(100, 100); ctx.stroke(); <canvas id="canvas"></canvas> It has already been drawn, but I want to change the lineWidth after it is drawn. 回答1: If you're asking about redrawing the line with a new line width, that's quite possible. You can use requestAnimationFrame . Here's a

Canvas change lineWidth on drawing after it has been drawn

孤街醉人 提交于 2020-01-17 06:03:21
问题 In canvas, is it possible to change the lineWidth of a drawing? Example: var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.moveTo(0,0); ctx.lineWidth = 15; ctx.lineTo(100, 100); ctx.stroke(); <canvas id="canvas"></canvas> It has already been drawn, but I want to change the lineWidth after it is drawn. 回答1: If you're asking about redrawing the line with a new line width, that's quite possible. You can use requestAnimationFrame . Here's a

Issue creating clickable area in canvas html5

江枫思渺然 提交于 2020-01-17 05:46:48
问题 I am trying to learn to use canvas so I choose to do an exercise. Basically, all I have is a canvas that generate an image, then it puts other two images on it and generate a polygon around them, those polygon are suppoused to be clickable to create the illusion that you are clicking on the objects (if I delete the borders). Ahh, and you can zoom and move the image with the mouse. You can see the test here. Yesterday I asked for help to make those areas clickeable and looks like the solution

HTML5 Canvas: Applying a gradient to shadow

↘锁芯ラ 提交于 2020-01-17 04:49:09
问题 I was surprised to find out that apparently the canvas API does not allow you to apply gradients to shadows like this: var grad = ctx.createLinearGradient(fromX, fromY, toX, toY); grad.addColorStop(0, "red"); grad.addColorStop(1, "blue"); ctx.strokeStyle = grad; ctx.lineWidth = 3; ctx.shadowBlur = 10; ctx.shadowColor = grad; // doesn't seem to work ctx.beginPath(); ctx.moveTo(fromX, fromY); ctx.lineTo(toX, toY); ctx.closePath(); ctx.stroke(); // linear gradient from start to end of line var

KineticJs group.setSize(300,300) not working

丶灬走出姿态 提交于 2020-01-17 03:41:09
问题 I am trying to change size of kinetic group. but it gives JavaScript error message. in kinetic js document its written than setSize works with group nodes 回答1: I think the documents are a bit outdated in that respect. Groups do not have a drawFunc so they do not have a width or height. If they ever do get width and height, it will be possible to create clipped groups, which will be nice. However, as they are now, groups are simply used to define a relative x and y starting coordinate for

KineticJs group.setSize(300,300) not working

五迷三道 提交于 2020-01-17 03:41:05
问题 I am trying to change size of kinetic group. but it gives JavaScript error message. in kinetic js document its written than setSize works with group nodes 回答1: I think the documents are a bit outdated in that respect. Groups do not have a drawFunc so they do not have a width or height. If they ever do get width and height, it will be possible to create clipped groups, which will be nice. However, as they are now, groups are simply used to define a relative x and y starting coordinate for

Dectect click in irregular shapes inside HTML5 canvas

偶尔善良 提交于 2020-01-17 03:38:05
问题 I am new using canvas and I created a simple script to draw irregular polygons in a canvas knowing the coord. Now I need to detect if an user clicks on one of those shapes and wich one (each object has an ID). You can see my script working here. var canvas = document.getElementById('canvas'); var ctx = canvas.getContext("2d"); var objetos = []; // First Shape objetos.push( { id:'First', coordinates: { p1: { x: 30, y: 10 }, p2: { x: 50, y: 50 }, p3: { x: 90, y: 90 }, p4: { x: 50, y: 90 }, } })

How to change color of circle temporarily in HTML5 Canvas

人走茶凉 提交于 2020-01-17 03:23:26
问题 I am trying to build simon game using html5 canvas and pure javascript. I have managed to get the simon game UI using html5 canvas. My next step is to make the four components light up randomly. I am not sure if this is even possible with html5 canvas or probably my approach is wrong. Any hints in the right direction will be of great help. My code is as follows codepen link: http://codepen.io/anon/pen/QEdPRN?editors=1010 var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"