Browse Source

Draw a pink square

master
isthisnagee 4 months ago
commit
d2305d09e1
2 changed files with 53 additions and 0 deletions
  1. 16
    0
      sections.nimble
  2. 37
    0
      src/sections.nim

+ 16
- 0
sections.nimble View File

@@ -0,0 +1,16 @@
# Package

version = "0.1.0"
author = "isthisnagee"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"
bin = @["sections"]



# Dependencies

requires "nim >= 1.0.2"
requires "cairo >= 0.1.1"
requires "https://isthisgit.dev/isthisnagee/colorutils.git"

+ 37
- 0
src/sections.nim View File

@@ -0,0 +1,37 @@
import times, cairo, strformat, colorutil

const
HEIGHT = 1048
WIDTH = 1048
type
Point = object
x: range[0.0..WIDTH.toFloat]
y: range[0.0..HEIGHT.toFloat]
# Shape = seq[Point]
Square = object
origin: Point
scale: float

proc newSquare(x: float, y: float, scale: float): Square =
result = Square(origin: Point(x: x, y: y), scale: scale)

proc draw(ctx: ptr Context, square: Square, color: HSL) =
let
rgb = color.toRGB
origin = square.origin
scale = square.scale
ctx.setSourceRGB(rgb.r, rgb.g, rgb.b)
ctx.rectangle(origin.x, origin.y, scale, scale)
ctx.fill()


when isMainModule:
var
surface = imageSurfaceCreate(FORMAT_ARGB32, 256, 256)
ctx = surface.create()

ctx.draw(newSquare(0.0, 0.0, WIDTH.toFloat), cPink)

let t = format(now(), "yyyy-mm-dd-hh-mm-ss")
discard surface.writeToPng(&"out/{t}.png")
discard surface.writeToPng("out/sample.png")

Loading…
Cancel
Save