html5-canvas

How to rotate a canvas object following mouse move event with easing?

假如想象 提交于 2020-01-25 20:13:39
问题 I am not sure if I have used the right word here. I guess easing means it does not follow the mouse immediately but with some delay? At the moment the iris is rotating to my mouse direction. What if I want it to have same effect as this?. Is it very hard to do so or just require simple code changes? Is there a standard way/solution for this kind of problem? Here is my current code. It can also be found at Rotating Iris . var canvas = document.getElementById('canvas'); var ctx = canvas

HTML5 video and canvas

好久不见. 提交于 2020-01-25 11:33:20
问题 I have a video and I need to capture 3 images from it, at different time. Time is not random, I have to take images at specified time (13:10:02, 13:10:03, 13:10:04). The images should be displayed on the page when I access the page, not when I click a button or something like that. Until now I tried with an example that I found on the internet, but on this example, the image is displayed after a button was clicked, and I don't know how to give a specified time. <video controls> <source src=

Call JS function from HTML

六月ゝ 毕业季﹏ 提交于 2020-01-25 11:12:09
问题 I am unable to call a function from HTML file. This seems simple and my code matches what I've seen in similar SO answers, but I am missing something still. I know the JS is loading/running because the game in the canvas is working. Edit: Chrome console returns "testFunction is not defined" meaning the JS is NOT loaded. Why? This is a test in the JS file: function testFunction(){ alert("It works!"); } and it's called from the HTML like so: <button type="button" onclick="testFunction()" id=

How does fillStyle work in bs-webapi Canvas2d

偶尔善良 提交于 2020-01-25 09:28:07
问题 I'm wondering how to create a and set a fill style using bs-webapi and Canvas2d interface in ReasonML. I think the definition I might need is this: let fillStyle = (ctx: t) => ctx |> fillStyle |> reifyStyle; But I'm having trouble understanding it. I have previously used this project as a source of examples, but I think the bs-webapi has changed since that project was authored. At least the following line modeled after the example: Canvas2d.fillStyle(ctx, "rgba(0,255,255,255)"); gives me this

Change delay in setTimeout using a button click

泄露秘密 提交于 2020-01-25 04:17:06
问题 I am working on creating a 3D rotating cube in HTML canvas. My code looks something like this function rotateCubeZM() { fr = 5; stoppage = 1; for(let i = 0;i<200;i++,fr+=dacc) { setTimeout(rotateCubeZ,i*fr*stoppage,1); } } Here dacc is a de-acceleration factor which slows down the rotation. I need to create button friction which will further slow down the de-acceleration by factor x. How do I change the de-acceleration factor while setTimeout is still in progress? I tried updating the value

Angular 2 - Provide 3rd-party library with element for rendering

喜欢而已 提交于 2020-01-25 04:13:17
问题 How would I provide a DOM element to a 3rd-party library in Angular 2? For example, if Library is the hypothetical 3rd-party library, and I had to do something like: var fakeId = document.getElementById('fake'); // e.g. canvas or SVG element var sirRender = Library.confiscate(fakeId); sirRender.drawMustache(); // accesses canvas context or manipulates SVG I am using Typescript and ES6 decorator component syntax. I'm imagining I can do something inside ngOnInit like: @Component({ ... }) export

Mouse handles are not in sync with the mouse

风流意气都作罢 提交于 2020-01-25 02:20:23
问题 I am trying to select a selection handle and then move it but the mouse handles are not in sync with the mouse pointer. when you select the rectangle and then try to move the middle selection handle to create a gap in the rectangle the mouse pointer is positioned away from the handle is. Fiddle is : http://jsfiddle.net/3PwWY/ case 8: if(mx > mySel.x + mySel.w/2) mySel.windowWidth = mx - (mySel.x + mySel.w/2); else mySel.windowWidth = (mySel.x + mySel.w/2) - mx; // Enforce limits on mx: //

How to re-render canvasjs chart with animation?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-25 02:17:07
问题 So far I've been successfully updating the data for the my chart following the guide in this link. However, how can do re-render it but with the same animation when it was first rendered? 回答1: It's somehow a hack and I know it shouldn't be this way but the only solution I found was to reinitialize the creation of the chart just to achieve that animation. 来源: https://stackoverflow.com/questions/28147817/how-to-re-render-canvasjs-chart-with-animation

Record at constant fps with CanvasCaptureMediaStream even on slow computers

旧城冷巷雨未停 提交于 2020-01-24 22:08:08
问题 I want to record a video from a HTML <canvas> element at a specific frame rate. I am using CanvasCaptureMediaStream with canvas.captureStream(fps) and also have access to the video track via const track = stream.getVideoTracks()[0] so I create track.requestFrame() to write it to the output video buffer via MediaRecorder . I want to precisely capture one frame at a time and then change the canvas content. Changing the canvas content can take some time (as images need to be loaded etc). So I

Finding size of rotated image to match top-line based on angle

落爺英雄遲暮 提交于 2020-01-24 22:07:09
问题 (illustration for reference: https://i.stack.imgur.com/Wsge0.png) Code example https://jsfiddle.net/waaentz/htrqdwjp/9/ const width = 1000; const height = 100; const canvas = document.createElement("canvas"); const stage = new createjs.Stage(canvas); const img = new Image(); const bitmap = new createjs.Bitmap(img); const baseGrid = new createjs.Shape(); const angle = 45; // Is dynamic const magicScaleFormular = 1.39 // Find scale based on height and angle img.src = getBase64(); img