Re: [JAVA2D] Optimizing concentric arcs

2008-09-24 Thread java2d
I don't modify the Graphics2D default stroke value, so I assume that the arcs 
are 1 pixel wide.
[Message sent by forum member 'ser207' (ser207)]

http://forums.java.net/jive/thread.jspa?messageID=301250

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Optimizing concentric arcs

2008-09-24 Thread java2d
Ig thanks for your reply.  I'm amazed by how much quicker your method is 
compared to g2d.draw( Ellipse2D));   There is a MASSIVE difference.

I have tried to adapt your solution to draw arcs;   i've googled but have not 
been able to find an arcs algorithm that I can use (at least not one that works 
correctly).  And not being a mathematician some of the algorithms meant nothing 
to me.   Any help/pointers would be greatly appreciated.
[Message sent by forum member 'ser207' (ser207)]

http://forums.java.net/jive/thread.jspa?messageID=301257

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Optimizing concentric arcs

2008-09-24 Thread java2d
this thing is called midpoint circle algoyrthm.
There is also a version which draws the circly only in a defined angle, I was 
not able to find such a version with a quick look at search machines, but I 
think there are definitivly ready-to-use implementations available.

A better optimized solution would be to look up for the right color in setRGB 
depending on the angle of the currently drawn pixel - this way you draw the 
circle only once, altering the color is bascially free :)

lg Clemens
[Message sent by forum member 'linuxhippy' (linuxhippy)]

http://forums.java.net/jive/thread.jspa?messageID=301302

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Optimizing concentric arcs

2008-09-24 Thread java2d
 this thing is called midpoint circle algoyrthm.
Yes after my previous post I found this: 
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
Which led me to hack your version of the waterfall code to do arcs.
Unfortunately I don't think it is accurate for small angles, for example less 
than 10 degrees.  Any idea where I'm going wrong?

 A better optimized solution would be to look up for the right color in setRGB 
 depending on the angle of the currently drawn pixel - this way you draw the 
 circle only once, altering the color is bascially free
This is a cool idea!


[code]
package waterfall;
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.awt.image.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;
 
public class WaterfallCircle01_LH_Arc extends javax.swing.JPanel {
 
private final int diameter = 1000; // pixels
private final int sectorExtent = 1;  // degree;
private final int numberSectors = 360/sectorExtent;
Random seed = new Random();



BufferedImage bimg = new BufferedImage(1000, 1000, 
BufferedImage.TYPE_INT_RGB);
int[] data=((DataBufferInt)bimg.getRaster().getDataBuffer()).getData();

LinkedListColor[] list = new LinkedList();

public WaterfallCircle01_LH_Arc() {
ActionListener taskPerformer = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
generateNewData();
repaint();
}
};
javax.swing.Timer t = new javax.swing.Timer(50, taskPerformer);
t.start();
}

private void generateNewData()
{   
Color[] sectors = new Color[numberSectors];

for(int i=0; inumberSectors; i++)
{
sectors[i] = getColor();
}

list.addLast(sectors);

if (list.size()diameter/2)
{
list.removeFirst();
}
}


private Color getColor() 
{
return new Color(seed.nextInt(0x100));
}
 

@Override
protected void paintComponent(Graphics g)
{
render(g);
}

void setRGB(int x, int y, Color[] colors, Rectangle bounds)
{
int rgb = colors[0].getRGB();

if (bounds.contains(x, y))
{
int index = y * bimg.getWidth() + x;
if (index  data.length)
{
data[index] = rgb;
}
}
}


private Rectangle arcBoundingRectangle(Point startPoint, Point endPoint)
{
Rectangle r = new Rectangle(Math.min(startPoint.x, endPoint.x), 
Math.min(startPoint.y, endPoint.y), 
Math.abs(startPoint.x-endPoint.x), 
Math.abs(startPoint.y-endPoint.y));
return r;
}

private Rectangle arcBoundingRectangle(Point2D startPoint, Point2D endPoint)
{
Rectangle r = new Rectangle((int)Math.round(Math.min(startPoint.getX(), 
endPoint.getX())), 
(int)Math.round(Math.min(startPoint.getY(), endPoint.getY())), 
(int)Math.round(Math.abs(startPoint.getX()-endPoint.getX())), 
(int)Math.round(Math.abs(startPoint.getY()-endPoint.getY(;
return r;
}


private void rasterCircle(int x0, int y0, int radius, Color[] colors, 
Rectangle arcBounds)
{
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;

setRGB(x0, y0 + radius, colors, arcBounds);
setRGB(x0, y0 - radius, colors, arcBounds);
setRGB(x0 + radius, y0, colors, arcBounds);
setRGB(x0 - radius, y0, colors, arcBounds);

while (x  y)
{
if (f = 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;

setRGB(x0 + x, y0 + y, colors, arcBounds);
setRGB(x0 - x, y0 + y, colors, arcBounds);
setRGB(x0 + x, y0 - y, colors, arcBounds);
setRGB(x0 - x, y0 - y, colors, arcBounds);
setRGB(x0 + y, y0 + x, colors, arcBounds);
setRGB(x0 - y, y0 + x, colors, arcBounds);
setRGB(x0 + y, y0 - x, colors, arcBounds);
setRGB(x0 - y, y0 - x, colors, arcBounds);
}
}

Point calcEndPoint(int anchorX, int anchorY, double radius, double 
angleRadians)
{
return new Point((int)Math.round(anchorX+(radius * 
Math.cos(angleRadians))), (int)Math.round(anchorY+(radius * 
Math.sin(angleRadians;
}
 
Point2D calcEndPoint2D(int anchorX, int anchorY, double radius, double 
angleRadians)
{

Re: [JAVA2D] Full Screen Exclusive in two monitor setup

2008-09-24 Thread java2d
Unfortunaly, I no longer have two monitors to try your suggestion, but I will 
give feedback as soon as possible.

Thank you,
Renan.
[Message sent by forum member 'renanpolo' (renanpolo)]

http://forums.java.net/jive/thread.jspa?messageID=301327

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Full Screen Exclusive in two monitor setup

2008-09-24 Thread Dmitri Trembovetski

[EMAIL PROTECTED] wrote:

Unfortunaly, I no longer have two monitors to try your suggestion, but I will 
give feedback as soon as possible.


  You don't need to have two monitors to print out that information -
  as long as it's the same machine it should be fine.

  Thanks,
Dmitri



Thank you,
Renan.
[Message sent by forum member 'renanpolo' (renanpolo)]

http://forums.java.net/jive/thread.jspa?messageID=301327

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


[JAVA2D] Drawing to an off screen buffer

2008-09-24 Thread java2d
Hi,

I'm trying to build a little program that draws complicated time-consuming 
plots. I'd like to avoid having my UI freeze up while I'm rendering, so I don't 
want to do the rendering on the event dispatch thread. So, what's the modern 
(well, Java 5 level of modern) way of doing this?

First, should I be drawing on a Canvas or a JPanel? I'm using Swing components 
in the rest of my app and I've read that you're not supposed to mix Swing and 
AWT, but I can switch if there's good reason.

Next, do I want to use VolatileImage, BufferStrategy, or something else? Can 
you even get a BufferStrategy for a JPanel? I'd like to get hardware double 
buffering, if possible.

Last, I assume it's OK to draw on the offscreen image on another thread and 
then put a runnable on the event dispatch thread to do the blt? Or is that the 
wrong way to go about it?

Any pointers to the current (JDK1.5) wisdom would be appreciated! Thanks,

-chris
[Message sent by forum member 'cbare' (cbare)]

http://forums.java.net/jive/thread.jspa?messageID=301468

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.