graphics

Blending images in java

与世无争的帅哥 提交于 2019-12-23 22:27:56
问题 Well I've got my game engine running smoothly, and perfectly on all machines! Before I continue adding functionality to the engine, I want to enhance the engine's graphical capabilities. The one I'm focused on is fading and blending images. I'm going to need some smooth transitions, so without using any 3rd party libraries like OpenGL, how does one apply opacity to images when drawing to a graphics object? thanks for any replies :D 回答1: Perhaps using an AlphaComposite could be what you're

Adding a point to the ggplot messes up the legend

£可爱£侵袭症+ 提交于 2019-12-23 22:14:02
问题 I have a data dataframe dat <- data.frame(cond = rep(c("A", "B"), each=10), xvar = 1:20 + rnorm(20,sd=3), yvar = 1:20 + rnorm(20,sd=3)) I want to scatter-plot it using ggplot2 Lets say the additional point would just be 15th row in the data g1 <- dat[15,] I can now generate the plot using scat1 <- ggplot(dat, aes(x=dat[,2], y=dat[,3], shape=factor(dat[,1]), size=2.5, colour = factor(dat[,1]))) + geom_point(alpha=1) #Add point to the plot scat1 <- scat1 + geom_point(x=g1[,2],y=g1[,3], colour=

What is the best approach to compute efficiently the first intersection between a viewing ray and a set of objects?

时间秒杀一切 提交于 2019-12-23 22:11:54
问题 For instance: An approach to compute efficiently the first intersection between a viewing ray and a set of three objects: one sphere, one cone and one cylinder (other 3D primitives). 回答1: What you're looking for is a spatial partitioning scheme. There are a lot of options for dealing with this, and lots of research spent in this area as well. A good read would be Christer Ericsson's Real-Time Collision Detection. One easy approach covered in that book would be to define a grid, assign all

Painting Graphics2D in a JFrame

為{幸葍}努か 提交于 2019-12-23 22:09:02
问题 I'm making a 2d vertical shooter game, in which everything is coded (and working) but the graphics. I have not used the Graphics classes before, so this is all new to me. The following is the code I use to paint everything to the JFrame: public void paintAll() { Graphics h = new Graphics2D(); for(Bullet j : GameState.getEnBullets()){ h.drawImage(j.getImage(),j.getX(), j.getY(), null);} for(Enemy j : GameState.getEnemies()){ h.drawImage(j.getImage(),j.getX(), j.getY(), null);} for(Bullet j :

Help me solve this bug with my ray tracer

不羁的心 提交于 2019-12-23 21:50:25
问题 I'm not going to post any code for this question because it would require way too much context, but I shall explain conceptually what I'm doing. I'm building a simple ray tracer that uses affine transformations. What I mean is that I'm intersecting all rays from camera coordinates with generic shapes. The shapes all have associated affine transformations, and the rays are first multiplied by the inverses of these transformations before intersecting with scene objects. So for example, say I

BlackBerry - how two merge two images

自闭症网瘾萝莉.ら 提交于 2019-12-23 21:39:06
问题 I want to merge two images in blackberry. one image is a big image and other image is a small one. position of small image will be define by developer. what are the possible ways? 回答1: You can use the Graphics class to draw multiple Bitmaps onto it in different offsets. Look into the Graphic.drawBitmap function. We use something like: graphics.drawBitmap(x1, y1, icon.getWidth(), icon.getHeight(), icon, 0, 0); Where the graphics object is the one passed by the paint method we override and icon

Drawing graphics on top of a JButton

北城余情 提交于 2019-12-23 21:00:31
问题 I have a situation wherein I have a bunch of JButtons on a GridLayout. I need each of the JButtons to have: a background image (but retain the ability to keep the default button look if needed) custom graphics drawn on top by other classes I have no trouble with the background image, since I am using setIcon() but I am having problems drawing things on top of the background. At one point I was able to draw on top of the button, but after the button was clicked, the drawings disappeared. How

Why is this print line command executing twice?

瘦欲@ 提交于 2019-12-23 20:29:06
问题 I have the code below. It all works, but annoyingly, the print line command in the while loop runs twice. There is (and I have tested for it), only unique items in the queue, no duplicates. public void paint(Graphics g) { boolean isParent; int drawCount = 1; int x = 0, y = 0, width = 0, height = 0; Color colour; while (!qtreeQueue.empty()) { drawNode = (QuadTreeNode) qtreeQueue.deque(); isParent = drawNode.getIsParent(); if (!isParent) { x = drawNode.getRectangle().x; y = drawNode

Clear foreground of a drawing panel in Swing

北城以北 提交于 2019-12-23 19:46:44
问题 Making this paintbrush program I decided I want to clear the panel container ( panel2 in the linked code). I used PanelName.setForeground(null) and it worked. What I'd like to know is if there are known drawbacks of this approach and other ways of removing graphics objects from the container. 回答1: If you override paintComponent , you can clear its Graphics using Graphics#clearRect. But overall, I prefer your approach because mine would require you to either subclass JPanel , or anonymously

Why does this R ggplot2 code bring up a blank display device?

梦想与她 提交于 2019-12-23 19:14:07
问题 While SO is not usually used for help with bugs, this one shows particularly simple and particularly annoying behavior. If you are a ggplot2 user, you can reproduce it in 10 seconds or less. As this GitHub issue: ggplot_gtable creates blank display says, the following code library(ggplot2) stat = qplot(Sepal.Length, Petal.Length, data = iris, color = Species) ggplot_gtable(ggplot_build(stat)) will produce a blank device. Note that since ggplot2 is a graphics library, some commands can bring