AuthorTravis Kirton
Tags color
This example shows how to create colors using red, green, blue values.
let color = Color(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
In C4 (and iOS) color values are measures from 0...1, instead of 0...255
0...1
0...255
var red, green, blue: Shape! override func setup() { setupShapes() setupLabels() red.fillColor = Color(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0) green.fillColor = Color(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0) blue.fillColor = Color(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0) } func setupShapes() { let frame = Rect(0, 0, canvas.width*0.9, canvas.height/5) red = Rectangle(frame: frame) green = Rectangle(frame: frame) blue = Rectangle(frame: frame) red.lineWidth = 0.0 green.lineWidth = 0.0 blue.lineWidth = 0.0 let dy = Vector(x: 0, y: canvas.height/4) red.center = canvas.center - dy green.center = canvas.center blue.center = canvas.center + dy canvas.add(red) canvas.add(green) canvas.add(blue) } func setupLabels() { let f = Font(name: "Helvetica", size: 30.0)! var l = TextShape(text: "{RGBA} : {1.0, 0, 0, 1.0}", font: f)! l.fillColor = white l.center = red.center canvas.add(l) l = TextShape(text: "{RGBA} : {0, 1.0, 0, 1.0}", font: f)! l.fillColor = white l.center = green.center canvas.add(l) l = TextShape(text: "{RGBA} : {0, 0, 1.0, 1.0}", font: f)! l.fillColor = white l.center = blue.center canvas.add(l) }