Moved things around a bit

This commit is contained in:
Devine Lu Linvega 2019-07-18 09:28:03 +09:00
parent bf17394bc4
commit 5b9819b84f
2 changed files with 111 additions and 109 deletions

View File

@ -19,10 +19,18 @@ npm start
## Library
- `(open path)`
- `(export path type quality)`
- `(folder path)` Returns the content of a folder path.
- `(exit force)` Exits Ronin/
- `(import path rect)` Imports a graphic file with format.
- `(export path format quality)` Exports a graphic file with format.
- `(pos x y t)` Returns a position shape.
- `(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.
- `(sub ...args)` Subtracts values.
- `(mul ...args)` Multiplies values.
@ -52,38 +60,30 @@ npm start
- `(last arr)` Returns the last
- `(rest [_ ...arr])`
- `(range start end step)`
- `(pos x y t)` Returns a position shape.
- `(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.
- `(get item key)` Gets an object's parameter with name.
- `(set item key val)` Sets an object's parameter with name as value.
- `(frame)` Returns a rect of the frame.
- `(center)` Returns a position of the center of the frame.
- `(scale rect w h)`
- `(resize w h)`
- `(crop rect)`
- `(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)`
- `(theme variable el)`
- `(gradient [x1 y1 x2 y2] colors 'black'])`
- `(draw path rect)`
- `(pixels rect fn q)`
- `(saturation pixel q)`
- `(contrast pixel q)`
- `(resize w h)`
- `(crop rect)`
- `(echo ...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)`
- `(time)` Returns timestamp in milliseconds.
- `(animate play)` Toggles animation.
- `(js)`
- `(test name a b)`
## Extras

View File

@ -1,22 +1,63 @@
function Library (ronin) {
this.open = async (path) => {
return ronin.surface.open(path)
this.import = async (path, rect) => { // Imports a graphic file with format.
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 }
var dataUrl = ronin.surface.el.toDataURL(type, quality)
var dataUrl = ronin.surface.el.toDataURL(format, quality)
const data = dataUrl.replace(/^data:image\/png;base64,/, '')
fs.writeFileSync(path, data, 'base64')
return path
}
this.folder = (path = ronin.source.path) => { // Returns the content of a folder path.
return fs.existsSync(path) ? fs.readdirSync(path) : []
// Shapes
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
return { x, y, t }
}
this.exit = (force = false) => { // Exits Ronin/
ronin.source.quit(force)
this.size = (w, h, t = 'size') => { // Returns a size shape.
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
@ -160,37 +201,18 @@ function Library (ronin) {
return arr
}
// Shapes
// Objects
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
return { x, y, t }
this.get = (item, key) => { // Gets an object's parameter with name.
return item[key]
}
this.size = (w, h, t = 'size') => { // Returns a size shape.
return { w, h, t }
this.set = (item, key, val) => { // Sets an object's parameter with name as value.
item[key] = val
return item[key]
}
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 }
}
// Helpers
// Frame
this.frame = () => { // Returns a rect of the frame.
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 }
}
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
this.clone = (a, b) => {
@ -212,30 +248,6 @@ function Library (ronin) {
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)?
this.of = (h, ...keys) => {
@ -257,12 +269,6 @@ function Library (ronin) {
// Pixels
this.draw = async (path, rect) => {
const img = new Image()
img.src = path
return ronin.surface.draw(img, rect)
}
this.pixels = (rect, fn, q) => {
const img = ronin.surface.context.getImageData(0, 0, rect.w, rect.h)
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]
}
//
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
// Misc
this.echo = (...args) => {
ronin.log(args)
@ -314,13 +304,16 @@ function Library (ronin) {
return args.reduce((acc, val) => { return acc + val }, '')
}
this.test = (name, a, b) => {
if (`${a}` !== `${b}`) {
console.warn('failed ' + name, a, b)
} else {
console.log('passed ' + name, a)
this.open = async (path) => { // Imports a graphic file and resizes the frame.
return ronin.surface.open(path)
}
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
@ -337,4 +330,13 @@ function Library (ronin) {
// javascript interop
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
}
}