Greyscale bars/Display: Difference between revisions
Content added Content deleted
m (Restore Scala. Several edits by [[Special:Contributions/Meerkat|Meerkat) |
|||
Line 431: | Line 431: | ||
Press Enter or Escape to exit the programs's display. |
Press Enter or Escape to exit the programs's display. |
||
=={{header| |
=={{header|Run BASIC}}== |
||
<lang Runbasic>for i = 1 to 4 |
<lang Runbasic>for i = 1 to 4 |
||
incr = int(256 / (i * 8)) |
incr = int(256 / (i * 8)) |
||
Line 445: | Line 445: | ||
end</lang> |
end</lang> |
||
<pre>Run in a browser</pre> |
<pre>Run in a browser</pre> |
||
=={{header|Scala}}== |
|||
<lang scala>import scala.swing._ |
|||
class GreyscaleBars extends Component { |
|||
override def paintComponent(g:Graphics2D)={ |
|||
val barHeight=size.height>>2 |
|||
for(run <- 0 to 3; colCount=8<<run){ |
|||
val deltaX=size.width.toDouble/colCount |
|||
val colBase=if (run%2==0) -255 else 0 |
|||
for(x <- 0 until colCount){ |
|||
val col=(colBase+(255.0/(colCount-1)*x).toInt).abs |
|||
g.setColor(new Color(col,col,col)) |
|||
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}}== |
=={{header|Seed7}}== |