graphics

Can't flip direction of ball without messing up gravity

你说的曾经没有我的故事 提交于 2019-12-29 02:12:07
问题 I am making a game like pong except that there is only one paddle and the ball moves in projectile motion. The goal is to keep the ball bouncing on your paddle for as long as possible. I when I have the ball hit the paddle the direction of the y component of the velocity has it's sign flipped. The issue with this is that when the ball is moving up gravity acts upon in in that direction, speeding it up. The code is below This is the code for my ball class, this is the tick method which is

JPanel background image

血红的双手。 提交于 2019-12-29 01:46:50
问题 This is my code, it indeed finds the image so that is not my concern, my concern is how to make that image be the background of the panel. I'm trying to work with Graphics but i doesnt work, any ideas?? please?? try { java.net.URL imgURL = MAINWINDOW.class.getResource(imagen); Image imgFondo = javax.imageio.ImageIO.read(imgURL); if (imgFondo != null) { Graphics grafica=null; grafica.drawImage(imgFondo, 0, 0, this); panel.paintComponents(grafica); } else { System.err.println("Couldn't find

Chart Compression

橙三吉。 提交于 2019-12-29 01:28:11
问题 I am writing a C# desktop application that requires a graphical representation (XoY) of some values (Y - value, X - (in) time). chart1.Series[0].Points.AddXY(time, new Random().Next(-325, 531)); //this operation occurs at a set interval The operation does its job, adding up values; however, in time the chart has the tendency to "squeeze" itself which makes interpreting it a much harder task. I want to make the graphic generate a better output, despite the number of points. Notes I consider

Java Swing graphics glitch?

风格不统一 提交于 2019-12-28 22:37:46
问题 Image of the glitch I am learning Java by reproducing examples from a textbook and as soon as I got to using the GUI classes I experienced some weird glitches, if that is the correct term. As you can see on the image, parts of the text are missing. The code generating this dialog isn't complicated either: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.Timer; public class InnerClassTest { public static void main(String[] args) {

C++ triangle rasterization

佐手、 提交于 2019-12-28 12:47:12
问题 I'm trying to fix this triangle rasterizer, but cannot make it work correctly. For some reason it only draws half of the triangles. void DrawTriangle(Point2D p0, Point2D p1, Point2D p2) { Point2D Top, Middle, Bottom; bool MiddleIsLeft; if (p0.y < p1.y) // case: 1, 2, 5 { if (p0.y < p2.y) // case: 1, 2 { if (p1.y < p2.y) // case: 1 { Top = p0; Middle = p1; Bottom = p2; MiddleIsLeft = true; } else // case: 2 { Top = p0; Middle = p2; Bottom = p1; MiddleIsLeft = false; } } else // case: 5 { Top =

The Maximum Volume of Trapped Rain Water in 3D

随声附和 提交于 2019-12-28 08:08:51
问题 A classic algorithm question in 2D version is typically described as Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given the input [0,1,0,2,1,0,1,3,2,1,2,1] the return value would be 6 The algorithm that I used to solve the above 2D problem is int trapWaterVolume2D(vector<int> A) { int n = A.size(); vector<int> leftmost(n, 0), rightmost(n, 0); //left exclusive scan, O(n), the

How to flood-fill part of a bitmap enclosed by a black border with my chosen color?

这一生的挚爱 提交于 2019-12-28 06:26:50
问题 I want to programmatically modify a bitmap using python but don't really need a thorough grounding in the subject, so would like to concentrate on learning just what I need to get the job done. A good example of the kind of thing I'm after would be a bitmap image of england and it's counties. This would initially display a black border around all the counties on a white background. So far so good, but how can I dynamically change the background color of a county? Off the top of my head I was

Algorithm for drawing a 4-connected line

老子叫甜甜 提交于 2019-12-28 05:54:12
问题 I'm looking for an algorithm (coded in Java would be nice, but anything clear enough to translate to Java is fine) to draw a 4-connected line. It seems that Bresenham's algorithm is the most widely used, but all the understandable implementations I've found are 8-connected. OpenCV's cvline function apparently has a 4-connected version, but the source code is, to me, as a mediocre and nearly C-illiterate programmer, impenetrable. Various other searches have turned up nothing. Thanks for any

Algorithm for drawing a 4-connected line

≡放荡痞女 提交于 2019-12-28 05:54:08
问题 I'm looking for an algorithm (coded in Java would be nice, but anything clear enough to translate to Java is fine) to draw a 4-connected line. It seems that Bresenham's algorithm is the most widely used, but all the understandable implementations I've found are 8-connected. OpenCV's cvline function apparently has a 4-connected version, but the source code is, to me, as a mediocre and nearly C-illiterate programmer, impenetrable. Various other searches have turned up nothing. Thanks for any

Image zoom centered on mouse position

[亡魂溺海] 提交于 2019-12-28 05:35:57
问题 I am writing a script with Fabric.js to zoom an image at the current mouse position. I have made some progress but there is an error somewhere. Case 1 : Keep the mouse at one point and zoom with the mouse wheel. Result: Works perfectly, image zooms at that particular pixel. Case 2: Zoom in a little at one position (3-5 times with mouse wheel), then move the mouse to a new position and zoom in there. Result: Works fine for the first point, but after moving to another point and zooming, the