so my code is:
import UIKit
class CanvasView: UIView { let originX: CGFloat = 150 let originY: CGFloat = 300 let squareSide: CGFloat = 100
var rubiksCubeDelegate: RubiksCubeDelegate? = nil
var fromCol: Int = -1
var fromRow: Int = -1
override func draw(_ rect: CGRect) {
drawFront()
drawTop()
drawRight()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let firstTouch = touches.first!
let fingerLocation = firstTouch.location(in: self)
fromCol = Int((fingerLocation.x - originX) / squareSide)
fromRow = Int((fingerLocation.y - originY) / squareSide)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let firstTouch = touches.first!
let fingerLocation = firstTouch.location(in: self)
let toCol: Int = Int((fingerLocation.x - originX) / squareSide)
let toRow: Int = Int((fingerLocation.y - originY) / squareSide)
print("V: from (\(fromCol), \(fromRow) to (\(toCol), \(toRow))")
rubiksCubeDelegate?.moveFinger(fromCol: fromCol, fromRow: fromRow, toCol: toCol, toRow: toRow)
}
func drawFront() {
drawsquare(col: 0, row: 0, color: .green)
drawsquare(col: 1, row: 0, color: .orange)
drawsquare(col: 2, row: 0, color: .blue)
drawsquare(col: 0, row: 1, color: .white)
drawsquare(col: 1, row: 1, color: .yellow)
drawsquare(col: 2, row: 1, color: .red)
drawsquare(col: 0, row: 2, color: .green)
drawsquare(col: 1, row: 2, color: .blue)
drawsquare(col: 2, row: 2, color: .orange)
}
func drawTop() {
drawTopParallelogram(col: 0, row: 0, color: .red)
drawTopParallelogram(col: 0, row: 1, color: .blue)
drawTopParallelogram(col: 0, row: 2, color: .green)
drawTopParallelogram(col: 1, row: 0, color: .yellow)
drawTopParallelogram(col: 1, row: 1, color: .red)
drawTopParallelogram(col: 1, row: 2, color: .white)
drawTopParallelogram(col: 2, row: 0, color: .blue)
drawTopParallelogram(col: 2, row: 1, color: .orange)
drawTopParallelogram(col: 2, row: 2, color: .green)
}
func drawRight() {
drawRightParallelogram(col: 0, row: 0, color: .orange)
drawRightParallelogram(col: 1, row: 0, color: .red)
drawRightParallelogram(col: 2, row: 0, color: .red)
drawRightParallelogram(col: 0, row: 1, color: .blue)
drawRightParallelogram(col: 1, row: 1, color: .orange)
drawRightParallelogram(col: 2, row: 1, color: .white)
drawRightParallelogram(col: 0, row: 2, color: .white)
drawRightParallelogram(col: 1, row: 2, color: .blue)
drawRightParallelogram(col: 2, row: 2, color: .green)
}
func drawRightParallelogram(col: Int, row: Int,color: CubeColor) {
colorOf(color: color).setFill()
let topLeftX: CGFloat = originX + 3 * squareSide + CGFloat(col) * squareSide/2
let topLeftY: CGFloat = originY - CGFloat(col) * squareSide/2 + CGFloat(row) * squareSide
let path = UIBezierPath()
path.move(to: CGPoint(x: topLeftX, y: topLeftY))
path.addLine(to: CGPoint(x: topLeftX + squareSide/2, y: topLeftY - squareSide/2))
path.addLine(to: CGPoint(x: topLeftX + squareSide/2, y: topLeftY + squareSide/2))
path.addLine(to: CGPoint(x: topLeftX, y: topLeftY + squareSide))
path.close()
path.fill()
path.stroke()
}
func drawTopParallelogram(col: Int, row: Int,color: CubeColor) {
colorOf(color: color).setFill()
let bottomLeftX: CGFloat = originX + CGFloat(col) * squareSide + CGFloat(2 - row) * squareSide/2
let bottomLeftY: CGFloat = originY + CGFloat(row - 2)*squareSide/2
let path = UIBezierPath()
path.move(to: CGPoint(x: bottomLeftX, y: bottomLeftY ))
path.addLine(to: CGPoint(x: bottomLeftX + squareSide/2,y: bottomLeftY - squareSide/2))
path.addLine(to: CGPoint(x: bottomLeftX + squareSide/2 + squareSide, y: bottomLeftY - squareSide/2))
path.addLine(to: CGPoint(x: bottomLeftX + squareSide, y: bottomLeftY))
path.close()
path.fill()
path.stroke()
}
func drawsquare(col: Int, row: Int,color: CubeColor) {
colorOf(color: color).setFill()
let squareX: CGFloat = originX + CGFloat(col) * squareSide
let squareY: CGFloat = originY + CGFloat(row) * squareSide
let square = UIBezierPath(rect: CGRect(x: squareX, y:squareY, width:squareSide, height:squareSide))
square.fill()
square.stroke()
}
func colorOf(color: CubeColor) -> UIColor {
var c: UIColor = .black
switch color {
case .blue:
c = UIColor.blue
case .green:
c = UIColor.green
case .orange:
c = UIColor.orange
case .red:
c = UIColor.red
case .white:
c = UIColor.white
case .yellow:
c = UIColor.yellow
}
return c
}
}
at "func drawFront() {" it said "Thread 1: breakpoint 1.1 (1)"
can any one help me fix this the app is always pausing