From d78a610d8021ab2537edd1f130026a8f511acabc Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 24 Jul 2019 10:09:21 +0900 Subject: [PATCH] Fixed issue with pixels --- README.md | 8 ++++++-- desktop/sources/scripts/library.js | 16 +++++++--------- .../transform.lisp => demo/branch.lisp} | 0 examples/pixels/pixels.lisp | 13 +++++++------ 4 files changed, 20 insertions(+), 17 deletions(-) rename examples/{archives/transform.lisp => demo/branch.lisp} (100%) diff --git a/README.md b/README.md index d8fe07d..096b4d6 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Additional functions can be found in the [includes](https://github.com/hundredra - `(circle cx cy r)` Returns a circle shape. - `(line a b)` Returns a line shape. - `(text x y p t ~f)` Returns a text shape. -- `(svg d)` Returns a svg shape. +- `(svg x y d)` Returns a svg shape. - `(stroke ~shape)` Strokes a shape. - `(fill ~rect)` Fills a shape. - `(clear ~rect)` Clears a rect. @@ -67,12 +67,16 @@ Additional functions can be found in the [includes](https://github.com/hundredra - `(mod a b)` Returns the modulo of a and b. - `(clamp val min max)` Clamps a value between min and max. - `(step val step)` +- `(floor)` - `(min)` - `(max)` - `(ceil)` -- `(floor)` - `(sin)` - `(cos)` +- `(log)` caclulates on the base of e. +- `(pow a b)` calculates a^b. +- `(sqrt)` calculate the square root. +- `(sq a)` calculate the square. - `(PI)` - `(TWO_PI)` - `(random ...args)` diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 0e6bcee..a32976e 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -153,7 +153,7 @@ function Library (ronin) { // Pixels this.pixels = (rect, fn, q) => { - const img = ronin.surface.context.getImageData(0, 0, rect.w, rect.h) + const img = ronin.surface.context.getImageData(rect.x, rect.y, rect.w, rect.h) for (let i = 0, loop = img.data.length; i < loop; i += 4) { const pixel = { r: img.data[i], g: img.data[i + 1], b: img.data[i + 2], a: img.data[i + 3] } const processed = fn(pixel, q) @@ -162,7 +162,7 @@ function Library (ronin) { img.data[i + 2] = processed[2] img.data[i + 3] = processed[3] } - ronin.surface.context.putImageData(img, 0, 0) + ronin.surface.context.putImageData(img, rect.x, rect.y) return rect } @@ -212,29 +212,27 @@ function Library (ronin) { return Math.round(val / step) * step } - this.floor = Math.floor // round down to the nearest integer - this.min = Math.min this.max = Math.max this.ceil = Math.ceil - this.floor = Math.floor + this.floor = Math.floor // round down to the nearest integer. this.sin = Math.sin this.cos = Math.cos - this.log = Math.log // caclulates on the base of e + this.log = Math.log // caclulates on the base of e. - this.pow = (a, b) => { // calculates a^b + this.pow = (a, b) => { // calculates a^b. return Math.pow(a, b) } - this.sqrt = Math.sqrt // calculate the square root + this.sqrt = Math.sqrt // calculate the square root. - this.sq = (a) => { // calculate the square + this.sq = (a) => { // calculate the square. return a * a } diff --git a/examples/archives/transform.lisp b/examples/demo/branch.lisp similarity index 100% rename from examples/archives/transform.lisp rename to examples/demo/branch.lisp diff --git a/examples/pixels/pixels.lisp b/examples/pixels/pixels.lisp index 761a462..b1cb522 100644 --- a/examples/pixels/pixels.lisp +++ b/examples/pixels/pixels.lisp @@ -1,7 +1,8 @@ -; pixels - -(clear) -(import "../../PREVIEW.jpg" - (frame)) +(clear) +; drag an image on the window +(open $path) +; (pixels - (rect 0 0 500 500) saturation 0.5) \ No newline at end of file + (rect 100 100 400 400) saturation 0) +(pixels + (rect 300 300 400 400) contrast 0.5) \ No newline at end of file