Skip to content

juandahurt/Minerva

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minerva

Minerva is a 2D renderer written in Swift inspired by p5.js and the CGContext.

Sketch

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 :)

Commands

With Minerva you can use different type of "commands", as I call them.

Shape

This kind of commands allow you to draw different kinds of shapes.

Line

// ... inside your sketch
override func draw() {
  // draw a line from (100, 100) to (200, 200)
  line(100, 100, 200, 200)
}
Screenshot 2024-11-06 at 4 03 02 PM

Rect

// ... 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)
}
Screenshot 2024-11-06 at 4 13 37 PM

Triangle

// ... inside your sketch
override func draw() {
  // draw triangle at (100, 150), (200, 150) and (150, 50)
  triangle(100, 150, 200, 150, 150, 50)
}
Screenshot 2024-11-06 at 5 41 13 PM

Color

Fill

// ... 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)
}

background

// ... 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)
}

Transform

This kind of commands allow you to apply some transformations to the current drawing group.

Translate

// ... inside your sketch
override func draw() {
  // ...
  // translates the coordiantes system by 5 in x and 45 in y
  translate(5, 45)
}

Rotate

// ... inside your sketch
override func draw() {
  // ...
  // rotates the coordiantes system by 45 degrees
  rotate(45)
}

Structure

Push

// ... inside your sketch
override func draw() {
  // Creates a new drawing group with the current transformations and fill color.
  push()
}

Pop

// ... inside your sketch
override func draw() {
  // Restores the last saved drawing group.
  pop()
}

Loop

// ... inside your sketch
override func draw() {
  // Stops the main loop.
  loop()
}

No loop

// ... inside your sketch
override func draw() {
  // Stops the main loop.
  noLoop()
}

Examples

Inside the demo-ios project, you will find some examples, such as the following:

Factal Organic Tree