Implementing a random color..


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Implementing a random color..

  1. #1
    Join Date
    Sep 2004
    Posts
    37

    Implementing a random color..

    I have written this program but I now need to modify it so that if plots each line inside the for loop in a random color:

    import java.awt.*;
    import java.applet.Applet;

    public class Lines1 extends Applet
    {
    public void paint(Graphics g)
    {
    g.drawLine(0,0,100,50);
    g.setColor(new Color(255,0,0));
    g.drawLine(50,75,200,25);
    g.drawLine(50,75,200,26);
    g.setColor(new Color(0,255,0));
    for (int y1=120;y1<200;y1++)
    {
    g.drawLine(100,y1,200,y1+20);
    }
    }
    }

    Once again, any help is much appreciated.
    Cheers
    Steve

  2. #2
    Join Date
    Sep 2004
    Posts
    37
    I've solved it! THanks anyway.
    Cheers
    Steve

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You can specify a new Color like this

    int colorInt=12345;
    Color c=new Color(colorInt);

    So you can basically generate random int's and create colors that way. - Check out Math.random().

    However, I'm not sure how it will perform if you do this by the thousands...
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center