func drawCube() { let cube = UIView() cube.frame.origin.x = 40 cube.frame.origin.y = 500 cube.frame.size.width = 40 cube.frame.size.height = 40 cube.backgroundColor = UIColor.blue view.addSubview(cube) } Function with the original parameters of the cube. Numeric values are not significant, this is just for example. If possible, I would like to understand the main points of the algorithm, so please leave a comment on the function.