Moved things around a bit
This commit is contained in:
parent
bf17394bc4
commit
5b9819b84f
40
README.md
40
README.md
@ -19,10 +19,18 @@ npm start
|
|||||||
|
|
||||||
## Library
|
## Library
|
||||||
|
|
||||||
- `(open path)`
|
- `(import path rect)` Imports a graphic file with format.
|
||||||
- `(export path type quality)`
|
- `(export path format quality)` Exports a graphic file with format.
|
||||||
- `(folder path)` Returns the content of a folder path.
|
- `(pos x y t)` Returns a position shape.
|
||||||
- `(exit force)` Exits Ronin/
|
- `(size w h t)` Returns a size shape.
|
||||||
|
- `(rect x y w h t)` Returns a rect shape.
|
||||||
|
- `(circle x y r t)` Returns a circle shape.
|
||||||
|
- `(line a b t)` Returns a line shape.
|
||||||
|
- `(text x y g s f t)` Returns a text shape.
|
||||||
|
- `(svg d t)` Returns a svg shape.
|
||||||
|
- `(stroke shape)` Strokes a shape.
|
||||||
|
- `(fill rect)` Fills a shape.
|
||||||
|
- `(clear rect)` Clears a rect.
|
||||||
- `(add ...args)` Adds values.
|
- `(add ...args)` Adds values.
|
||||||
- `(sub ...args)` Subtracts values.
|
- `(sub ...args)` Subtracts values.
|
||||||
- `(mul ...args)` Multiplies values.
|
- `(mul ...args)` Multiplies values.
|
||||||
@ -52,38 +60,30 @@ npm start
|
|||||||
- `(last arr)` Returns the last
|
- `(last arr)` Returns the last
|
||||||
- `(rest [_ ...arr])`
|
- `(rest [_ ...arr])`
|
||||||
- `(range start end step)`
|
- `(range start end step)`
|
||||||
- `(pos x y t)` Returns a position shape.
|
- `(get item key)` Gets an object's parameter with name.
|
||||||
- `(size w h t)` Returns a size shape.
|
- `(set item key val)` Sets an object's parameter with name as value.
|
||||||
- `(rect x y w h t)` Returns a rect shape.
|
|
||||||
- `(circle x y r t)` Returns a circle shape.
|
|
||||||
- `(line a b t)` Returns a line shape.
|
|
||||||
- `(text x y g s f t)` Returns a text shape.
|
|
||||||
- `(svg d t)` Returns a svg shape.
|
|
||||||
- `(frame)` Returns a rect of the frame.
|
- `(frame)` Returns a rect of the frame.
|
||||||
- `(center)` Returns a position of the center of the frame.
|
- `(center)` Returns a position of the center of the frame.
|
||||||
- `(scale rect w h)`
|
- `(scale rect w h)`
|
||||||
|
- `(resize w h)`
|
||||||
|
- `(crop rect)`
|
||||||
- `(clone a b)`
|
- `(clone a b)`
|
||||||
- `(stroke shape)` Strokes a shape.
|
|
||||||
- `(fill rect)` Fills a shape.
|
|
||||||
- `(clear rect)` Clears a rect.
|
|
||||||
- `(get item key)` Gets an object's parameter with name.
|
|
||||||
- `(set item key val)` Sets an object's parameter with name as value.
|
|
||||||
- `(of h ...keys)`
|
- `(of h ...keys)`
|
||||||
- `(theme variable el)`
|
- `(theme variable el)`
|
||||||
- `(gradient [x1 y1 x2 y2] colors 'black'])`
|
- `(gradient [x1 y1 x2 y2] colors 'black'])`
|
||||||
- `(draw path rect)`
|
|
||||||
- `(pixels rect fn q)`
|
- `(pixels rect fn q)`
|
||||||
- `(saturation pixel q)`
|
- `(saturation pixel q)`
|
||||||
- `(contrast pixel q)`
|
- `(contrast pixel q)`
|
||||||
- `(resize w h)`
|
|
||||||
- `(crop rect)`
|
|
||||||
- `(echo ...args)`
|
- `(echo ...args)`
|
||||||
- `(str ...args)`
|
- `(str ...args)`
|
||||||
- `(test name a b)`
|
- `(open path)` Imports a graphic file and resizes the frame.
|
||||||
|
- `(folder path)` Returns the content of a folder path.
|
||||||
|
- `(exit force)` Exits Ronin.
|
||||||
- `(ronin)`
|
- `(ronin)`
|
||||||
- `(time)` Returns timestamp in milliseconds.
|
- `(time)` Returns timestamp in milliseconds.
|
||||||
- `(animate play)` Toggles animation.
|
- `(animate play)` Toggles animation.
|
||||||
- `(js)`
|
- `(js)`
|
||||||
|
- `(test name a b)`
|
||||||
|
|
||||||
## Extras
|
## Extras
|
||||||
|
|
||||||
|
@ -1,22 +1,63 @@
|
|||||||
function Library (ronin) {
|
function Library (ronin) {
|
||||||
this.open = async (path) => {
|
this.import = async (path, rect) => { // Imports a graphic file with format.
|
||||||
return ronin.surface.open(path)
|
const img = new Image()
|
||||||
|
img.src = path
|
||||||
|
return ronin.surface.draw(img, rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.export = (path, type = 'image/png', quality = 1.0) => {
|
this.export = (path, format = 'image/png', quality = 1.0) => { // Exports a graphic file with format.
|
||||||
if (!path) { console.warn('Missing export path'); return path }
|
if (!path) { console.warn('Missing export path'); return path }
|
||||||
var dataUrl = ronin.surface.el.toDataURL(type, quality)
|
var dataUrl = ronin.surface.el.toDataURL(format, quality)
|
||||||
const data = dataUrl.replace(/^data:image\/png;base64,/, '')
|
const data = dataUrl.replace(/^data:image\/png;base64,/, '')
|
||||||
fs.writeFileSync(path, data, 'base64')
|
fs.writeFileSync(path, data, 'base64')
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
this.folder = (path = ronin.source.path) => { // Returns the content of a folder path.
|
// Shapes
|
||||||
return fs.existsSync(path) ? fs.readdirSync(path) : []
|
|
||||||
|
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
|
||||||
|
return { x, y, t }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.exit = (force = false) => { // Exits Ronin/
|
this.size = (w, h, t = 'size') => { // Returns a size shape.
|
||||||
ronin.source.quit(force)
|
return { w, h, t }
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rect = (x, y, w, h, t = 'rect') => { // Returns a rect shape.
|
||||||
|
return { x, y, w, h, t }
|
||||||
|
}
|
||||||
|
|
||||||
|
this.circle = (x, y, r, t = 'circle') => { // Returns a circle shape.
|
||||||
|
return { x, y, r, t }
|
||||||
|
}
|
||||||
|
|
||||||
|
this.line = (a, b, t = 'line') => { // Returns a line shape.
|
||||||
|
return { a, b, t }
|
||||||
|
}
|
||||||
|
|
||||||
|
this.text = (x, y, g, s, f = 'Arial', t = 'text') => { // Returns a text shape.
|
||||||
|
return { x, y, g, s, f, t }
|
||||||
|
}
|
||||||
|
|
||||||
|
this.svg = (d, t = 'svg') => { // Returns a svg shape.
|
||||||
|
return { d, t }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
this.stroke = (shape = this.frame(), thickness, color) => { // Strokes a shape.
|
||||||
|
ronin.surface.stroke(shape, thickness, color)
|
||||||
|
return shape
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fill = (rect = this.frame(), color) => { // Fills a shape.
|
||||||
|
ronin.surface.fill(rect, color)
|
||||||
|
return rect
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clear = (rect = this.frame()) => { // Clears a rect.
|
||||||
|
ronin.surface.clear(rect)
|
||||||
|
return rect
|
||||||
}
|
}
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
@ -160,37 +201,18 @@ function Library (ronin) {
|
|||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shapes
|
// Objects
|
||||||
|
|
||||||
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
|
this.get = (item, key) => { // Gets an object's parameter with name.
|
||||||
return { x, y, t }
|
return item[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.size = (w, h, t = 'size') => { // Returns a size shape.
|
this.set = (item, key, val) => { // Sets an object's parameter with name as value.
|
||||||
return { w, h, t }
|
item[key] = val
|
||||||
|
return item[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rect = (x, y, w, h, t = 'rect') => { // Returns a rect shape.
|
// Frame
|
||||||
return { x, y, w, h, t }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.circle = (x, y, r, t = 'circle') => { // Returns a circle shape.
|
|
||||||
return { x, y, r, t }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.line = (a, b, t = 'line') => { // Returns a line shape.
|
|
||||||
return { a, b, t }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.text = (x, y, g, s, f = 'Arial', t = 'text') => { // Returns a text shape.
|
|
||||||
return { x, y, g, s, f, t }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.svg = (d, t = 'svg') => { // Returns a svg shape.
|
|
||||||
return { d, t }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
|
|
||||||
this.frame = () => { // Returns a rect of the frame.
|
this.frame = () => { // Returns a rect of the frame.
|
||||||
return ronin.surface.getFrame()
|
return ronin.surface.getFrame()
|
||||||
@ -205,6 +227,20 @@ function Library (ronin) {
|
|||||||
return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h }
|
return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.resize = async (w = 1, h = 1) => {
|
||||||
|
const rect = w <= 1 || h <= 1 ? { x: 0, y: 0, w: this.frame().w * w, h: this.frame().h * h } : { x: 0, y: 0, w, h }
|
||||||
|
const a = document.createElement('img')
|
||||||
|
const b = document.createElement('img')
|
||||||
|
a.src = ronin.surface.el.toDataURL()
|
||||||
|
ronin.surface.resizeImage(a, b)
|
||||||
|
ronin.surface.resize(rect, true)
|
||||||
|
return ronin.surface.draw(b, rect)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.crop = async (rect) => {
|
||||||
|
return ronin.surface.crop(rect)
|
||||||
|
}
|
||||||
|
|
||||||
// Copy/Paste
|
// Copy/Paste
|
||||||
|
|
||||||
this.clone = (a, b) => {
|
this.clone = (a, b) => {
|
||||||
@ -212,30 +248,6 @@ function Library (ronin) {
|
|||||||
return [a, b]
|
return [a, b]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stroke = (shape = this.frame(), thickness, color) => { // Strokes a shape.
|
|
||||||
ronin.surface.stroke(shape, thickness, color)
|
|
||||||
return shape
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fill = (rect = this.frame(), color) => { // Fills a shape.
|
|
||||||
ronin.surface.fill(rect, color)
|
|
||||||
return rect
|
|
||||||
}
|
|
||||||
|
|
||||||
this.clear = (rect = this.frame()) => { // Clears a rect.
|
|
||||||
ronin.surface.clear(rect)
|
|
||||||
return rect
|
|
||||||
}
|
|
||||||
|
|
||||||
this.get = (item, key) => { // Gets an object's parameter with name.
|
|
||||||
return item[key]
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set = (item, key, val) => { // Sets an object's parameter with name as value.
|
|
||||||
item[key] = val
|
|
||||||
return item[key]
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Should remove (of) for (get)?
|
// TODO: Should remove (of) for (get)?
|
||||||
|
|
||||||
this.of = (h, ...keys) => {
|
this.of = (h, ...keys) => {
|
||||||
@ -257,12 +269,6 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// Pixels
|
// Pixels
|
||||||
|
|
||||||
this.draw = async (path, rect) => {
|
|
||||||
const img = new Image()
|
|
||||||
img.src = path
|
|
||||||
return ronin.surface.draw(img, rect)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pixels = (rect, fn, q) => {
|
this.pixels = (rect, fn, q) => {
|
||||||
const img = ronin.surface.context.getImageData(0, 0, rect.w, rect.h)
|
const img = ronin.surface.context.getImageData(0, 0, 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) {
|
||||||
@ -287,23 +293,7 @@ function Library (ronin) {
|
|||||||
return [pixel.r * q + intercept, pixel.g * q + intercept, pixel.b * q + intercept, pixel.a]
|
return [pixel.r * q + intercept, pixel.g * q + intercept, pixel.b * q + intercept, pixel.a]
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// Misc
|
||||||
|
|
||||||
this.resize = async (w = 1, h = 1) => {
|
|
||||||
const rect = w <= 1 || h <= 1 ? { x: 0, y: 0, w: this.frame().w * w, h: this.frame().h * h } : { x: 0, y: 0, w, h }
|
|
||||||
const a = document.createElement('img')
|
|
||||||
const b = document.createElement('img')
|
|
||||||
a.src = ronin.surface.el.toDataURL()
|
|
||||||
ronin.surface.resizeImage(a, b)
|
|
||||||
ronin.surface.resize(rect, true)
|
|
||||||
return ronin.surface.draw(b, rect)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.crop = async (rect) => {
|
|
||||||
return ronin.surface.crop(rect)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generics
|
|
||||||
|
|
||||||
this.echo = (...args) => {
|
this.echo = (...args) => {
|
||||||
ronin.log(args)
|
ronin.log(args)
|
||||||
@ -314,13 +304,16 @@ function Library (ronin) {
|
|||||||
return args.reduce((acc, val) => { return acc + val }, '')
|
return args.reduce((acc, val) => { return acc + val }, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.test = (name, a, b) => {
|
this.open = async (path) => { // Imports a graphic file and resizes the frame.
|
||||||
if (`${a}` !== `${b}`) {
|
return ronin.surface.open(path)
|
||||||
console.warn('failed ' + name, a, b)
|
|
||||||
} else {
|
|
||||||
console.log('passed ' + name, a)
|
|
||||||
}
|
}
|
||||||
return a === b
|
|
||||||
|
this.folder = (path = ronin.source.path) => { // Returns the content of a folder path.
|
||||||
|
return fs.existsSync(path) ? fs.readdirSync(path) : []
|
||||||
|
}
|
||||||
|
|
||||||
|
this.exit = (force = false) => { // Exits Ronin.
|
||||||
|
ronin.source.quit(force)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
@ -337,4 +330,13 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// javascript interop
|
// javascript interop
|
||||||
this.js = window
|
this.js = window
|
||||||
|
|
||||||
|
this.test = (name, a, b) => {
|
||||||
|
if (`${a}` !== `${b}`) {
|
||||||
|
console.warn('failed ' + name, a, b)
|
||||||
|
} else {
|
||||||
|
console.log('passed ' + name, a)
|
||||||
|
}
|
||||||
|
return a === b
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user