2d

pygame moving left and right issue

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 15:11:25
I have started making something on pygame but I have encountered an issue when moving left or right. if I quickly change from pressing the right arrow key to pressing the left one and also let go of the right one the block just stops moving. this is my code bg = "sky.jpg" ms = "ms.png" import pygame, sys from pygame.locals import * x,y = 0,0 movex,movey=0,0 pygame.init() screen=pygame.display.set_mode((664,385),0,32) background=pygame.image.load(bg).convert() mouse_c=pygame.image.load(ms).convert_alpha() m = 0 pygame.event.pump() while 1: for event in pygame.event.get(): if event.type == QUIT:

How to multiple a 2D point with a 4D Matrix

北慕城南 提交于 2019-12-06 14:05:20
问题 How can I convert a 2D point (or 3D with Z=0) to 2D point(where Z is ignored) with a 4D matrix ? I am using Microsofts Silverlight to project a 2D control as pseudo 3D using a Matrix3D definition of Matrix3D I know the initial 2D coordinate of a point in the untransformed control and I want the 2D position of the point after the transform. The silverlight API is sparse regarding 3D methods. Please suggest basic math to perform the calculation. This is a follow on from a silverlight specific

Appropriate similarity metrics for multiple sets of 2D coordinates

删除回忆录丶 提交于 2019-12-06 13:22:25
I have a collection of 2D coordinate sets (on the scale of a 100K-500K points in each set) and I am looking for the most efficient way to measure the similarity of 1 set to the other. I know of the usuals: Cosine, Jaccard/Tanimoto, etc. However I am hoping for some suggestions on any fast/efficient ones to measure similarity, especially ones that can cluster by similarity. Edit 1: The image shows what I need to do. I need to cluster all the reds, blues and greens by their shape/orientatoin, etc. alt text http://img402.imageshack.us/img402/8121/curves.png It seems that the first step of any

Plotting equation to cartesian plane

爷,独闯天下 提交于 2019-12-06 12:38:54
问题 I am trying to plot a two variable equation to a Cartesian plane. Here is my problem, on the code below if I comment out one for loop and let another run, the plot of the graph (the negative or positive sides of x) is correct, but if I run both for loops they seem to alter each other and the graph comes out wrong. I've tried every combination of for loops, looping frontward, backward, nothing seems to solve it. I commented out the where these loops are at the end of the class "public class

Infinite Scrolling Background in XNA

倖福魔咒の 提交于 2019-12-06 11:11:33
I'm drawing a ground texture in a sidescrolling platformer like this: spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, _camera.GetViewMatrix(Parallax)); foreach (Sprite sprite in Sprites) sprite.Draw(spriteBatch); spriteBatch.End(); In Sprite.Draw() public void Draw(SpriteBatch spriteBatch) { if (Texture != null) spriteBatch.Draw(Texture, Position, new Rectangle(0, 0, Texture.Width, Texture.Height), Color.White, Rotation, Origin, Scale, SpriteEffects.None, ZIndex); } How can I get the texture to repeat in the X Direction infinitely? Any resources explaining how to do

Using Swing, I want to draw a couple of points

こ雲淡風輕ζ 提交于 2019-12-06 10:55:09
问题 ... in an image and do some calculation on their [x y] coordinates. My first idea was to use an image as the background of a JPanel and then register the points, but I'm not sure there will be a way to mark these on the JPanel. There is also the Drawing library, which I'm unfamiliar with, but I'm not sure if I can combine these with Swing. Can you name me the packages/classes I can use in order to do the task? References of code that already does it are also welcome. Thank you! 回答1: The issue

How to produce Photoshop stroke effect?

不羁岁月 提交于 2019-12-06 10:31:16
问题 I'm looking for a way to programmatically recreate the following effect: Give an input image: input http://www.shiny.co.il/shooshx/ConeCarv/q_input.png I want to iteratively apply the "stroke" effect. The first step looks like this: step 1 http://www.shiny.co.il/shooshx/ConeCarv/q_step1.png The second step like this: alt text http://www.shiny.co.il/shooshx/ConeCarv/q_step2.png And so on. I assume this will involves some kind of edge detection and then tracing the edge somehow. Is there a

How to get the first column's contents from a 2D array

前提是你 提交于 2019-12-06 10:29:00
How can I pull the first column from my 2D array? I am initialising my array in a method like this //Initialise the array with the values from the file public static float[][] data(float[][] data, Scanner scan){ int count = 0; for (int i=0;i<data.length;i++){ for (int j=0;j<data[0].length;j++){ count++; if(count<data.length*data[0].length){ for(int k=0;k<2; k++){ data[i][j] = (float) IOUtil.skipToDouble(scan); System.out.print(data[i][j] + " "); } System.out.println(); } } } return data; } This is the contents of my test file. (Please bare in mind the file could be any length) 13.97 2.2 12.05

Error on drawing Fibonacci in web

こ雲淡風輕ζ 提交于 2019-12-06 09:57:38
问题 Currently I have this fiddle from Blindman67 which draws Golden spiral figure 1(see image below). function renderSpiral(pointA, pointB, turns){ var dx, dy, rad, i, ang, cx, cy, dist, a, c, angleStep, numberTurns, nTFPB, scale, styles; // clear the canvas ctx.clearRect(0, 0, ctx.canvas.width,ctx.canvas.height) // spiral stuff a = 1; // the larger this number the larger the spiral c = 1.358456; // constant See https://en.wikipedia.org/wiki/Golden_spiral angleStep = Math.PI/20; // set the

How to test if a line intersects a convex polygon?

被刻印的时光 ゝ 提交于 2019-12-06 09:37:27
Assume you are given the equation of a line (in 2d), and the equations of lines that form a convex polygon (the polygon could be unbounded). How do I determine if the line intersects the polygon? Furthermore, are there computational geometry libraries where such tasks are pre-defined? I ask because I'm interested not just in the 2D version but n-dimensional geometry. For the 2D case, I think the problem simplifies a bit. The line partitions the space into two regions. If the polygon is present in only one of those regions, then the line does not intersect it. If the polygon is present in both