Jump to content

Greyscale bars/Display: Difference between revisions

m (→‎{{header|C}}: simplify)
Line 431:
Press Enter or Escape to exit the programs's display.
 
=={{header|ScalaRunbasic}}==
<lang scalaRunbasic>importfor scala.swing._i = 1 to 4
incr = int(256 / (i * 8))
 
c = 256
class GreyscaleBars extends Component {
html "<table style='width: 200px; height: 11px;' border=0 cellpadding=0 cellspacing=0><tr>"
override def paintComponent(g:Graphics2D)={
for j = 1 to i * 8
val barHeight=size.height>>2
html "<td style='background-color: rgb(";c;",";c;",";c;");'></td>"
for(run <- 0 to 3; colCount=8<<run){
c = c - incr
val deltaX=size.width.toDouble/colCount
next j
val colBase=if (run%2==0) -255 else 0
for(x <- 0html until colCount){"</tr>"
next i
val col=(colBase+(255.0/(colCount-1)*x).toInt).abs
html "</table>"
g.setColor(new Color(col,col,col))
}end</lang>
<pre>Run in a browser</pre>
val startX=(deltaX*x).toInt
val endX=(deltaX*(x+1)).toInt
g.fillRect(startX, barHeight*run, endX-startX, barHeight)
}
}
}
}</lang>
Open window:
[[File:greyscalebars_scala.png|thumb|right]]
<lang scala>new MainFrame(){
title="Greyscale bars"
visible=true
preferredSize=new Dimension(640, 320)
contents=new GreyscaleBars()
}</lang>
 
=={{header|Seed7}}==
23

edits

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