morepretty

This commit is contained in:
Ryan Oldenburg 2021-07-18 16:59:50 -05:00
parent c3e168caa4
commit e5cccb63d1
5 changed files with 49 additions and 52 deletions

View file

@ -2,7 +2,6 @@
import math, pixie, sdl2, sdl2/gfx import math, pixie, sdl2, sdl2/gfx
const const
rmask = uint32 0x000000ff rmask = uint32 0x000000ff
gmask = uint32 0x0000ff00 gmask = uint32 0x0000ff00
@ -23,7 +22,6 @@ var
mainTexture: TexturePtr mainTexture: TexturePtr
evt = sdl2.defaultEvent evt = sdl2.defaultEvent
proc display() = proc display() =
## Called every frame by main while loop ## Called every frame by main while loop
@ -52,7 +50,8 @@ proc display() =
inc frameCount inc frameCount
var dataPtr = ctx.image.data[0].addr var dataPtr = ctx.image.data[0].addr
mainSurface = createRGBSurfaceFrom(dataPtr, cint w, cint h, cint 32, cint 4*w, rmask, gmask, bmask, amask) mainSurface = createRGBSurfaceFrom(dataPtr, cint w, cint h, cint 32, cint 4*w,
rmask, gmask, bmask, amask)
mainTexture = render.createTextureFromSurface(mainSurface) mainTexture = render.createTextureFromSurface(mainSurface)
destroy(mainSurface) destroy(mainSurface)
@ -62,7 +61,6 @@ proc display() =
render.present() render.present()
discard sdl2.init(INIT_EVERYTHING) discard sdl2.init(INIT_EVERYTHING)
window = createWindow("SDL/Pixie", 100, 100, cint w, cint h, SDL_WINDOW_SHOWN) window = createWindow("SDL/Pixie", 100, 100, cint w, cint h, SDL_WINDOW_SHOWN)
render = createRenderer(window, -1, 0) render = createRenderer(window, -1, 0)

View file

@ -1,7 +1,6 @@
## Load and Save SVG files. ## Load and Save SVG files.
import cairo, chroma, pixie/common, pixie/images, strutils, vmath, import cairo, chroma, pixie/common, pixie/images, strutils, vmath, xmlparser, xmltree
xmlparser, xmltree
include pixie/paths include pixie/paths

View file

@ -1,4 +1,4 @@
import blends, bumpy, chroma, common, images, masks, paints, internal, strutils, vmath import blends, bumpy, chroma, common, images, internal, masks, paints, strutils, vmath
when defined(amd64) and not defined(pixieNoSimd): when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2 import nimsimd/sse2

View file

@ -592,7 +592,7 @@ block:
image = newImage(300, 227) image = newImage(300, 227)
ctx = newContext(image) ctx = newContext(image)
rhino = readImage("tests/images/rhino.png") rhino = readImage("tests/images/rhino.png")
ctx.drawImage(rhino, 33, 71, 104, 124, 21, 20, 87, 104); ctx.drawImage(rhino, 33, 71, 104, 124, 21, 20, 87, 104)
image.writeFile("tests/images/context/draw_image_rhino.png") image.writeFile("tests/images/context/draw_image_rhino.png")
block: block:
@ -600,7 +600,7 @@ block:
image = newImage(300, 227) image = newImage(300, 227)
ctx = newContext(image) ctx = newContext(image)
rhino = readImage("tests/images/rhino.png") rhino = readImage("tests/images/rhino.png")
ctx.drawImage(rhino, rect(33, 71, 104, 124), rect(21, 20, 87, 104)); ctx.drawImage(rhino, rect(33, 71, 104, 124), rect(21, 20, 87, 104))
image.writeFile("tests/images/context/draw_image_rhino2.png") image.writeFile("tests/images/context/draw_image_rhino2.png")
block: block:

View file

@ -445,20 +445,20 @@ block:
# Draw shapes # Draw shapes
for i in 0 .. 3: for i in 0 .. 3:
for j in 0 .. 2: for j in 0 .. 2:
ctx.beginPath(); ctx.beginPath()
let x = 25f + j.float32 * 50f; # x coordinate let x = 25f + j.float32 * 50f # x coordinate
let y = 25f + i.float32 * 50f; # y coordinate let y = 25f + i.float32 * 50f # y coordinate
let radius = 20f; # Arc radius let radius = 20f # Arc radius
let startAngle = 0f; # Starting point on circle let startAngle = 0f # Starting point on circle
let endAngle = PI + (PI * j.float32) / 2; # End point on circle let endAngle = PI + (PI * j.float32) / 2 # End point on circle
let counterclockwise = i mod 2 == 1; # Draw counterclockwise let counterclockwise = i mod 2 == 1 # Draw counterclockwise
ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise); ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise)
if i > 1: if i > 1:
ctx.fill(); ctx.fill()
else: else:
ctx.stroke(); ctx.stroke()
surface.writeFile("tests/images/paths/arc.png") surface.writeFile("tests/images/paths/arc.png")
@ -473,10 +473,10 @@ block:
p1 = vec2(90, 130) p1 = vec2(90, 130)
p2 = vec2(20, 20) p2 = vec2(20, 20)
ctx.beginPath(); ctx.beginPath()
ctx.moveTo(p0.x, p0.y); ctx.moveTo(p0.x, p0.y)
ctx.arcTo(p1.x, p1.y, p2.x, p2.y, 50); ctx.arcTo(p1.x, p1.y, p2.x, p2.y, 50)
ctx.lineTo(p2.x, p2.y); ctx.lineTo(p2.x, p2.y)
ctx.stroke() ctx.stroke()
surface.writeFile("tests/images/paths/arcTo1.png") surface.writeFile("tests/images/paths/arcTo1.png")
@ -487,33 +487,33 @@ block:
ctx = newContext(surface) ctx = newContext(surface)
surface.fill(rgba(255, 255, 255, 255)) surface.fill(rgba(255, 255, 255, 255))
# Tangential lines # Tangential lines
ctx.beginPath(); ctx.beginPath()
ctx.strokeStyle = "gray"; ctx.strokeStyle = "gray"
ctx.moveTo(200, 20); ctx.moveTo(200, 20)
ctx.lineTo(200, 130); ctx.lineTo(200, 130)
ctx.lineTo(50, 20); ctx.lineTo(50, 20)
ctx.stroke(); ctx.stroke()
# Arc # Arc
ctx.beginPath(); ctx.beginPath()
ctx.strokeStyle = "black"; ctx.strokeStyle = "black"
ctx.lineWidth = 5; ctx.lineWidth = 5
ctx.moveTo(200, 20); ctx.moveTo(200, 20)
ctx.arcTo(200,130, 50,20, 40); ctx.arcTo(200, 130, 50, 20, 40)
ctx.stroke(); ctx.stroke()
# Start point # Start point
ctx.beginPath(); ctx.beginPath()
ctx.fillStyle = "blue"; ctx.fillStyle = "blue"
ctx.arc(200, 20, 5, 0, 2 * PI); ctx.arc(200, 20, 5, 0, 2 * PI)
ctx.fill(); ctx.fill()
# Control points # Control points
ctx.beginPath(); ctx.beginPath()
ctx.fillStyle = "red"; ctx.fillStyle = "red"
ctx.arc(200, 130, 5, 0, 2 * PI); # Control point one ctx.arc(200, 130, 5, 0, 2 * PI) # Control point one
ctx.arc(50, 20, 5, 0, 2 * PI); # Control point two ctx.arc(50, 20, 5, 0, 2 * PI) # Control point two
ctx.fill(); ctx.fill()
surface.writeFile("tests/images/paths/arcTo2.png") surface.writeFile("tests/images/paths/arcTo2.png")
@ -523,11 +523,11 @@ block:
ctx = newContext(surface) ctx = newContext(surface)
surface.fill(rgba(255, 255, 255, 255)) surface.fill(rgba(255, 255, 255, 255))
ctx.beginPath(); ctx.beginPath()
ctx.moveTo(180, 90); ctx.moveTo(180, 90)
ctx.arcTo(180,130, 110,130, 130); ctx.arcTo(180, 130, 110, 130, 130)
ctx.lineTo(110, 130); ctx.lineTo(110, 130)
ctx.stroke(); ctx.stroke()
surface.writeFile("tests/images/paths/arcTo3.png") surface.writeFile("tests/images/paths/arcTo3.png")