Code Sketch


kavya bhimashankar konale
By: Mhalsakant School
Category: Art
// Clear the canvas and set a dark background
clear()
drawStage(ColorMaker.black)

// Create a Picture representing the box face
val boxPic = Picture {
  setPenColor(ColorMaker.cyan)
  setFillColor(ColorMaker.blue)
  repeat(4) {
    forward(120)
    right(90)
  }
}

// Center the box on the stage
val cb = canvasBounds
boxPic.setPosition(cb.x + cb.width / 2 - 60, cb.y + cb.height / 2 - 60)
draw(boxPic)

// Animation loop to simulate a rotating 3D box effect
var angle = 0.0
animate {
  boxPic.rotate(1)
  
  // Corrected: Passing only a single argument to setScale
  val scaleFactor = math.abs(math.cos(math.toRadians(angle)))
  boxPic.setScale(scaleFactor max 0.1)
  
  angle = (angle + 2) % 360
}