canvas

How to style canvas elements with CSS

大城市里の小女人 提交于 2020-06-07 04:20:51
问题 I have a lot of figures and elements drawn in the a HTML canvas. All of them have different colors, strokes, etc. I really don't like that all these values are wandering in my JS code as some styles are in the CSS and some are in the code. Does somebody know a good way to define the styles in CSS and read the styles when actually rendering the objects? Here is some example of what I need to do: context.beginPath(); context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false); context

Difference between ImageBitmap and ImageData

半腔热情 提交于 2020-05-31 08:07:34
问题 What is the difference between ImageBitmap and ImageData in JavaScript? when do you want the one or the other? 回答1: An ImageBitmap holds a reference to bitmap data, which can be passed to and stored directly in the GPU. An ImageData holds a reference to a canvas pixel ArrayBuffer, which itself represents raw pixel values as an Array of un-premultiplied RGBA color channel values, which is only used by the CPU. The former can be painted directly by the GPU, with no other operations required.

Tkinter: What is faster: Deleting and drawing a new one or Itemconfig?

痞子三分冷 提交于 2020-05-28 05:05:50
问题 On a Tkinter Canvas, what is faster on updating a piece of text, canvas.itemconfig(text, text='new text') or deleting the text and writing new text to the screen. Deleting the text and adding new text: text = canvas.create_text(200, 200, text='old text') canvas.delete(text) text = canvas.create_text(200, 200, text='old text') Using itemconfig text = canvas.create_text(200, 200, text='old text') canvas.itemconfig(text, text='new text') 回答1: Faster for one item is irrelevant. The canvas has

Tkinter: What is faster: Deleting and drawing a new one or Itemconfig?

不问归期 提交于 2020-05-28 05:03:19
问题 On a Tkinter Canvas, what is faster on updating a piece of text, canvas.itemconfig(text, text='new text') or deleting the text and writing new text to the screen. Deleting the text and adding new text: text = canvas.create_text(200, 200, text='old text') canvas.delete(text) text = canvas.create_text(200, 200, text='old text') Using itemconfig text = canvas.create_text(200, 200, text='old text') canvas.itemconfig(text, text='new text') 回答1: Faster for one item is irrelevant. The canvas has

Webworker OffscreenCanvas draw regular image

只谈情不闲聊 提交于 2020-05-28 04:52:56
问题 Webworkers can fetch regular images through XMLHttpRequest , right? How can the workers then draw these images to OffscreenCanvas? Probably want to use XMLHttp.responseType = 'blob' ? Another way would be to set the src of an image element and then transfer the element to worker, but my workers always reject such images. Thanks 回答1: The ImageBitmap API is here for this purpose (among others). Note: this demo will currently run only on Chrome... const offcanvas = canvas

Using text to mask a video

左心房为你撑大大i 提交于 2020-05-26 08:15:12
问题 Is it possible to use HTML/CSS text to mask a video? I've found and set up ways that sort of work, but none allow for a transparent background behind the text. For example, this pen requires you to have some sort of fill, where it isn't really masking the actual video, but creating the illusion. https://codepen.io/dudleystorey/pen/QvvEYQ If you change body { background: white; margin: 2rem; } To body { background: black; margin: 2rem; } You'll see that it's just a white fill with a mask on

Rendering MathJax output on <canvas>

冷暖自知 提交于 2020-05-26 04:24:47
问题 I have searched this topic, but not able to find a direct answer, and I am also not good in javascript. So I hope someone can show me how to do this. I simply like to display math inside canvas2D. I use context.fillText to pass string to canvas2d, but that string is clearly not being processed by Mathjax since it is not on the page itself. Here is a MWE. What do I need to modify this to make math show up on the canvas? <!DOCTYPE html> <html> <head> <script type="text/x-mathjax-config">

Rendering MathJax output on <canvas>

﹥>﹥吖頭↗ 提交于 2020-05-26 04:24:22
问题 I have searched this topic, but not able to find a direct answer, and I am also not good in javascript. So I hope someone can show me how to do this. I simply like to display math inside canvas2D. I use context.fillText to pass string to canvas2d, but that string is clearly not being processed by Mathjax since it is not on the page itself. Here is a MWE. What do I need to modify this to make math show up on the canvas? <!DOCTYPE html> <html> <head> <script type="text/x-mathjax-config">

canvas context property to PREVENT hardware accelerated rendering?

痴心易碎 提交于 2020-05-24 05:42:23
问题 Is there a setting for the canvas context that will prevent its renderer from using hardware acceleration? I want to render without it, but don't want to ask the user to disable it from their chrome browser since that is counter-intuitive and doesn't provide a seamless workflow experience. 回答1: Short Answer: No, but it is at least being considered by those developing Chromium. MDN: CanvasContext2D In the page you'll find an internal method called demote . Long Answer: There's nothing

canvas context property to PREVENT hardware accelerated rendering?

喜你入骨 提交于 2020-05-24 05:42:14
问题 Is there a setting for the canvas context that will prevent its renderer from using hardware acceleration? I want to render without it, but don't want to ask the user to disable it from their chrome browser since that is counter-intuitive and doesn't provide a seamless workflow experience. 回答1: Short Answer: No, but it is at least being considered by those developing Chromium. MDN: CanvasContext2D In the page you'll find an internal method called demote . Long Answer: There's nothing