diff --git a/README.md b/README.md index 5472448..488386f 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ var p: Path p.polygon(100, 100, 70, sides=6) p.closePath() -let mask = newImage(200, 200) -mask.fillPath(p, rgba(255, 255, 255, 255)) +let mask = newMask(200, 200) +mask.fillPath(p) blur.blur(20) blur.draw(mask, blendMode = bmMask) @@ -47,12 +47,7 @@ let r = 25.0 var path: Path -path.moveTo(x+r, y) -path.arcTo(x+w, y, x+w, y+h, r) -path.arcTo(x+w, y+h, x, y+h, r) -path.arcTo(x, y+h, x, y, r) -path.arcTo(x, y, x+w, y, r) -path.closePath() +path.roundedRect(vec2(x, y), vec2(w, h), r, r, r, r) image.fillPath(path, rgba(255, 0, 0, 255)) ``` @@ -62,11 +57,7 @@ image.fillPath(path, rgba(255, 0, 0, 255)) [examples/square.nim](examples/square.nim) ```nim var p: Path -p.moveTo(50, 50) -p.lineTo(50, 150) -p.lineTo(150, 150) -p.lineTo(150, 50) -p.closePath() +p.rect(50, 50, 100, 100) image.fillPath(p, rgba(255, 0, 0, 255)) ``` diff --git a/examples/blur.nim b/examples/blur.nim index e3b11f0..aa34a4f 100644 --- a/examples/blur.nim +++ b/examples/blur.nim @@ -11,8 +11,8 @@ var p: Path p.polygon(100, 100, 70, sides=6) p.closePath() -let mask = newImage(200, 200) -mask.fillPath(p, rgba(255, 255, 255, 255)) +let mask = newMask(200, 200) +mask.fillPath(p) blur.blur(20) blur.draw(mask, blendMode = bmMask) diff --git a/examples/blur.png b/examples/blur.png index f350a4f..0f4e20b 100644 Binary files a/examples/blur.png and b/examples/blur.png differ diff --git a/examples/rounded_rectangle.nim b/examples/rounded_rectangle.nim index 63a0d31..164a76b 100644 --- a/examples/rounded_rectangle.nim +++ b/examples/rounded_rectangle.nim @@ -1,4 +1,4 @@ -import pixie, chroma +import pixie, chroma, vmath let image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) @@ -11,12 +11,7 @@ let r = 25.0 var path: Path -path.moveTo(x+r, y) -path.arcTo(x+w, y, x+w, y+h, r) -path.arcTo(x+w, y+h, x, y+h, r) -path.arcTo(x, y+h, x, y, r) -path.arcTo(x, y, x+w, y, r) -path.closePath() +path.roundedRect(vec2(x, y), vec2(w, h), r, r, r, r) image.fillPath(path, rgba(255, 0, 0, 255)) diff --git a/examples/square.nim b/examples/square.nim index 9f17fee..528d3ab 100644 --- a/examples/square.nim +++ b/examples/square.nim @@ -4,11 +4,7 @@ var image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) var p: Path -p.moveTo(50, 50) -p.lineTo(50, 150) -p.lineTo(150, 150) -p.lineTo(150, 50) -p.closePath() +p.rect(50, 50, 100, 100) image.fillPath(p, rgba(255, 0, 0, 255)) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 41cc84f..9d00bd6 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -418,10 +418,13 @@ proc drawCorrect( p = matInv * vec2(0 + h, 0 + h) dx = matInv * vec2(1 + h, 0 + h) - p dy = matInv * vec2(0 + h, 1 + h) - p - while max(dx.length, dy.length) > 2: + minFilterBy2 = max(dx.length, dy.length) + + while minFilterBy2 > 2: b = b.minifyBy2() dx /= 2 dy /= 2 + minFilterBy2 /= 2 matInv = matInv * scale(vec2(0.5, 0.5)) for y in 0 ..< a.height: