Fixed issue with pixels

This commit is contained in:
Devine Lu Linvega 2019-07-24 10:09:21 +09:00
parent a1af04063b
commit d78a610d80
4 changed files with 20 additions and 17 deletions

View File

@ -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)`

View File

@ -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
}

View File

@ -1,7 +1,8 @@
; pixels
(clear)
(import "../../PREVIEW.jpg"
(frame))
; drag an image on the window
(open $path)
;
(pixels
(rect 0 0 500 500) saturation 0.5)
(rect 100 100 400 400) saturation 0)
(pixels
(rect 300 300 400 400) contrast 0.5)