Simple physics-based movement

I found this question very interesting since I had recently done some work on modeling projectile motion with drag. Point 1: You are essentially updating the position and velocity using an explicit/forward Euler iteration where each new value for the states should be a function of the old values. In such a case, you should … Read more

How do i tint an image with HTML5 Canvas?

You have compositing operations, and one of them is destination-atop. If you composite an image onto a solid color with the ‘context.globalCompositeOperation = “destination-atop”‘, it will have the alpha of the foreground image, and the color of the background image. I used this to make a fully tinted copy of an image, and then drew … Read more

How to convert a Numpy 2D array with object dtype to a regular 2D array of floats

Nasty little problem… I have been fooling around with this toy example: >>> arr = np.array([[‘one’, [1, 2, 3]],[‘two’, [4, 5, 6]]], dtype=np.object) >>> arr array([[‘one’, [1, 2, 3]], [‘two’, [4, 5, 6]]], dtype=object) My first guess was: >>> np.array(arr[:, 1]) array([[1, 2, 3], [4, 5, 6]], dtype=object) But that keeps the object dtype, so … Read more

Closest point to a given point

Don’t forget that you don’t need to bother with the square root. If you just want to find the nearest one (and not it’s actual distance) just use dx^2 + dy^2, which will give you the distance squared to the each item, which is just as useful. If you have no data structure wrapping this … Read more

Javascript 2d array indexOf

You cannot use indexOf to do complicated arrays (unless you serialize it making everything each coordinate into strings), you will need to use a for loop (or while) to search for that coordinate in that array assuming you know the format of the array (in this case it is 2d). var arr = [[2,3],[5,8],[1,1],[0,9],[5,7]]; var … Read more