發表文章

目前顯示的是 3月, 2019的文章

Draw circle in random place

圖片
2 The question is as follows: 1. It is necessary to realize circles on the screen in a random place. 2. Circles must be of different radii and do not overlap each other and do not go beyond the screen. Created a separate file for View. Here is the code: override func draw(_ rect: CGRect) { var number = 1 while number <= 5 { //1. Screen center coordinates let viewMidX = self.bounds.size.height let viewMidY = self.bounds.size.width //2. Circle radius let circleWidth = CGFloat(20 + arc4random_uniform(30)) let circleHeight = circleWidth //3. Two random number let randomNumberOne = CGFloat(arc4random_uniform(40)) let randomNumberTwo = CGFloat(arc4random_uniform(20)) //4. Coordinates and sizes of the circle