iphone - Coloring of a rectangle -
i'm newbie graphics.i'm drawing rectangle change color after 1 second.
- (void)drawrect:(cgrect)rect { [self setwidthheightofrectangle]; [self changecolorofnumbers]; cgcontextref ctx = uigraphicsgetcurrentcontext(); cgcontextclearrect(ctx, rect); // draw solid square cgcontextsetrgbfillcolor(ctx, 255, 255, 255, 1); cgcontextfillrect(ctx, cgrectmake(0.0, 24.0, 380.0, 2.0)); cgcontextsetrgbfillcolor(ctx, rednumber, greennumber, bluenumber, 1); cgcontextfillrect(ctx, frametodraw); }
i'm changing color of rectangle using changecolorofnumbers method. here method
- (void)changecolorofnumbers { ihit++; if (ihit==100) { rednumber=249; greennumber=252; bluenumber=0; } else if (ihit==200) { rednumber=0; greennumber=168; bluenumber=245; } else if (ihit==300) { rednumber=255; greennumber=0; bluenumber=140; } else if (ihit==400) { rednumber=255; greennumber=125; bluenumber=0; } else if (ihit==500) { rednumber=0; greennumber=176; bluenumber=72; } else if (ihit==600) { rednumber=128; greennumber=0; bluenumber=148; } else if (ihit==700) { rednumber=8; greennumber=79; bluenumber=168; } else if (ihit==800) { rednumber=127; greennumber=212; bluenumber=20; } else if (ihit==900) { rednumber=255; greennumber=0; bluenumber=0; } else if (ihit==1) { rednumber=0; greennumber=0; bluenumber=0; frametodraw=cgrectmake(0.0, 0.0, 0.0, 50.0); } else if (ihit==2) { rednumber=255; greennumber=255; bluenumber=255; } }
problem some of rgb colors i'm applying aren't showing up. doing wrong here?.....
thanks...
color components must vary 0 1 - try normalize them dividing on 255.0f;
Comments
Post a Comment