Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
31
Task/Draw-a-sphere/Swift/draw-a-sphere.swift
Normal file
31
Task/Draw-a-sphere/Swift/draw-a-sphere.swift
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
class Sphere: UIView{
|
||||
|
||||
override func drawRect(rect: CGRect)
|
||||
{
|
||||
let context = UIGraphicsGetCurrentContext()
|
||||
let locations: [CGFloat] = [0.0, 1.0]
|
||||
|
||||
let colors = [UIColor.whiteColor().CGColor,
|
||||
UIColor.blueColor().CGColor]
|
||||
|
||||
let colorspace = CGColorSpaceCreateDeviceRGB()
|
||||
|
||||
let gradient = CGGradientCreateWithColors(colorspace,
|
||||
colors, locations)
|
||||
|
||||
var startPoint = CGPoint()
|
||||
var endPoint = CGPoint()
|
||||
startPoint.x = self.center.x - (self.frame.width * 0.1)
|
||||
startPoint.y = self.center.y - (self.frame.width * 0.15)
|
||||
endPoint.x = self.center.x
|
||||
endPoint.y = self.center.y
|
||||
let startRadius: CGFloat = 0
|
||||
let endRadius: CGFloat = self.frame.width * 0.38
|
||||
|
||||
CGContextDrawRadialGradient (context, gradient, startPoint,
|
||||
startRadius, endPoint, endRadius,
|
||||
0)
|
||||
}
|
||||
}
|
||||
|
||||
var s = Sphere(frame: CGRectMake(0, 0, 200, 200))
|
||||
Loading…
Add table
Add a link
Reference in a new issue