Changed the pixels and convolve param order
This commit is contained in:
parent
e0d27dbcb4
commit
550784be54
@ -53,7 +53,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(size w h)` Returns a size shape.
|
- `(size w h)` Returns a size shape.
|
||||||
- `(rect x y w h)` Returns a rect shape.
|
- `(rect x y w h)` Returns a rect shape.
|
||||||
- `(circle cx cy r)` Returns a circle shape.
|
- `(circle cx cy r)` Returns a circle shape.
|
||||||
- `(ellipse cx cy rx ry)` Returns an ellipse shape.
|
- `(ellipse cx cy rx ry)` Returns a ellipse shape.
|
||||||
- `(line ax ay bx by)` Returns a line shape.
|
- `(line ax ay bx by)` Returns a line shape.
|
||||||
- `(text x y p t ~a ~f)` Returns a text shape.
|
- `(text x y p t ~a ~f)` Returns a text shape.
|
||||||
- `(svg x y d)` Returns a svg shape.
|
- `(svg x y d)` Returns a svg shape.
|
||||||
@ -74,9 +74,9 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(clone a b)`
|
- `(clone a b)`
|
||||||
- `(drag ~rect)` Drag a part of the canvas.
|
- `(drag ~rect)` Drag a part of the canvas.
|
||||||
- `(view a b)` View a part of the canvas.
|
- `(view a b)` View a part of the canvas.
|
||||||
- `(pick shape)` Returns the color of a pixel at pos, or of the average of the pixels in rect.
|
- `(pick ~shape)` Returns the color of a pixel at pos, or of the average of the pixels in rect.
|
||||||
- `(theme variable ~el)`
|
- `(theme variable ~el)`
|
||||||
- `(pixels rect fn ~q)`
|
- `(pixels fn ~q ~rect)`
|
||||||
- `(saturation pixel q)` Change the saturation of pixels.
|
- `(saturation pixel q)` Change the saturation of pixels.
|
||||||
- `(contrast pixel q)` Change the contrast of pixels.
|
- `(contrast pixel q)` Change the contrast of pixels.
|
||||||
- `(brightness pixel q)` Change the brightness of pixels.
|
- `(brightness pixel q)` Change the brightness of pixels.
|
||||||
@ -125,7 +125,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(of h ...keys)` Gets object parameters with names.
|
- `(of h ...keys)` Gets object parameters with names.
|
||||||
- `(keys item)` Returns a list of the object's keys
|
- `(keys item)` Returns a list of the object's keys
|
||||||
- `(values item)` Returns a list of the object's values
|
- `(values item)` Returns a list of the object's values
|
||||||
- `(convolve rect kernel)`
|
- `(convolve kernel ~rect)`
|
||||||
- `(blur)`
|
- `(blur)`
|
||||||
- `(sharpen)`
|
- `(sharpen)`
|
||||||
- `(edge)`
|
- `(edge)`
|
||||||
|
15
WORKSHOP.md
15
WORKSHOP.md
@ -145,18 +145,17 @@ First let's open an image, ideally one in color, and change every pixel of a sel
|
|||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
(open $path)
|
(open $path)
|
||||||
(pixels
|
(pixels saturation 10
|
||||||
(rect 100 100 200 200) saturation 10)
|
(rect 100 100 200 200))
|
||||||
```
|
```
|
||||||
|
|
||||||
### saturation
|
### saturation
|
||||||
|
|
||||||
In the previous example, we increased the saturation of a region of the image, to desaturate an entire image, you can first use `(frame)` which will select the entire canvas, and set the pixel filter to `saturation` and the value to `0.5`(50% saturation):
|
In the previous example, we increased the saturation of a region of the image, to desaturate an entire image, you can simply omit the `(frame)` which will select the entire canvas, and set the pixel filter to `saturation` and the value to `0.5`(50% saturation):
|
||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
(open $path)
|
(open $path)
|
||||||
(pixels
|
(pixels saturation 0.5)
|
||||||
(frame) saturation 0.5)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### convolve
|
### convolve
|
||||||
@ -167,8 +166,7 @@ Effects which use the surrounding pixels, or convolution matrix, are used with t
|
|||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
(open $path)
|
(open $path)
|
||||||
(convolve
|
(convolve sharpen $rect)
|
||||||
(frame) sharpen)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Custom convolve kernels can also be created like this:
|
Custom convolve kernels can also be created like this:
|
||||||
@ -180,8 +178,7 @@ Custom convolve kernels can also be created like this:
|
|||||||
(-1 -1 -1)
|
(-1 -1 -1)
|
||||||
(-1 5 -1)
|
(-1 5 -1)
|
||||||
(-1 -1 -1)))
|
(-1 -1 -1)))
|
||||||
(convolve
|
(convolve blur)
|
||||||
(frame) blur)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
@ -22,7 +22,7 @@ app.on('ready', () => {
|
|||||||
webPreferences: { zoomFactor: 1.0, nodeIntegration: true, backgroundThrottling: false }
|
webPreferences: { zoomFactor: 1.0, nodeIntegration: true, backgroundThrottling: false }
|
||||||
})
|
})
|
||||||
|
|
||||||
app.win.webContents.removeAllListeners('devtools-reload-page');
|
app.win.webContents.removeAllListeners('devtools-reload-page')
|
||||||
|
|
||||||
app.win.loadURL(`file://${__dirname}/sources/index.html`)
|
app.win.loadURL(`file://${__dirname}/sources/index.html`)
|
||||||
// app.inspect()
|
// app.inspect()
|
||||||
|
@ -191,7 +191,7 @@ function Library (ronin) {
|
|||||||
ronin.surface.context.drawImage(ronin.surface.getCrop(a), b.x, b.y, b.w, b.h)
|
ronin.surface.context.drawImage(ronin.surface.getCrop(a), b.x, b.y, b.w, b.h)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pick = (shape) => { // Returns the color of a pixel at pos, or of the average of the pixels in rect.
|
this.pick = (shape = this.frame()) => { // Returns the color of a pixel at pos, or of the average of the pixels in rect.
|
||||||
const rect = shape.w && shape.h ? shape : this.rect(shape.x, shape.y, 1, 1)
|
const rect = shape.w && shape.h ? shape : this.rect(shape.x, shape.y, 1, 1)
|
||||||
const img = ronin.surface.context.getImageData(rect.x, rect.y, rect.w, rect.h)
|
const img = ronin.surface.context.getImageData(rect.x, rect.y, rect.w, rect.h)
|
||||||
const sum = [0, 0, 0]
|
const sum = [0, 0, 0]
|
||||||
@ -211,7 +211,7 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// Pixels
|
// Pixels
|
||||||
|
|
||||||
this.pixels = (rect, fn, q = 1) => {
|
this.pixels = (fn, q = 1, rect = this.frame()) => {
|
||||||
if (!fn) { console.warn('Unknown function'); return rect }
|
if (!fn) { console.warn('Unknown function'); return rect }
|
||||||
const img = ronin.surface.context.getImageData(rect.x, rect.y, 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) {
|
for (let i = 0, loop = img.data.length; i < loop; i += 4) {
|
||||||
@ -382,7 +382,7 @@ function Library (ronin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.map = (arr, fn) => { // Run a function on each element in a list.
|
this.map = (arr, fn) => { // Run a function on each element in a list.
|
||||||
return Promise.all(arr.map(fn)).then( result => { return result } )
|
return Promise.all(arr.map(fn)).then(result => { return result })
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filter = (arr, fn) => { // Remove from list, when function returns false.
|
this.filter = (arr, fn) => { // Remove from list, when function returns false.
|
||||||
@ -465,7 +465,7 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// Convolve
|
// Convolve
|
||||||
|
|
||||||
this.convolve = (rect, kernel) => {
|
this.convolve = (kernel, rect = this.frame()) => {
|
||||||
const sigma = kernel.flat().reduce((a, x) => (a + x))
|
const sigma = kernel.flat().reduce((a, x) => (a + x))
|
||||||
const kw = kernel[0].length; const kh = kernel.length
|
const kw = kernel[0].length; const kh = kernel.length
|
||||||
const img = ronin.surface.context.getImageData(rect.x, rect.y, rect.w, rect.h)
|
const img = ronin.surface.context.getImageData(rect.x, rect.y, rect.w, rect.h)
|
||||||
|
@ -3,7 +3,7 @@ function Surface (ronin) {
|
|||||||
this.el.id = 'surface'
|
this.el.id = 'surface'
|
||||||
this._guide = document.createElement('canvas')
|
this._guide = document.createElement('canvas')
|
||||||
this._guide.id = 'guide'
|
this._guide.id = 'guide'
|
||||||
this._guide.setAttribute('tabindex', '1'); // focus is necessary to capture keyboard events
|
this._guide.setAttribute('tabindex', '1') // focus is necessary to capture keyboard events
|
||||||
this.ratio = window.devicePixelRatio
|
this.ratio = window.devicePixelRatio
|
||||||
// Contexts
|
// Contexts
|
||||||
this.context = this.el.getContext('2d')
|
this.context = this.el.getContext('2d')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user