size(200, 200)
background(0)
val maxDistance: Float = dist(width/2, height/2, width, height)
val distances = Vector.tabulate(width, height){ case (i, j) =>
dist(width/2, height/2, j, i)/maxDistance * 255
}
for (i <- 0 until(height, 2) ; j <- 0 until(width, 2)) {
stroke(distances(j)(i))
point(j, i)
}
To me, that's a lot better than the original Java. Less clutter, more higher-level constructs. Even in this simple example, the Scala code does a better job of showing the intentions rather than the specifics of the algorithm.
background(0)
val maxDistance: Float = dist(width/2, height/2, width, height)
val distances = Vector.tabulate(width, height){ case (i, j) =>
dist(width/2, height/2, j, i)/maxDistance * 255
}
for (i <- 0 until(height, 2) ; j <- 0 until(width, 2)) {
stroke(distances(j)(i))
point(j, i)
}
hmmmm ... strangely arousing.
ReplyDelete; )
Well, yes.
ReplyDeletesize.
(it doesn't matter, except when it matters.)
maximum distance, width, height
case of I and J (Joo? You?) leads to...
width, height, width/2, height/2, wi--
0 until height, 0 until width, nothing left outside
stroke; distances of J and I
point: teleia: convergence: meeting: merging: climax: setting one pixel alight
J and I
But seriously, code *is* somewhat arousing. ;)
(The output of this particular code can be seen here (SFW): http://processing.org/learning/basics/array2d.html)