teaching machines

Triangular Colors

Last week I was trying to think of boolean predicates that I could use for exercises in an introductory programming class. I remembered the triangle inequality, which states how the lengths of three line segments must relate if they are to be formed into a triangle. In short, each segment must be shorter than the other two combined.

I absently connected in my mind the three sides of a triangle to the three components of an RGB color. If I treated the red, green, and blue intensities as the lengths of the three line segments, which colors could make triangles?

This seemed like a job for volume rendering, but my volume renderer is in a state of disrepair. So, I just generated a bunch of slices across the color cube with this Kotlin code:

for (b in 0..255) {
val image = BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB)
for (g in 0..255) {
for (r in 0..255) {
if (r + g > b && r + b > g && b + g > r) {
image.setRGB(r, g, Color(r, g, b).rgb)
}
}
}

val path = String.format("frame%03d.png", b)
ImageIO.write(image, "png", File(path))
}


Red increases along the x-axis, green along the y-axis, and blue along the z-axis. In this animation, I advance along the z-axis, slice by slice:

I think I like the complement better:

But I really think I need to get my volume renderer working again. And maybe write it in Javascript this time.