mihalis's picture

My Articles for MacTech issue 348

Title for article 1: "The Xcodebuild command line tool".

Title for article 2: "An introduction to Regular Expressions".

Title for article 3: "Introduction to Swift - Part 3".

mihalis's picture

Programming in R

I wrote "Programming in R" for Linux Format magazine, issue 193!

mihalis's picture

I wrote 2 articles for LUD issue 146

I wrote two articles for Linux User & Developer issue 146!

Title 1: "How to Handle UNIX Signals".

Title 2: "3D Rendering with WebGL".

mihalis's picture

An Introduction to Swift (part 1)

I wrote "An Introduction to Swift" for MacTech issue 346!

mihalis's picture

Drawing a circle in Swift using Bezier

The following Swift code produces the image you can see at the end of the post including the error messages.

import UIKit
import Darwin

var x,y: CGFloat
x = 10
y = 10

var point = CGPoint(x:100, y:100)
var radius: CGFloat = 50.0

let context = UIGraphicsGetCurrentContext()
var circle: UIBezierPath = UIBezierPath()
var start: CGPoint = CGPointMake(point.x + radius, point.y)


// It was not working with i=0...
// Do not know why
for (var i=0.0001; i {
let test = CGFloat( i * M_PI/180)
let cosTest = cos(test)
let sinTest = sin(test)

x = (point.x + radius * cosTest)
y = (point.y + radius * sinTest)
circle.addLineToPoint(CGPointMake(x, y))



I do not know if the error messages are because of the fact that I running the code in a Playground.



Subscribe to RSS - Programming