Random Colors? help :(

What is the command to make random colors?

Simple bug in your code, nothing big, really...
rg.nextInt(256), rg.nextInt(256), rg.nextInt(256));
There is no error in my code, the range is 0 to 255..
"Color(int r, int g, int b, int a)
Creates an sRGB color with the specified specified red, green, blue, and alpha values in the range (0 - 255)."Yes, there is an error in your code. I see you read the Color API. Did you read the API for Random.nextInt()?

Similar Messages

  • Need help forming randomly colored lines, that are equidistant(ex included)

    My assignment: The
    top-right cell requires horizontal lines that are equidistant in the cell. Each line is 10 pixels apart. Additionally, the lines need to be colored randomly in any possible red, green and blue range.
    example: http://i68.photobucket.com/albums/i35/stxda/example.jpg
    (example of what I need to do)
    what I have now: http://i68.photobucket.com/albums/i35/stxda/current.jpg
    I have all the lines coded for the top right cell, but I do not know how to get the colors random. I only know how to set all the lines to one single color.
    Below is my coding:
    (please try this out and help me code it)
    my AIM screen name is sTxDa if there are any questions/comments
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    public class Lab06G90 extends Applet
    public void paint(Graphics g)
    // BELOW is for the top left cell and box (which is int a and the box's frame)
    int width = 800;
    int height = 600;
    g.drawRect(10,10,width,height);
    g.drawLine(410,10,410,610);
    g.drawLine(10,310,810,310);
    for (int a = 20; a <= 400; a += 10)
    g.drawLine(a,20,a,290);
    // BELOW is for the top right cell, which is int b. so far
    // i've only done the lines, and not yet the random colors
    for (int b = 10; b <= 290; b += 10)
    g.drawLine(420,b,800,b);
    }

    but I do not know how to get the colors randomUse the Random class.

  • Help needed in generating random colors...

    Please review my code. I'm trying to generate ten triangles in random colors but each time I run the app the triangles are always in the same color (but a different color with each run). What am I doing wrong?
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class DrawTriangles extends JFrame
    public DrawTriangles ( )
    super ( "Drawing Random Triangles" );
    setSize ( 400, 400 );
    setVisible ( true );
    public void paint ( Graphics g )
    super.paint ( g );
    int [ ] xArray = { 10, 40, 70, 100, 130, 160, 190, 220, 250, 280 };
    int [ ] yArray = { 30, 60, 90, 120, 150, 180, 210, 240, 270, 300 };
    Graphics2D g2d = ( Graphics2D ) g;
    GeneralPath triangle = new GeneralPath ( );
    for ( int counter = 0; counter < 10; counter++ )
    triangle.moveTo ( xArray [ counter ], yArray [ counter ]);
    for ( int count = 1; count < 3; count++ )
    triangle.lineTo ( xArray [ counter ] + 20, yArray [ counter ] + 40 );
    triangle.lineTo ( yArray [ counter ] + 20, xArray [ counter ] + 20 );
    triangle.closePath ( );
    g2d.setColor ( new Color (
    ( int ) ( Math.random ( ) * 256 ),
    ( int ) ( Math.random ( ) * 256 ),
    ( int ) ( Math.random ( ) * 256 ) ) );
    g2d.fill ( triangle );
    public static void main ( String args [ ] )
    DrawTriangles application = new DrawTriangles ( );
    application.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );

    You're are only drawing one thing, the GeneralPath, not ten things. If you want your things to have ten different colors then you will need ten different things. (ie, use 10 different general path instances)

  • Randomized Colors are Too Dark. Questions on Color Boxes

    Hey all,
    I am attempting to change the color of the plots on a mixed signal
    graph remotely using the "color box" control which works fine; however, I
    am also setting the color boxes to a random color when the program
    first starts up which is where my problem lies.
    What I currently am doing is that I have a random number generator
    pumping out a number after which I multiply the number by 10000000, just
    to give me some colors brighter than black, and then I have that wired up to
    the color box control I am setting the random color on. The problem with
    this is that although it does produce some decent colors some of the
    colors produced are quite dark and pretty hard to see on the mixed
    signal graph.
    I could make the graph background a different color if I have to in
    order to see a majority of the colors that come out, but I would much
    rather just have the colors come out more on the bright and colorful
    side.
    So I have two questions for you guys and gals:
    1) How do the colors of the colorbox get determined using the unsigned 32 int?
    One such example of why I am confused is that the number that I have
    going in is 5726420 from the random number generator (+ being
    multiplied), but on the colorbox control the RGB value is R:87 G:96
    B:212. Why is that?
    2) Is there any kind of algorithm out there that someone has done
    that can produce values randomly that will give kind of neony colors? or
    anything semi-bright for that matter?
    Any help is very much appreciated!
    Ionized
    Solved!
    Go to Solution.

    Use "RGB to color" from three random U8 (o..255) values to generate a color. (double click it to open the VI to understand the structure of the color data type )
    LabVIEW Champion . Do more with less code and in less time .

  • Howto: Random color in the spry menu

    Im new to css and trying to use random colors when hovering over the links in the spry menu.
    I anderstand i need to use javascript for the random hex value, but i cant figgure how to insert the value into the css.

    Have a look at th Spry Element Selector Utility which can be found here http://labs.adobe.com/technologies/spry/articles/element_selector/ and here http://labs.adobe.com/technologies/spry/articles/data_api/apis/element_selector.html
    I hope this helps.
    Ben

  • How do I generate a random color? Here's my code...

    I'm trying to color a rectangle one of four colors, randomly. I can't figure out what I'm doing wrong. Here's my code:
    import javax.swing.*;
    import java.awt.*;
    public class Rectangle extends JComponent  {
         private static final long serialVersionUID = 1L;
         public Rectangle(int x, int y, int w, int h)  {
            super();
              setBounds(x, y, w, h);
            setBackground(Color.RED);
        public void paint(Graphics g)  {
            g.setColor( getBackground() );
            g.fillRect(0, 0, getWidth()-1, getHeight()-1);
            repaint();
            paintChildren(g);
    }Basically, I need "g.setColor( getBackground() );" to be one of four random colors. I have a seperate class that this is used for.
    Here is some code I was throwing around, but it doesn't seem to work at all:
    public void randomcolor(int too) {
         Random ran = new Random();
         too=ran.nextInt(4)+1;
         switch (too)     {
         case 1: color=Color.blue;
         break;
         case 2: color= Color.green;
         break;
         case 3:color=Color.orange;
         break;
         case 4: color=Color.green;
         break;
         default: System.out.println("wrong number, pick another ");
         top.setBackground(color);
         left.setBackground(color);
         right.setBackground(color);
         bottom.setBackground(color);
    }     Any help would be amazing. Thanks!

    Thanks! Your code worked exactly as it was supposed
    to. =D
    Unfortunately, mine's kind of messed up at the core.
    You see, I have 4 rectangles (forming a square) that
    flash in a random position at a random size in a
    window (like a screen saver.)
    Each time the square flashes, I need it to be a
    different color, preferably with all the sides the
    same random color. However, where I put the random
    code, it chose random colors for each side and stuck
    with them throughout the whole animation of the
    square bouncing around.
    I'm not sure what to do, now. If you want, I'll post
    my code, if you think you can help.
    ~DacWhat you could do then is move the responsibility of changing the Color of a Rectangle away from the Rectangle class and let one class control the four Rectangles. Something like this:
    import java.awt.Color;
    import java.util.Random;
    public class RectangleController {
        private static Random rand = new Random();
        private Color[] colors = {Color.blue, Color.green, Color.orange, Color.green};
        private Rectangle[] rectangles;
        public RectangleController() {
            rectangles = new Rectangle[4];
        public void changeColors() {
            Color newColor = getRandomColor();
            for(Rectangle rect : rectangles) {
                rect.setBackground(newColor);
        private Color getRandomColor() {
            return colors[rand.nextInt(colors.length)];
    }

  • 4 pre-defined random colors

    Hi everybody
    Im trying do design an application in flash and I want to use
    random colors. But i just want to use 4 pre-defined random colors.
    So my question is this: how do I set the 4 colors to display
    randomly?I must say that I'm a begginer in flash so please have
    some patience...
    Thank you for your help
    Best regards,

    Create an array that holds your pre-defined colors, then use
    the random math function to get an random index to use for your
    array which will give you your randomly defined color. Something
    like this:
    var myArray:Array = ["0xFF0000", "0x00FF00", "0x0000FF"];
    var randColor:String = myArray[random(3)];
    trace(randColor);
    So you'd use the variable randColor wherever you're defining
    the color in your movie.
    Hope that helps!

  • Rented a movie but cannot watch it; It shows random color screen with correct voices

    I cannot capture the movie, but it has many random colored box.
    The movie is "Red riding hood". I rented it.
    I wonder if anyone here can help me and also point me to where I can refund this. It looks like I won't be able to watch it.

    Hi Tanin,
    Welcome to the Support Communities!
    The following information should help you with this:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
    http://support.apple.com/kb/HT1933?viewlocale=en_US
    Cheers,
    Judy

  • Where is "Assign Random Colors To Parts" in Acrobat 9 Pro Extended?

    In Acrobat 8 3D there was "Assign Random Colors To Parts" in the Enhance tab of the Conversion dialog box. Where did it go in Acrobat 9 Pro Extended?

    Hello Greg!
    Thank you for your post.
    You should know that these forums are specific to the
    Acrobat.com website and its set of hosted services, and do
    not cover the Acrobat family of desktop products.
    Please visit the following Acrobat forums for any questions
    related to the Acrobat family of desktop products:
    http://www.adobeforums.com/cgi-bin/webx/.3bbeda8b/
    Thanks!!
    Pete

  • Color picker from swatches choosing random color (Illustrator CC 2014)...

    When I select a color from swatches, and use the color picker (i.e. double click fill color) for shades and whatnot, it initially shows a random color... anyone else getting this? Every single time you open the color picker it never stays at the current fill color... ugh. Now, if I pick a color from a Kuler swatch, it shows properly.

    I figured out a quick workaround to this that at least lets you continue on. When you select the object the color of which you want to know, the color picker dialog window opens. You'll see the false swatch color on the top (in this case the green) and the true color on the bottom (in this case the orange). Double click the orange color field. This will make both orange, and display the true values.
    Note that, unless you change some value, when you repeat this, it will still display the green.

  • A torrent i recently downloaded keeps popping up again and again and again. I've already downloaded it, but the download window still pops up randomly. Help!!!

    A torrent i recently downloaded keeps popping up again and again and again. I've already downloaded it, but the download window still pops up randomly. Help!!!

    Try to clear your download history. You will find help in [[Clear Recent History]].

  • When using the brush tool to paint a color, it is painting different, random colors

    When using the brush tool to paint a color, it is painting different, random colors  (Elements 11)

    Click on the top right corner in the tool option bar of the brush tool and select "Reset Tool". Probably your blending mode other than 'Normal' is selected.

  • How can to randomly color only half of the string?

    hello
    i need guidance in randomly coloring only half of the string, this string is also moving and changing color only in half part.
    suggestions will be appreciated, thx
    jenny

    Your best bet would be to use crayola or magic marker. If your colorblind, read the labels on the crayons and they will say what the colors are.

  • I'm trying to create a random color generator

    //               create random color generator
                        String[]colors = {"RED", "ORANGE", "YELLOW", "GREEN", "BLUE", "INDIGO", "PURPLE"};
    //               create variable to store random color
                        int mycolorint = (int)(Math.random()*7);
                        String mycolor = colors[mycolorint];
    //               label axis
                   StdDraw.setPenColor(StdDraw.(mycolor));
    what is wrong with this code?

    StdDraw.setPenColor(StdDraw.(mycolor));This line really doesn't make any sense. If you think about it you haven't seen any java code which includes something like "foo.(bar)" or "Foo.(bar)". The compiler wants to see identifiers either side of the dot - and identifiers don't start with a (.
    I am guessing that if "RED" gets chosen from the array, then you want the label axis to useStdDraw.setPenColor(StdDraw.RED);In that case you have to set the array up a little differently.
        // create random color generator
    ???[]colors = {
            StdDraw.RED, StdDraw.ORANGE, StdDraw.YELLOW,
            StdDraw.GREEN, StdDraw.BLUE, StdDraw.INDIGO, StdDraw.PURPLE
        // create variable to store random color
    int mycolorint = (int)(Math.random() * 7);
    ??? mycolor = colors[mycolorint];
        // label axis
    StdDraw.setPenColor(mycolor);You will have to read the documentation for this StdDraw class to see what type StdDraw.RED etc are.

  • Giving particles random colors AND fade out.

    Hi all, I want to make my particles start with random colors AND fade out but it seems to be impossible to do... even though I would think its a pretty fundamental feature.
    The only way it seems to make them start with random colors is Particle Cell: Color Mode: Pick from range - and setup the gradient with the allowed colors - but then I cant fade them out. The only way it seems to make them fade out is to set Color Mode: Over Life.
    It seems quite logical that there would be a Particle Behaviour 'Fade Over Life' (similar to Scale Over Life) which you apply to the cell. Is this possible to implement some how? ideally I would also like each particle to fade in briefly as well as fading out - but i guess thats asking too much!!

    If you use the Color Mode of Pick from Range, the opacity gradient will still work "over life" - controlling opacity over the life of each particle. Just add opacity tags at the end and middle, and set the ending opacity to zero (and beginning, if you like)

Maybe you are looking for