Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Draw-a-sphere/Swift/draw-a-sphere-1.swift
Normal file
31
Task/Draw-a-sphere/Swift/draw-a-sphere-1.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))
|
||||
13
Task/Draw-a-sphere/Swift/draw-a-sphere-2.swift
Normal file
13
Task/Draw-a-sphere/Swift/draw-a-sphere-2.swift
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
struct ContentView: View {
|
||||
|
||||
var body: some View {
|
||||
|
||||
let gradient = RadialGradient(gradient: Gradient(colors:[.white, .black]),
|
||||
center: .init(x: 0.4, y: 0.4), startRadius: 10, endRadius: 100)
|
||||
|
||||
return Circle()
|
||||
.fill(gradient)
|
||||
.frame(width: 200, height: 200)
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue