Make Black in RGB?

Discussion in 'iOS Development' started by Rockstarou812, Apr 12, 2009.

  1. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Ok I made a simple drawing app, I have an array of colors and they each have a red, blue, and green value. I know how colors work, when they are all combined 100%, you get white. I want black...

    Any suggestions?

    Code:
    redA = [[NSMutableArray new] retain];
    	[redA addObject:[NSNumber numberWithFloat:1.0]]; //1
    	[redA addObject:[NSNumber numberWithFloat:1.0]]; //1 
    	[redA addObject:[NSNumber numberWithFloat:0.356862745098039]]; //2
    	[redA addObject:[NSNumber numberWithFloat:0.0]]; //3
    	[redA addObject:[NSNumber numberWithFloat:0.0]]; //5
    	[redA addObject:[NSNumber numberWithFloat:0.0]]; //6
    	[redA addObject:[NSNumber numberWithFloat:0.2]]; //7
    	[redA addObject:[NSNumber numberWithFloat:1.0]]; //8
    	
    	greenA = [[NSMutableArray new] retain];
    	[greenA addObject:[NSNumber numberWithFloat:0.0]]; //1
    	[greenA addObject:[NSNumber numberWithFloat:0.368627450980392]]; //1
    	[greenA addObject:[NSNumber numberWithFloat:0.5]]; //2
    	[greenA addObject:[NSNumber numberWithFloat:1.0]]; //3
    	[greenA addObject:[NSNumber numberWithFloat:1.0]]; //5
    	[greenA addObject:[NSNumber numberWithFloat:0.0]]; //6
    	[greenA addObject:[NSNumber numberWithFloat:0.0]]; //7
    	[greenA addObject:[NSNumber numberWithFloat:0.0]]; //8
    	
    	blueA = [[NSMutableArray new] retain];
    	[blueA addObject:[NSNumber numberWithFloat:0.0]]; //1
    	[blueA addObject:[NSNumber numberWithFloat:0.0]]; //1
    	[blueA addObject:[NSNumber numberWithFloat:0.0]]; //2
    	[blueA addObject:[NSNumber numberWithFloat:0.0]]; //3
    	[blueA addObject:[NSNumber numberWithFloat:1.0]]; //5
    	[blueA addObject:[NSNumber numberWithFloat:1.0]]; //6
    	[blueA addObject:[NSNumber numberWithFloat:0.5]]; //7
    	[blueA addObject:[NSNumber numberWithFloat:0.615686274509804]]; //8
    	
    	opacityA = [[NSMutableArray new] retain];
    	[opacityA addObject:[NSNumber numberWithFloat:0.5]]; //1
    	[opacityA addObject:[NSNumber numberWithFloat:0.4]]; //1 
    	[opacityA addObject:[NSNumber numberWithFloat:1.0]]; //2
    	[opacityA addObject:[NSNumber numberWithFloat:0.5]]; //3
    	[opacityA addObject:[NSNumber numberWithFloat:0.5]]; //5
    	[opacityA addObject:[NSNumber numberWithFloat:0.5]]; //6
    	[opacityA addObject:[NSNumber numberWithFloat:1.0]]; //7
    	[opacityA addObject:[NSNumber numberWithFloat:0.5]]; //8
    
    
    There is a small part of my code

    Thanks in advance
  2. Gamma

    Gamma Active Member

    Joined:
    Apr 2, 2008
    Messages:
    1,964
    Likes Received:
    3
    Device:
    iPod touch
    Black is #000000 in standard RGB codes. I don't know anything about iPhone programming, so I can't check your code
  3. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    [UIColor colorWithRed:0 green:0 blue:0 alpha:1]
  4. eric_chaos

    eric_chaos Well-Known Member

    Joined:
    Nov 4, 2007
    Messages:
    3,746
    Likes Received:
    35
    Device:
    iPhone 4 (Black)
    #000000 is hex. RGB would be 0,0,0
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    As stated black us red:0, green:0, blue:0, alpha:anything.

    What's bothering me is how you're setting up these arrays. I mean, it techincally works fine, but it's not the best way to go about setting them up.

    First of all, each time your code oases through that code, you're increasing retain counts on your arrays. If you release elsewhere, then fine. Ideally, you would use, instead of what you have:
    Code:
    NSMutableArray *redValue = [[NSMutableArray alloc] init];  
    
    /* later */
    [redValue removeAllObjects];
    [redValue addObjects:yourFirstNumber, yourSecondNumber, /* etc */ nil];
    
    Of course, given the platform we're working on, I wouldn't bother wasting the memory on NSMutableArrays/NSNumbers or the cycles it takes to fill them out.

    Instead, you'd be much, *much* better off using a standard float array.
    Code:
    float redValues[15] = {0.0, 0.33, 0.66, /* etc */ };
    /*. later in your code. */
    someColor = [UIColor colorWithRed:redValue[x] green:greenValue[x] blue:blueValue[x] alpha:alphaValue[x]];
    
    ...or whatever you're using those components for. I chose 15 because, if I'm not mistaken, there are 15 standard UIColors.


    Typed out on my phone. Please excuse any typos.
  6. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Hey, I was out of town. Thanks for all the help guys. And especially you Skylar, I will make it a float array, because you're right, it would be less memory demanding, and more efficient.

    Please Register or Log in to view images

Share This Page