Re-implemented (export)

This commit is contained in:
neauoire 2019-11-02 17:11:41 -04:00
parent 707f056649
commit ff934f9f16
7 changed files with 45 additions and 54 deletions

15
404.html Normal file
View File

@ -0,0 +1,15 @@
---
permalink: /404.html
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Loading..</title>
</head>
<body style='background:black'>
<script>
document.location.href = '/index.html'
</script>
</body>
</html>

View File

@ -38,10 +38,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
## Library
- `(import path shape ~alpha)` Imports a graphic file with format.
- `(export path ~format ~quality)` Exports a graphic file with format.
- `(open path ~ratio)` Imports a graphic file and resizes the frame.
- `(exit ~force)` Exits Ronin.
- `(export ~name ~format ~quality)` Exports a graphic file with format.
- `(pos ~x ~y)` Returns a position shape.
- `(line ax ay bx by)` Returns a line shape.
- `(size w h)` Returns a size shape.
@ -126,12 +123,6 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
- `(blur)` Returns the blur kernel.
- `(sharpen)` Returns the sharpen kernel.
- `(edge)` Returns the edge kernel.
- `(dir ~path)` Returns the content of a directory.
- `(file ~path)` Returns the content of a file.
- `(dirpath ~path)` Returns the path of a directory.
- `(filepath ~path)` Returns the path of a file.
- `(dirname ~path)` Returns the name of a folder.
- `(filename ~path)` Returns the name of a file.
- `(offset a b)` Offsets pos a with pos b, returns a.
- `(distance a b)` Get distance between positions.
- `(echo ...args)` Print arguments to interface.
@ -142,6 +133,19 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
- `(test name a b)`
- `(benchmark fn)` Logs time taken to execute a function.
### In Development
- `(import path shape ~alpha)` Imports a graphic file with format.
- `(export path ~format ~quality)` Exports a graphic file with format.
- `(open path ~ratio)` Imports a graphic file and resizes the frame.
- `(exit ~force)` Exits Ronin.
- `(dir ~path)` Returns the content of a directory.
- `(file ~path)` Returns the content of a file.
- `(dirpath ~path)` Returns the path of a directory.
- `(filepath ~path)` Returns the path of a file.
- `(dirname ~path)` Returns the name of a folder.
- `(filename ~path)` Returns the name of a file.
<img src='https://raw.githubusercontent.com/hundredrabbits/Ronin/master/PREVIEW2.jpg' width='600'/>
<img src='https://raw.githubusercontent.com/hundredrabbits/Ronin/master/PREVIEW3.jpg' width='600'/>

View File

@ -10,17 +10,17 @@ function Library (ronin) {
// IO
this.import = async (path, shape, alpha = 1) => { // Imports a graphic file with format.
const img = new Image()
img.src = path
return ronin.surface.draw(img, shape, alpha)
// const img = new Image()
// img.src = path
// return ronin.surface.draw(img, shape, alpha)
}
this.export = (path, quality = 1.0) => { // Exports a graphic file with format.
// if (!path) { console.warn('Missing export path'); return path }
// const dataUrl = ronin.surface.el.toDataURL(path.indexOf('.jpg') > -1 ? 'image/jpeg' : path.indexOf('.png') > -1 ? 'image/png' : format, quality)
// const data = dataUrl.replace(/^data:image\/png;base64,/, '').replace(/^data:image\/jpeg;base64,/, '')
// fs.writeFileSync(path, data, 'base64')
// return path
this.export = (name = 'export', type = 'image/png', quality = 1.0) => { // Exports a graphic file with format.
const base64 = ronin.surface.el.toDataURL(type, quality)
const link = document.createElement('a')
link.setAttribute('href', base64)
link.setAttribute('download', type === 'image/png' ? name + '.png' : name + '.jpg')
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }))
}
this.open = async (path, ratio = 1) => { // Imports a graphic file and resizes the frame.

View File

@ -83,11 +83,7 @@ function Ronin () {
requestAnimationFrame(() => this.loop())
}
this.reset = function () {
this.theme.reset()
}
this.log = function (...msg) {
this.log = (...msg) => {
this.commander.setStatus(msg.reduce((acc, val) => {
return acc + JSON.stringify(val).replace(/"/g, '').trim() + ' '
}, ''))

View File

@ -293,10 +293,11 @@ function Surface (ronin) {
}
this.fitWindow = function (size) {
const win = require('electron').remote.getCurrentWindow()
const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
if (size.w < 10 || size.h < 10) { return }
win.setSize(Math.floor((size.w / this.ratio) + pad.w), Math.floor((size.h / this.ratio) + pad.h), true)
console.log('TODO')
// const win = require('electron').remote.getCurrentWindow()
// const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
// if (size.w < 10 || size.h < 10) { return }
// win.setSize(Math.floor((size.w / this.ratio) + pad.w), Math.floor((size.h / this.ratio) + pad.h), true)
}
this.maximize = () => {

View File

@ -58,12 +58,3 @@
; Interop
(test "interop" ((of (of (js) "Math") "max") 2 4) 4)
(test "recursive key selector" ((of (js) "Math" "max") 2 4) 4)
; fs
; filesystem
(echo (filepath))
(echo (dirpath))
(echo (file))
(echo (dir))

View File

@ -1,16 +0,0 @@
; recursive
(clear)
(defn rec
(v)
(if
(gt v 0)
(
(stroke
(circle
(mul 5 v)
(mul 5 v)
(mul 5 v)) "red" 1)
(rec
(sub v 5)))))
(rec 100)