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 ;
for ( int columncount = 8 ; columncount < 128 ; columncount *= 2 ) {
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(
g.setColor( nextColor ) ;
g.fillRect( xstart , ystart , columnwidth , columnheight ) ;
Line 655 ⟶ 656:
}
}</lang>
=={{header|JavaScript}}==
Live Demo: http://jsfiddle.net/gcN9g/embedded/result/
|