Hi again, 

It does not draw segments but I guess it should be easily extendable to do so - 
its late and I'll go to bed now instead of playing any further. Btw. it does 
500 lines in 12ms on my C2D.
Did not think about the gradient solution, sounds really good :)

[code]

package waterfall;
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Arc2D;
import java.awt.image.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;
 
public class WaterfallArc01 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();
    
    LinkedList<Color[]> list = new LinkedList();
    
    public WaterfallArc01() {
        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; i<numberSectors; i++)
        {
            sectors[i] = getColor();
        }
        
        list.addLast(sectors);
        
        if (list.size()>diameter/2)
        {
            list.removeFirst();
        }
    }
            
            
    private Color getColor() 
    {
        return new Color(seed.nextInt(0x1000000));
    }
 
    
    @Override
    protected void paintComponent(Graphics g)
    {
        render(g);
    }
    
    void setRGB(int x, int y, Color[] colors)
    {
//               int angle = (int) Math.toDegrees(Math.atan2(x, y));
//               angle = angle == 0 ? 1 : angle;
                 int rgb = colors[0].getRGB();
        
        int index = y*bimg.getWidth() + x;
        if(index < data.length)
        {
                data[index] = rgb;
        }
    }
    
         void rasterCircle(int x0, int y0, int radius, Color[] colors)
          {
            int f = 1 - radius;
            int ddF_x = 1;
            int ddF_y = -2 * radius;
            int x = 0;
            int y = radius;
            
            setRGB(x0, y0 + radius, colors);
            setRGB(x0, y0 - radius, colors);
            setRGB(x0 + radius, y0, colors);
            setRGB(x0 - radius, y0, colors);
         
            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);
              setRGB(x0 - x, y0 + y, colors);
              setRGB(x0 + x, y0 - y, colors);
              setRGB(x0 - x, y0 - y, colors);
              setRGB(x0 + y, y0 + x, colors);
              setRGB(x0 - y, y0 + x, colors);
              setRGB(x0 + y, y0 - x, colors);
              setRGB(x0 - y, y0 - x, colors);
            }
          }
 
    private void render(Graphics g)
    {
        Graphics2D g2d = (Graphics2D) bimg.getGraphics();    
        
        long startTime = System.nanoTime();
        int size = diameter;
        int x=500;
        int y = x;
        double startAngle=0;
        double oldX=x;
 
        // Erase background to white
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, diameter, diameter);
        
 
        Color[] sectors;
        Iterator<Color[]> it = list.descendingIterator();
        while(it.hasNext())  // each update
        {
            sectors = it.next();
                        
            /*for(int i=0; i< sectors.length; i++)  // all sectors
            {
                g2d.setColor(sectors[i]);
                g2d.draw(new Arc2D.Double(x, y, size, size, startAngle, 
                    sectorExtent, Arc2D.OPEN));
                startAngle += sectorExtent;
            }*/
            rasterCircle(500, 500, size/2, sectors);
            oldX = x;
            do{
                size = size - 1;
                x = (diameter - size)/2;
            } while(x == oldX);
            y = x;
            startAngle=0d;
        }
        
        long estimatedTime = System.nanoTime() - startTime;
        System.out.println(list.size()+" lines, render time: 
"+(double)estimatedTime/1e9);
        
        g.drawImage(bimg, 0, 0, null);
    }
  
}
[/code]
[Message sent by forum member 'linuxhippy' (linuxhippy)]

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

===========================================================================
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".

Reply via email to