// Color Cube
// This is a color cube centered about the origin. It is used to help determine orientation in the scene.

// Set units
@settings(defaultLengthUnit = mm, kclVersion = 1.0)

// Parameters referenced in drawRectangle
size = 100
halfSize = size / 2
extrudeLength = 1.0
metalConstant = 50
roughnessConstant = 50

// Create planes for 6 sides of a cube
bluePlane = offsetPlane(XY, offset = halfSize)
yellowPlane = offsetPlane(XY, offset = -halfSize)
greenPlane = offsetPlane(XZ, offset = -halfSize)
purplePlane = offsetPlane(-XZ, offset = -halfSize)
redPlane = offsetPlane(YZ, offset = halfSize - extrudeLength)
tealPlane = offsetPlane(YZ, offset = -halfSize)

// Sketch a rectangle centered at the origin of the profile
fn sketchRectangle(profile, color) {
  return profile
    |> startProfile(at = [-halfSize, halfSize])
    |> angledLine(angle = 0, length = size, tag = $rectangleSegmentA001)
    |> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = size, tag = $rectangleSegmentB001)
    |> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)
    |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
    |> close()
    |> extrude(length = extrudeLength)
    |> appearance(color = color, metalness = metalConstant, roughness = roughnessConstant)
}

// Sketch each side of the cube
sketchRectangle(profile = bluePlane, color = '#0000FF')
sketchRectangle(profile = yellowPlane, color = '#FFFF00')
sketchRectangle(profile = greenPlane, color = '#00FF00')
sketchRectangle(profile = redPlane, color = '#FF0000')
sketchRectangle(profile = tealPlane, color = '#00FFFF')
sketchRectangle(profile = purplePlane, color = '#FF00FF')
