beef331 / website

Code for the official Nim programming language website
https://nim-lang.org
18 stars 1 forks source link

Drawim #29

Closed GabrielLasso closed 2 years ago

GabrielLasso commented 3 years ago

Name: Drawim

Author: Gabriel Lasso

Posting: A drawing library in Nim, inspired by p5js. Builds to native, using OpenGL, and to JavaScript, using HTML5 Canvas.

It allows you to create simulations, visualize structures, make 2D plots and even prototype 2D games with an easy and intuitive synax.

Example to draw a recursive tree:

import drawim, std/math

proc branch(len: int) =
  if (len < 1):
    return
  line(0, 0, 0, len)

  push()
  translate(0, len)
  rotate(PI / 5)
  branch(int(float(len)*0.7))
  pop()

  push()
  translate(0, len)
  rotate(-PI / 5)
  branch(int(float(len)*0.7))
  pop()

proc draw() =
  background(200)
  stroke(30, 150, 15)
  translate(int(width / 2), height)
  rotate(PI)

  branch(100)

run(600, 400, draw)

Result: Captura de tela de 2021-09-13 21-55-41

More examples:

beef331 commented 3 years ago

Worth noting you don't have jscanvas, opengl, staticGflw pinned to a version in your nimble which can result in problems.

GabrielLasso commented 2 years ago

Worth noting you don't have jscanvas, opengl, staticGflw pinned to a version in your nimble which can result in problems.

Thanks, I fixed the versions in the nimble file