canvas

Have object detect if completely inside other object JavaScript

断了今生、忘了曾经 提交于 2020-01-05 08:39:22
问题 Hello I'm making a game for my CS class using JavaScript. I know how to ale objects collide with each other in the canvas but I m trying to get an object to detect if it's completely inside another object If (object1.xcoord > object2.xcoord && object1.xcoord + object1.width < object2.xcoord + object2.width && object1.ycoord + object1.height < object2.ycoord +object2.height) { alert("hi") } Note I only need those three sides it doesn't matter to me if object 1 is within top side of object 2

Bezier curves draw stretched ellipses in HTML5 canvas

ぃ、小莉子 提交于 2020-01-05 07:37:22
问题 This method for drawing ellipses appears to be clean and elegant: http://www.williammalone.com/briefs/how-to-draw-ellipse-html5-canvas/ However, in testing it, I found that the resulting ellipses were stretched. Setting width and height equal, I got ellipses that were about 20% taller than wide. Here's the result with width = height = 50 : To make sure that the problem was with the method itself, I tried changing the algorithm so that all the points used for the Bezier curves were rotated 90

Get dimensions of a HTML5 canvas graphic (Arc), when an event occurs

ぐ巨炮叔叔 提交于 2020-01-05 07:18:10
问题 My question is: how should I do the logical and mathematical part, in order to calculate the position of each arc, when an event is emitted: "click", "mouseover", etc. Points to consider: . Line width . They are rounded lines. . Arc length in percentage. . Which element is first, ej: z-index position. My source code Thank you for your time. 回答1: There is a convenient isPointInStroke() method, just for that. To take the z-index into consideration, just check in the reverse order you drew:

HTML5 Save canvas to PNG

心不动则不痛 提交于 2020-01-05 07:12:46
问题 I am following this example to save the canvas to a PNG file. http://greenethumb.com/article/1429/user-friendly-image-saving-from-the-canvas/ My problem: The downloaded file is corrupt and when I open it in notepad, it has this pattern: HTML CODE (Correspoding to the PHP file) ASCII CHARACTERS (which I thought corresponded to the PNG file) <body><html> If I remove #1 and #3 and save the file locally, I get a valid PNG image. I am doing exactly what the example above says, but my results are

how to maintain canvas size when converting python turtle canvas to bitmap

寵の児 提交于 2020-01-05 07:08:10
问题 I want to convert a Python Turtle module (tkinter) canvas into a bitmap. I have followed the suggestion at "How to convert a Python tkinter canvas postscript file to an image file readable by the PIL?" to convert it first to postscript; then I open it as a PIL image, then save that as a bitmap. But the bitmap is a different size from the original canvas. import turtle import io from PIL import Image myttl = turtle.Turtle() wd=500 ht=500 turtle.setup(width=wd, height=ht, startx=0, starty=0)

jquery tipsy tooltip not working with d3.js circles

99封情书 提交于 2020-01-05 05:49:07
问题 Here is my d3.js code var circles = vis.selectAll("circle").data(data) circles .enter() .append("svg:circle") .attr("stroke", "black") .attr("cx", function (d) { return xRange(d.year); }) .attr("cy", function (d) { return yRange(d.count); }) .style("fill", function(d,i){return color(i);}) .append("svg:title") .text(function (d) { return d.corpus; }) In the end i have appended a tooltip to the circles.I tried to attach jquery tipsy tooltip to the circles but did'nt work.Here is how i did it(i

canvas绘制贝塞尔曲线

佐手、 提交于 2020-01-05 05:45:43
1、绘制二次方贝塞尔曲线 quadraticCurveTo(cp1x,cp1y,x,y); 其中参数cp1x和cp1y是控制点的坐标,x和y是终点坐标 数学公式表示如下: 二次方贝兹曲线的路径由给定点 P 0 、 P 1 、 P 2 的函数 B ( t )追踪: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> *{padding: 0;margin:0;} body{background: #1b1b1b;} #div1{margin:50px auto; width:300px; height: 300px;} canvas{background: #fff;} </style> <script type="text/javascript"> window.onload = function(){ var c = document.getElementById('myCanvas'); var content = c.getContext('2d'); //绘制二次方贝塞尔曲线 content.strokeStyle ="#FF5D43"; content.beginPath(); content.moveTo(0,200); content

THREE.js Multiple views to Multiple Canvasses by Object Cloning. Pitfalls?

ぃ、小莉子 提交于 2020-01-05 04:48:09
问题 In object picking from small three.js viewport I was given a way to mouse-pick objects from a small (not fullscreen) canvas. But now I want to display N different views of the same scene and also be able to do object picking. To avoid complexity:- I prefer not to have N viewports on one canvas (as per http://webglsamples.googlecode.com/hg/multiple-views/multiple-views.html) and I prefer not to do canvas copying (as per gman's nice method in Display different scenes sharing resources on

How can I overlay multiple PNGs and have each of them clickable in their visible area?

烈酒焚心 提交于 2020-01-05 04:37:08
问题 I need to set up a clickable image system for dynamically created content. The image consists of a background image, and several grey-scale mask images. Background Image: Masks: , , , , Each area, defined by a mask, should be highlighted on mouse over, clickable on the image, and open a certain link. How do I do this the smartest way? I need this to be responsive, and work with a couple of hundred masks. I haven't tried anything yet, but I've done some research, which have resulted in two

How do i make the jumping smoother in this game. It is Teleporting

你说的曾经没有我的故事 提交于 2020-01-05 04:31:10
问题 After a long time of looking through internet, i finally figured out how to make my character jump. But i am still having problems with jumping. When i would press the jump button, the character / ball would basically teleport to the desired location, then slowly fall down because of the gravity that i have set up. I have no clue what so ever. I am a student and a programming languages learner, so please bear with me. If you guys could make the going up part of the jumping much smoother for