Minerva is a 2D renderer written in Swift inspired by p5.js and the CGContext.
In order to be able to render something using Minerva, you need to create a Sketch
.
class YourSketch: Sketch {
override func setup() {
// called ony once
}
override func draw() {
// called every frame
}
}
And then, inside your view or view controller:
addSketch(yourSketch)
And that's it :)
With Minerva you can use different type of "commands", as I call them.
This kind of commands allow you to draw different kinds of shapes.
// ... inside your sketch
override func draw() {
// draw a line from (100, 100) to (200, 200)
line(100, 100, 200, 200)
}
// ... inside your sketch
override func draw() {
// draw a rect at (100, 100) with a width of 50 and height of 30
rect(100, 100, 50, 30)
}
// ... inside your sketch
override func draw() {
// draw triangle at (100, 150), (200, 150) and (150, 50)
triangle(100, 150, 200, 150, 150, 50)
}
// ... inside your sketch
override func draw() {
// set black as the fill color
fill(0, 0, 0)
// draw a black rectangle
rect(0, 0, 100, 300)
}
// ... inside your sketch
// it's not really necessary to set the background color per frame
override func setup() {
// set white as the background color
background(255, 255, 255)
}
This kind of commands allow you to apply some transformations to the current drawing group.
// ... inside your sketch
override func draw() {
// ...
// translates the coordiantes system by 5 in x and 45 in y
translate(5, 45)
}
// ... inside your sketch
override func draw() {
// ...
// rotates the coordiantes system by 45 degrees
rotate(45)
}
// ... inside your sketch
override func draw() {
// Creates a new drawing group with the current transformations and fill color.
push()
}
// ... inside your sketch
override func draw() {
// Restores the last saved drawing group.
pop()
}
// ... inside your sketch
override func draw() {
// Stops the main loop.
loop()
}
// ... inside your sketch
override func draw() {
// Stops the main loop.
noLoop()
}
Inside the demo-ios
project, you will find some examples, such as the following:
Factal Organic Tree |
---|