graphics

Bar Chart in java

余生长醉 提交于 2019-12-21 05:48:07
问题 I want to change the height of each bar (for example 10 for red part and 20 for blue part). But when I increase the height value it will increase the chart from bottom whereas I want the change to top! Do you know what is wrong with it? import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing

Java / OpenGL: Getting the image of a Canvas as a BufferedImage

无人久伴 提交于 2019-12-21 05:28:34
问题 I've got some code that initializes OpenGL to render to a java.awt.Canvas. The problem is, I can't figure out how I can get the buffer of the canvas and turn it into a BufferedImage. I've tried overriding getGraphics(), cloning the Raster, and replacing the CanvasPeer with a custom one. I'm guessing OpenGL doesn't use java graphics in any way then, so how can I get OpenGL's buffer and convert it into a BufferedImage? I am using LWJGL's code for setting parent: Display.setParent(display_parent

How do I initialize a Graphics object in Java?

喜欢而已 提交于 2019-12-21 05:26:09
问题 this is the code: import java.awt.*; import java.applet.*; public class anim1 extends Applet{ public void paint (Graphics g) { g.drawString("",400,300); } public static void main(String ad[]) { anim1 a=new anim1(); Graphics g1; a.paint(g1); } } It says that g1 is not initialized. But how do I initialize an abstract class? 回答1: Well there are two issues here 1: Graphics g1; a.paint(g1); And you are getting the error that G1 is not initialized. That's because the variable g1 is never set to

How to divide an ellipse to equal segments?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 05:13:19
问题 This calculates vertex coordinates on ellipse: function calculateEllipse(a, b, angle) { var alpha = angle * (Math.PI / 180) ; var sinalpha = Math.sin(alpha); var cosalpha = Math.cos(alpha); var X = a * cosalpha - b * sinalpha; var Y = a * cosalpha + b * sinalpha; } But how can I calculate the "angle" to get equal or roughly equal circumference segments? 回答1: So from what Jozi's said in the OP's comments, what's needed isn't how to subdivide an ellipse into equal segments (which would require

How to make a round Progress Bar in codename one?

主宰稳场 提交于 2019-12-21 05:12:27
问题 I want to create a round progress bar, depicting the current status in percent in its mid. like this: now I already followed the instructions on creating a flat progress bar, but as I am not familiar with swing and I don't have any clue of Javas graphics, I have no clue how to transfer from the 'flat' to the 'round' progress bar. How could a code similiar to the progress bar look like? ps: I saw Hannahs post on the analog clock and tried it like this - but failed due to my lack in painting

iOS - Clipping union of two paths using UIBezierPath appendPath

a 夏天 提交于 2019-12-21 04:39:12
问题 I'm attempting the create a clipping path in the shape of a plus sign, so that subsequent paths that I draw into the same context have this portion removed. I create the clipping path using two rectangle paths overlaid on each other. This is what I'd like the final drawing to look like when I subsequently draw a circle: xXX| |XXx XXXX| |XXXX XXXXX| |XXXXX ——— ——— ——— ——— XXXXX| |XXXXX XXXX| |XXXX xXX| |XXx However, it actually looks like this: xXX| |XXx XXXX| |XXXX XXXXX| |XXXXX ——— XX——— ———

Drawing aliased, pixel-perfect 1px splines (Catmull-Rom, specifically)

徘徊边缘 提交于 2019-12-21 04:36:06
问题 A brief background: I'm working on a web-based drawing application and need to draw 1px thick splines that pass through their control points. The issue I'm struggling with is that I need to draw each of the pixels between p1 and p2 as if I were using a 1px pencil tool. So, no anti-aliasing and one pixel at a time. This needs to be done manually without the use of any line/curve library code as my brush system depends upon having a pixel coordinate to apply the brush tip to the canvas.

R / RStudio : graph scaling issues & fuzziness on high dpi screens

痴心易碎 提交于 2019-12-21 04:32:12
问题 On high DPI 4K monitors it seems that under Windows the RStudio plot window uses pixel doubling to make the plot legible (I'm using RStudio 0.99.483 and R 3.2.2 and Windows 8.1, but same result under Windows 10). This results in really fuzzy text & graphics (plus doesn't play well with Cleartype, as it results in colour fringing after pixel doubling). Example: qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7)) with zoom in RStudio set to 200%

How to fastest check if point (3D) is inside convex hull given by set of point

心不动则不痛 提交于 2019-12-21 04:25:43
问题 I have set P of point (3D) which are vertices of convex hull (every one). I looking for method for checking if given point p0 is NOT outside of this convex hull. I'll have to repeat the checking it several times (for different p0). So if is possible to reuse part of computation it would be great. On stackoverflow pages i found this: Find if a point is inside a convex hull for a set of points without computing the hull itself There are 2 aproche: First based on convex hull property - set of

OpenGL: projecting mouse click onto geometry

五迷三道 提交于 2019-12-21 04:15:07
问题 I have this view set: glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective glLoadIdentity(); //Reset the drawing perspective and I get a screen position (sx, sy) from a mouse click. Given a value of z, how can I calculate x and y in 3d-space from sx and sy? 回答1: You should use gluUnProject : First, compute the "unprojection" to the near plane: GLdouble modelMatrix[16]; GLdouble projMatrix[16]; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX