import io.data2viz.color.*
import io.data2viz.geom.*
import io.data2viz.math.*
import io.data2viz.viz.*
import io.data2viz.scale.*
import io.data2viz.random.*
fun main() {
val gridSize = 8
val numWidth = 6
val numHeight = 5
val rectSize = 8.0
val total = numWidth*numHeight*gridSize*gridSize
val colorScale = ScalesChromatic.Continuous.linearLAB()
var randAngle = RandomDistribution.uniform(.0, 360.0)
val allAngles = (0..total).map {
randAngle().deg
}.toMutableList()
val allColors = allAngles.map {
Colors.hsl(it, 100.pct, 50.pct)
}
var offset = 0
val viz = viz {
size = size(numWidth*gridSize*rectSize, numHeight*gridSize*rectSize)
rect {
width = gridSize * numWidth.toDouble()
height = gridSize * numHeight.toDouble()
fill = Colors.Web.gray
}
val rects = (0 until numWidth).map { gridX ->
val xLine = gridX * gridSize
(0 until numHeight).map { gridY ->
val yLine = gridY * gridSize
(0 until gridSize).map { pointX ->
val xPos = xLine + pointX
(0 until gridSize).map { pointY ->
val yPos = yLine + pointY
rect {
x = rectSize * xPos
y = rectSize * yPos
width = rectSize
height = rectSize
fill = allColors[xPos + (yPos*gridSize*numWidth)]
}
}
}.flatten()
}.flatten()
}.flatten()
animation {
offset++
rects.forEachIndexed { index, rect ->
rect.fill = allColors[(index+offset)%total]
}
}
}
viz.bindRendererOnNewCanvas()
// randAngle = RandomDistribution.uniform(100.0, 360.0)
// allAngles = (0..numWidth*numHeight*gridSize*gridSize).map { randAngle().deg }
// viz.render()
// randAngle = RandomDistribution.uniform(200.0, 360.0)
// allAngles = (0..numWidth*numHeight*gridSize*gridSize).map { randAngle().deg }
// viz.render()
// randAngle = RandomDistribution.uniform(300.0, 360.0)
// allAngles = (0..numWidth*numHeight*gridSize*gridSize).map { randAngle().deg }
// viz.render()
}
comments