Jump to content

Greyscale bars/Display: Difference between revisions

→‎{{header|Java}}: Adjusted so color component always goes from 0 to 255 or vice versa in each quarter
(→‎{{header|C sharp|C#}}: removing some repetition from c# version)
(→‎{{header|Java}}: Adjusted so color component always goes from 0 to 255 or vice versa in each quarter)
Line 627:
public void paint ( Graphics g ) {
int run = 0 ;
intdouble colorcomp = 0.0 ; //component of the color
for ( int columncount = 8 ; columncount < 128 ; columncount *= 2 ) {
intdouble colorgap = 255.0 / (columncount - 1) ; //by this gap we change the background color
int columnwidth = width / columncount ;
int columnheight = height / 4 ;
if ( run % 2 == 0 ) //switches color directions with every for loop
colorcomp = 0.0 ;
else {
colorcomp = 255.0 ;
colorgap *= -1.0 ;
}
int ystart = 0 + columnheight * run ;
int xstart = 0 ;
for ( int i = 0 ; i < columncount ; i++ ) {
int icolor = (int)Math.round(colorcomp) ; //round to nearer integer
Color nextColor = new Color( colorcompicolor , colorcompicolor, colorcompicolor ) ;
g.setColor( nextColor ) ;
g.fillRect( xstart , ystart , columnwidth , columnheight ) ;
Line 655 ⟶ 656:
}
}</lang>
 
=={{header|JavaScript}}==
Live Demo: http://jsfiddle.net/gcN9g/embedded/result/
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.