Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/circle2circle.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var
a: Circle
Expand All @@ -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()
4 changes: 2 additions & 2 deletions examples/circle2line.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma
var
c: Circle
l: Line
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions examples/circle2rect.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var
a: Circle
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions examples/circle2seg.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma
var
a: Circle
s: Segment
Expand All @@ -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")
Expand Down
25 changes: 23 additions & 2 deletions examples/common.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
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)
path.closePath()
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)
4 changes: 2 additions & 2 deletions examples/convexhull.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions examples/hull2hull.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma, random, common
import bumpy, pixie/demo, vmath, chroma, random

var
hull1: seq[Vec2]
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions examples/line2line.nim
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/line2poly.nim
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion examples/line2rect.nim
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion examples/line2seg.nim
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
6 changes: 3 additions & 3 deletions examples/point2circle.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var
a: Vec2
Expand All @@ -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()
4 changes: 2 additions & 2 deletions examples/point2line.nim
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions examples/point2point.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var a, b: Vec2
b.x = 300
Expand All @@ -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()
4 changes: 2 additions & 2 deletions examples/point2rect.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var
a: Vec2
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions examples/point2seg.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var
a: Vec2
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/poly2circle.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion examples/poly2point.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion examples/rect2rect.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bumpy, pixie/demo, vmath, chroma
import bumpy, common, pixie/demo, vmath, chroma

var
a: Rect
Expand Down
6 changes: 6 additions & 0 deletions examples/run.bat
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/tri2point.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down