graphics

Picking in java 2d

二次信任 提交于 2019-12-14 01:27:19
问题 I am using java2d to draw a simple graph at the moment I have implemented picking by calling contains(MousePoint) for each object/shape, this works but scales linearly. Is there a more efficient method for picking in java2d? 回答1: Yes, although the full answer would be too long for this space. First of all, unless you have a lot of nodes, then linear will most likely be fine, and you shouldn't change anything unless performance is already seen to suffer. Second, what you want, in general, is

“Screen” effect in Java 2D graphics

狂风中的少年 提交于 2019-12-14 01:21:29
问题 This is a question that's been bugging me for some time now: In photoshop/GIMP, there is a "screen" layer composition mode. This mode has bright colours have a strong alpha, and dark colours a weak one. Black is entirely transparent, white entirely opaque. I would dearly love to be able to replicate this composite using Java 2D graphics, but my repeated attempts at trying to coax AlphaComposite into this have failed - and indeed I think this is outside of AlphaComposite's capabilities. A

High-Resolution Processing Output

微笑、不失礼 提交于 2019-12-14 00:35:56
问题 I'm looking for help with the programming language/environment Processing. I'm fairly new to Processing and I am experimenting with a piece of code from someone over at openprocessing.org. I really like the visual results this code delivers and I would like to further work with it. Unfortunately, the output is very low resolution. Hence I'm looking for someone who might be able to help me figure out how to a) Increase the size or resolution of the shapes generated and b) save everything as a

Can not complete drawline on JButton [closed]

被刻印的时光 ゝ 提交于 2019-12-13 23:18:23
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . So I am making a simple tic tac toe game and ran into a problem at the last minute I am trying to draw a line at the win location but on the final win location(index), the line gets hidden behind the JButton not entirly sure why it is doing this. I know alot of people say do not use getGraphics() , and I am

Drawing lines in java (Graphics 2D)

十年热恋 提交于 2019-12-13 22:13:07
问题 I am trying to do a little program on Eclipse. The program goes like this: when I click for the 1st time on thr Panel on the frame, a line has to be drawn regarding the Y position of my mouse listener.The line takes all the width of the panel. On the 2nd click, another line has to be drawn, again regarding the Y position of where I clicked. After, I'll put a little circle between the 2 lines and make a little animation with it. But now, I have a problem. When I click on the panel, a line is

Rotate tetris blocks at runtime

空扰寡人 提交于 2019-12-13 21:29:55
问题 I have a class tetronimo (a tetris block) that has four QRect types (named first , second , third , fourth respectively). I draw each tetronimo using a build_tetronimo_L type functions. These build the tetronimo in a certain direction, but as in tetris you're supposed to be able to rotate the tetronimo's, I'm trying to rotate a tetronimo by rotating each individual square of the tetronimo. I have found the following formula to apply to each (x, y) coordinate of a particular square. newx = cos

Using user-defined functions within “curve” function in R graphics

送分小仙女□ 提交于 2019-12-13 21:14:17
问题 I am needing to produce normally distributed density plots with different total areas (summing to 1). Using the following function, I can specify the lambda - which gives the relative area: sdnorm <- function(x, mean=0, sd=1, lambda=1){lambda*dnorm(x, mean=mean, sd=sd)} I then want to plot up the function using different parameters. Using ggplot2, this code works: require(ggplot2) qplot(x, geom="blank") + stat_function(fun=sdnorm,args=list(mean=8,sd=2,lambda=0.7)) + stat_function(fun=sdnorm

lockCanvas and synchronization in Android

荒凉一梦 提交于 2019-12-13 20:59:24
问题 @Override public void run() { Canvas canvas = null; // used for drawing { while (threadIsRunning) { try { canvas = surfaceHolder.lockCanvas(null); // line 1 synchronized(surfaceHolder) // line 2 { //do something ..... } } } } According to many post and blogs lockCanvas will make a lock on canvas so that multiple access to canvas is not possible and synchronized block is used so that no other thread draw on canvas .. Ques is if other thread is prevented from having a canvas by lock canvas by

Get bitmap and draw it into image

一笑奈何 提交于 2019-12-13 19:03:12
问题 I am trying to save my drawing from picturebox into bitmap and draw that bitmap into image. So far, nothing has appeared in the final image, but while debugging I can only say, that the original bitmap is not null and with/height are correct. However nothing appears after I draw it into image. I save my drawing into bitmap like this: GraphicsPath path = RoundedRectangle.Create(x, y, width, height, corners, RoundedRectangle.RectangleCorners.All); g.FillPath(Brushes.LightGray, path); g.SetClip

Flickering Java GUI in Ubuntu 14.04

守給你的承諾、 提交于 2019-12-13 18:43:33
问题 I stumbled upon a problem I cant solve nor can I understand. I'm writing a simple 2D game using Java 1.8.0_31 with java.awt.Canvas on Ubuntu 14.04. The problem is that I get this unbearable flickering(an issue I never had on Windows), to make sure my code is not the problem I wrote a small test program with a moving circle... The test loop: public void run() { long startTime = System.currentTimeMillis(); long tick = 1000; int fps = 0; int upd = 0; double nanoScale = 1000000000.0 / 60; double