From dda6cd262c020869d2f0235f2d9030607e8c0b13 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sat, 9 Oct 2021 16:34:57 -0500 Subject: [PATCH] update examples to use current pixie --- examples/circle2circle.nim | 6 +++--- examples/circle2line.nim | 4 ++-- examples/circle2rect.nim | 4 ++-- examples/circle2seg.nim | 4 ++-- examples/common.nim | 25 +++++++++++++++++++++++-- examples/convexhull.nim | 4 ++-- examples/hull2hull.nim | 6 +++--- examples/line2line.nim | 5 +++-- examples/line2poly.nim | 2 +- examples/line2rect.nim | 2 +- examples/line2seg.nim | 2 +- examples/point2circle.nim | 6 +++--- examples/point2line.nim | 4 ++-- examples/point2point.nim | 6 +++--- examples/point2rect.nim | 4 ++-- examples/point2seg.nim | 4 ++-- examples/poly2circle.nim | 2 +- examples/poly2point.nim | 2 +- examples/rect2rect.nim | 2 +- examples/run.bat | 6 ++++++ examples/tri2point.nim | 2 +- 21 files changed, 65 insertions(+), 37 deletions(-) diff --git a/examples/circle2circle.nim b/examples/circle2circle.nim index a9131eb..aeec47a 100644 --- a/examples/circle2circle.nim +++ b/examples/circle2circle.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Circle @@ -14,12 +14,12 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a.pos = getMousePos() - screen.fillCircle(a.pos, a.radius, parseHtmlColor("#2ecc71")) + screen.fillCircle(a, parseHtmlColor("#2ecc71")) var color = if overlaps(a, b): parseHtmlColor("#e74c3c") else: parseHtmlColor("#3498db") color.a = 0.75 - screen.fillCircle(b.pos, b.radius, color) + screen.fillCircle(b, color) tick() diff --git a/examples/circle2line.nim b/examples/circle2line.nim index 84dc2dc..2fba85b 100644 --- a/examples/circle2line.nim +++ b/examples/circle2line.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var c: Circle l: Line @@ -14,7 +14,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) c.pos = getMousePos() - screen.fillCircle(c.pos, c.radius, parseHtmlColor("#2ecc71")) + screen.fillCircle(c, parseHtmlColor("#2ecc71")) var color = if overlaps(c, l): parseHtmlColor("#e74c3c") diff --git a/examples/circle2rect.nim b/examples/circle2rect.nim index 9e6968f..ea327e4 100644 --- a/examples/circle2rect.nim +++ b/examples/circle2rect.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Circle @@ -15,7 +15,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a.pos = getMousePos() - screen.fillCircle(a.pos, a.radius, parseHtmlColor("#2ecc71")) + screen.fillCircle(a, parseHtmlColor("#2ecc71")) var color = if overlaps(a, b): parseHtmlColor("#e74c3c") diff --git a/examples/circle2seg.nim b/examples/circle2seg.nim index 3276c7f..5c346db 100644 --- a/examples/circle2seg.nim +++ b/examples/circle2seg.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Circle s: Segment @@ -14,7 +14,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a.pos = getMousePos() - screen.fillCircle(a.pos, a.radius, parseHtmlColor("#2ecc71")) + screen.fillCircle(a, parseHtmlColor("#2ecc71")) var color = if overlaps(a, s): parseHtmlColor("#e74c3c") diff --git a/examples/common.nim b/examples/common.nim index 403c681..3ce1464 100644 --- a/examples/common.nim +++ b/examples/common.nim @@ -1,7 +1,7 @@ import pixie proc fillPoly*(image: Image, poly: seq[Vec2], color: SomeColor) = - var path: Path + let path = newPath() path.moveTo(poly[0]) for p in poly[1..^1]: path.lineTo(p) @@ -9,9 +9,30 @@ proc fillPoly*(image: Image, poly: seq[Vec2], color: SomeColor) = image.fillPath(path, color) proc strokePoly*(image: Image, poly: seq[Vec2], color: SomeColor) = - var path: Path + let path = newPath() path.moveTo(poly[0]) for p in poly[1..^1]: path.lineTo(p) path.closePath() image.strokePath(path, color) + +proc fillRect*(image: Image, rect: Rect, color: SomeColor) = + let p = newPath() + p.rect(rect) + image.fillPath(p, color) + +proc fillCircle*(image: Image, circle: Circle, color: SomeColor) = + let p = newPath() + p.circle(circle) + image.fillPath(p, color) + +proc strokeCircle*(image: Image, circle: Circle, color: SomeColor) = + let p = newPath() + p.circle(circle) + image.fillPath(p, color) + +proc strokeSegment*(image: Image, segment: Segment, color: SomeColor) = + let p = newPath() + p.moveTo(segment.at) + p.lineTo(segment.to) + image.strokePath(p, color) diff --git a/examples/convexhull.nim b/examples/convexhull.nim index d0db92a..c7839d5 100644 --- a/examples/convexhull.nim +++ b/examples/convexhull.nim @@ -31,7 +31,7 @@ while true: inc i for p in points: - screen.strokeCircle(p, 5, parseHtmlColor("#2ecc71")) + screen.strokeCircle(circle(p, 5), parseHtmlColor("#2ecc71")) if isKeyDown(KEY_SPACE): gen() @@ -42,7 +42,7 @@ while true: if p.dist(getMousePos()) < 6: dragging = i if dragging != -1: - screen.fillCircle(points[dragging], 7, parseHtmlColor("#2ecc71")) + screen.fillCircle(circle(points[dragging], 7), parseHtmlColor("#2ecc71")) points[dragging] = getMousePos() hull = convexHull(points) else: diff --git a/examples/hull2hull.nim b/examples/hull2hull.nim index 429e113..140e94f 100644 --- a/examples/hull2hull.nim +++ b/examples/hull2hull.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma, random, common +import bumpy, pixie/demo, vmath, chroma, random var hull1: seq[Vec2] @@ -59,7 +59,7 @@ while true: var at: Vec2 if a.intersects(b, at): ctx.strokeStyle = rgba(255, 0, 0, 255) - ctx.strokeCircle(at, 3) + ctx.strokeCircle(circle(at, 3)) let normalA = a.convexHullNormal ctx.strokeStyle = rgba(255, 0, 0, 255) ctx.strokeSegment(segment(at, at + normalA*40)) @@ -77,7 +77,7 @@ while true: normA /= numA.float32 normB /= numA.float32 ctx.strokeStyle = rgba(255, 0, 0, 255) - ctx.strokeCircle(avgA, 5) + ctx.strokeCircle(circle(avgA, 5)) ctx.strokeStyle = rgba(255, 0, 0, 255) ctx.strokeSegment(segment(avgA, avgA + normA*80)) ctx.strokeStyle = rgba(0, 255, 0, 255) diff --git a/examples/line2line.nim b/examples/line2line.nim index f170512..1264378 100644 --- a/examples/line2line.nim +++ b/examples/line2line.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma # The lines always overlap unless you get them to be perfectly parallel. @@ -11,12 +11,13 @@ a.a.y = 100 b.a.x = 0 b.a.y = 400 -b.b.x = screen.width.float32 b.b.y = 600 start() while true: + b.b.x = screen.width.float32 + screen.fill(rgba(255, 255, 255, 255)) if getMousePos().x > 300: diff --git a/examples/line2poly.nim b/examples/line2poly.nim index bd3bfbf..b0ad9e3 100644 --- a/examples/line2poly.nim +++ b/examples/line2poly.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma, common +import bumpy, common, pixie/demo, vmath, chroma, common # The lines always overlap unless you get them to be perfectly parallel. diff --git a/examples/line2rect.nim b/examples/line2rect.nim index 91c16ee..fcf1aad 100644 --- a/examples/line2rect.nim +++ b/examples/line2rect.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma # The lines always overlap unless you get them to be perfectly parallel. diff --git a/examples/line2seg.nim b/examples/line2seg.nim index e2ed966..2ac878f 100644 --- a/examples/line2seg.nim +++ b/examples/line2seg.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma # The lines always overlap unless you get them to be perfectly parallel. diff --git a/examples/point2circle.nim b/examples/point2circle.nim index 82d0bea..44e1028 100644 --- a/examples/point2circle.nim +++ b/examples/point2circle.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Vec2 @@ -13,12 +13,12 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a = getMousePos() - screen.strokeCircle(a, 10, parseHtmlColor("#2ecc71")) + screen.strokeCircle(circle(a, 10), parseHtmlColor("#2ecc71")) var color = if overlaps(a, b): parseHtmlColor("#e74c3c") else: parseHtmlColor("#3498db") color.a = 0.75 - screen.fillCircle(b.pos, b.radius, color) + screen.fillCircle(b, color) tick() diff --git a/examples/point2line.nim b/examples/point2line.nim index 2aba8a8..72bc8f7 100644 --- a/examples/point2line.nim +++ b/examples/point2line.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma # The lines always overlap unless you get them to be perfectly parallel. @@ -17,7 +17,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) p = getMousePos() - screen.strokeCircle(p, 10, parseHtmlColor("#2ecc71")) + screen.strokeCircle(circle(p, 10), parseHtmlColor("#2ecc71")) let color = if overlaps(l, p, fudge = 1.5): diff --git a/examples/point2point.nim b/examples/point2point.nim index 94f6eb8..4aa2ff0 100644 --- a/examples/point2point.nim +++ b/examples/point2point.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a, b: Vec2 b.x = 300 @@ -10,12 +10,12 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a = getMousePos() - screen.strokeCircle(a, 10, parseHtmlColor("#2ecc71")) + screen.strokeCircle(circle(a, 10), parseHtmlColor("#2ecc71")) var color = if overlaps(a, b): parseHtmlColor("#e74c3c") else: parseHtmlColor("#3498db") color.a = 0.75 - screen.fillCircle(b, 10, color) + screen.fillCircle(circle(b, 10), color) tick() diff --git a/examples/point2rect.nim b/examples/point2rect.nim index 7d56fae..f48c259 100644 --- a/examples/point2rect.nim +++ b/examples/point2rect.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Vec2 @@ -14,7 +14,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a = getMousePos() - screen.strokeCircle(a, 10, parseHtmlColor("#2ecc71")) + screen.strokeCircle(circle(a, 10), parseHtmlColor("#2ecc71")) var color = if overlaps(a, b): parseHtmlColor("#e74c3c") diff --git a/examples/point2seg.nim b/examples/point2seg.nim index 802ffc7..14dfe09 100644 --- a/examples/point2seg.nim +++ b/examples/point2seg.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Vec2 @@ -14,7 +14,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) a = getMousePos() - screen.strokeCircle(a, 10, parseHtmlColor("#2ecc71")) + screen.strokeCircle(circle(a, 10), parseHtmlColor("#2ecc71")) var color = if overlaps(a, s): parseHtmlColor("#e74c3c") diff --git a/examples/poly2circle.nim b/examples/poly2circle.nim index add7280..badc761 100644 --- a/examples/poly2circle.nim +++ b/examples/poly2circle.nim @@ -16,7 +16,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) circle.pos = getMousePos() - screen.fillCircle(circle.pos, circle.radius, parseHtmlColor("#2ecc71")) + screen.fillCircle(circle, parseHtmlColor("#2ecc71")) var color = if overlaps(poly, circle): diff --git a/examples/poly2point.nim b/examples/poly2point.nim index 93db515..00eb674 100644 --- a/examples/poly2point.nim +++ b/examples/poly2point.nim @@ -15,7 +15,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) point = getMousePos() - screen.fillCircle(point, 10, parseHtmlColor("#2ecc71")) + screen.fillCircle(circle(point, 10), parseHtmlColor("#2ecc71")) var color = if overlaps(poly, point): diff --git a/examples/rect2rect.nim b/examples/rect2rect.nim index eae4349..a5205cf 100644 --- a/examples/rect2rect.nim +++ b/examples/rect2rect.nim @@ -1,4 +1,4 @@ -import bumpy, pixie/demo, vmath, chroma +import bumpy, common, pixie/demo, vmath, chroma var a: Rect diff --git a/examples/run.bat b/examples/run.bat index 84257ad..8eee39c 100644 --- a/examples/run.bat +++ b/examples/run.bat @@ -1,10 +1,16 @@ nim c -r circle2circle.nim +nim c -r circle2line.nim nim c -r circle2rect.nim nim c -r circle2seg.nim +nim c -r convexhull.nim +nim c -r hull2hull.nom nim c -r line2line.nim +nim c -r line2poly.nim +nim c -r line2rect.nim nim c -r line2seg.nim nim c -r point2circle.nim +nim c -r point2line.nim nim c -r point2point.nim nim c -r point2rect.nim nim c -r point2seg.nim diff --git a/examples/tri2point.nim b/examples/tri2point.nim index b6f0cb4..4742e78 100644 --- a/examples/tri2point.nim +++ b/examples/tri2point.nim @@ -14,7 +14,7 @@ while true: screen.fill(rgba(255, 255, 255, 255)) point = getMousePos() - screen.fillCircle(point, 10, parseHtmlColor("#2ecc71")) + screen.fillCircle(circle(point, 10), parseHtmlColor("#2ecc71")) var color = if overlaps(tri, point):