html5-canvas

WebGl Fragment Shader pass array

半腔热情 提交于 2020-04-30 04:48:17
问题 I know very little about OpenGL or WebGL. I was wondering if it is possible to pass a fragment shader an argument. Specifically, I'd like to pass it a multidimensional array with the colors to set for each pixel, for example: [0][0][0] = 1 would be the red component of the pixel at (0, 0). 回答1: The standard way of doing this is by using a texture rather than passing an array. 回答2: Simon's answer is right on . But took me about 6 hours to actually get it working.Here is my full working code as

HTML canvas returns “off-by-some” bytes from getImageData

生来就可爱ヽ(ⅴ<●) 提交于 2020-03-21 20:13:31
问题 I found that getImageData of an HTML canvas seems to return incorrect byte values. I generated a 1x1 px image with the following Python code: from PIL import Image import numpy as np a = np.array([[[12, 187, 146, 62]]], dtype=np.uint8) Image.fromarray(a).save('image.png') I converted the image to base64 to include it in this code snippet: let image = document.createElement('img'); image.addEventListener('load', () => { let canvas = document.createElement('canvas'); let ctx = canvas.getContext

Bouncing ball code causes jitter in HTML5 canvas

…衆ロ難τιáo~ 提交于 2020-03-05 04:39:33
问题 I have a HTML Canvas on my website that I use to contain balls that drop into the canvas, they bounce around and have a real good time settling down at the bottom in a range of ways. I was under the impression this was working perfectly. However, it has now been brought to my attention these balls jitter and freak out on other people's computers. I checked the browser they are using and it is the same as mine (Chrome V79). So just to clarify - I have never had it bug on my computer but it

Bouncing ball code causes jitter in HTML5 canvas

本小妞迷上赌 提交于 2020-03-05 04:37:28
问题 I have a HTML Canvas on my website that I use to contain balls that drop into the canvas, they bounce around and have a real good time settling down at the bottom in a range of ways. I was under the impression this was working perfectly. However, it has now been brought to my attention these balls jitter and freak out on other people's computers. I checked the browser they are using and it is the same as mine (Chrome V79). So just to clarify - I have never had it bug on my computer but it

HTML5 Limit Moving Image Into Canvas

别说谁变了你拦得住时间么 提交于 2020-02-25 08:43:11
问题 canvas.onmousemove = function (e) { if (isDown === true) { var pos = getMousePos(canvas, e); var x = pos.x; var y = pos.y; //translate difference from now and start element.translate(x - startX, y - startY); drawImage(); //update start positions for next loop startX = x; startY = y; }} http://jsfiddle.net/braziel/nWyDE/ Friends, I need help to limit the movement of an image within the canvas when zoomed. I put the link, you can see the image when zoomed and dragged it exceeded the limit of

HTML5 Limit Moving Image Into Canvas

我是研究僧i 提交于 2020-02-25 08:43:11
问题 canvas.onmousemove = function (e) { if (isDown === true) { var pos = getMousePos(canvas, e); var x = pos.x; var y = pos.y; //translate difference from now and start element.translate(x - startX, y - startY); drawImage(); //update start positions for next loop startX = x; startY = y; }} http://jsfiddle.net/braziel/nWyDE/ Friends, I need help to limit the movement of an image within the canvas when zoomed. I put the link, you can see the image when zoomed and dragged it exceeded the limit of

Save hidden DIV as canvas image

感情迁移 提交于 2020-02-25 06:53:46
问题 I used the following code to save the visible as image. html2canvas(document.querySelector('.specific'), { onrendered: function(canvas) { theCanvas = canvas; Canvas2Image.saveAsPNG(canvas); } }); Is there any way that I can able to save the hidden 回答1: There are some solutions out there, like for example display property toggle, or render inside hidden element. Solution 1 Quickly toggle visibility property const el = document.querySelector('.specific'); el.style.display = "block"; // or any

Emulate free drawing with fabricjs

旧街凉风 提交于 2020-02-25 04:20:29
问题 I am developing application which has whiteboard. Whiteboard should work like idroo.com. One user is drawing something another user should be able to see it on his browser in real time. I use fabricjs as canvas wrapper and it has everithing I need. But I can't emulate free drawing on canvas. I send mouse position and brush options to remote client and try to render them by firing mouse move events. But it don't work. If some body has simialiar problem can you please help? canvasContainer.on(

Save canvas/image after css applied

空扰寡人 提交于 2020-02-24 03:42:34
问题 I have a simple canvas with an image on it (image 500x333): <canvas id="capEdit" width="500" height="333"></canvas> I then apply a simply horizontal flip on the canvas/image using CSS, works perfectly .flipH { -moz-transform: scale(-1, 1); -webkit-transform: scale(-1, 1); -o-transform: scale(-1, 1); transform: scale(-1, 1); filter: FlipH; } I'm now trying to save the image on the canvas WITH its flipped state, but it only saves the original image, here's what I'm trying: $(document).on("click

Save canvas/image after css applied

早过忘川 提交于 2020-02-24 03:40:26
问题 I have a simple canvas with an image on it (image 500x333): <canvas id="capEdit" width="500" height="333"></canvas> I then apply a simply horizontal flip on the canvas/image using CSS, works perfectly .flipH { -moz-transform: scale(-1, 1); -webkit-transform: scale(-1, 1); -o-transform: scale(-1, 1); transform: scale(-1, 1); filter: FlipH; } I'm now trying to save the image on the canvas WITH its flipped state, but it only saves the original image, here's what I'm trying: $(document).on("click