Commit ea398396 authored by h2b's avatar h2b

Colors added.

parent 9f7a956d
......@@ -18,8 +18,20 @@
package de.h2b.scala.lib.simgraf.shapes
import de.h2b.scala.lib.simgraf.{ Point, World }
import de.h2b.scala.lib.simgraf.ColorIterator
/**
* A bar chart as shape.
*
* Each bar is displayed in a different color ''excluding'' the active color.
*
* @constructor
*
* @param heights sequence of bar heights
*
* @param enc enclosing for this chart; defaults to the full world if not
* explicitly or otherwise implicitly given
*
* @since 1.4.0
* @author h2b
*/
......@@ -37,10 +49,14 @@ case class BarChart (val heights: Double*)
val (wl, wr, wb, wt) = enc.lrbt(w)
val barWidth = (wr-wl)/heights.size
var x = wl
val activeColor = w.activeColor
val colorIterator = ColorIterator(activeColor)
for (h heights) {
w.activeColor = colorIterator.next()
f(Point(x, wb), Point(x+barWidth, h))
x += barWidth
}
w.activeColor = activeColor
}
}
......@@ -42,14 +42,14 @@ object ChartDemo extends App {
{
val world = newDefaultWorld("Bar Chart Drawed")
world.clear(Color.Black)
world.activeColor = Color.Red
world.activeColor = Color.Black
world.draw(BarChart(30, 60, 20, 80, 50))
}
{
val world = newDefaultWorld("Bar Chart Filled")
world.clear(Color.Black)
world.activeColor = Color.Red
world.activeColor = Color.Black
world.fill(BarChart(30, 60, 20, 80, 50))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment