Merge pull request #6 from hundredrabbits/master

sync
This commit is contained in:
Nikolaus Gradwohl 2019-07-21 12:17:58 +02:00 committed by GitHub
commit c07f6552ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 1335 additions and 56 deletions

View File

@ -97,6 +97,7 @@ Additional functions can be found in the [includes](https://github.com/hundredra
- `(js)` Javascript interop.
- `(test name a b)`
- `(benchmark fn)` logs time taken to execute a function.
- `(osc ~address)` returns the last received osc msg on port 12940
## Extras

View File

@ -1,6 +1,7 @@
const { app, BrowserWindow, webFrame, Menu } = require('electron')
const path = require('path')
const url = require('url')
const osc = require('osc')
const shell = require('electron').shell
let isShown = true

1262
desktop/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
"main": "main.js",
"scripts": {
"start": "electron .",
"install": "electron-rebuild",
"clean": "rm -r ~/Desktop/Ronin-darwin-x64/ ; rm -r ~/Desktop/Ronin-linux-x64/ ; rm -r ~/Desktop/Ronin-win32-x64/ ; echo 'cleaned build location'",
"build_osx": "electron-packager . Ronin --platform=darwin --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.icns ; echo 'Built for OSX'",
"build_linux": "electron-packager . Ronin --platform=linux --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.ico ; echo 'Built for LINUX'",
@ -16,8 +17,12 @@
"push_status": "~/butler status hundredrabbits/ronin",
"push": "npm run build ; npm run push_theme ; npm run push_osx ; npm run push_linux ; npm run push_win ; npm run clean ; npm run push_status"
},
"dependencies": {
"osc": "^2.3.1"
},
"devDependencies": {
"electron": "^5.0.6",
"electron-packager": "^13.1.1"
"electron-packager": "^13.1.1",
"electron-rebuild": "^1.8.5"
}
}

View File

@ -9,6 +9,8 @@
<script type="text/javascript" src="scripts/surface.js"></script>
<script type="text/javascript" src="scripts/lisp.js"></script>
<script type="text/javascript" src="scripts/library.js"></script>
<script type="text/javascript" src="scripts/osc.js"></script>
<link rel="stylesheet" type="text/css" href="links/reset.css"/>
<link rel="stylesheet" type="text/css" href="links/fonts.css"/>
<link rel="stylesheet" type="text/css" href="links/main.css"/>

View File

@ -33,6 +33,7 @@ function Commander (ronin) {
this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
ronin.surface.maximize()
ronin.interpreter.run(txt)
ronin.always === true && requestAnimationFrame(() => this.run(txt))
}
@ -71,7 +72,7 @@ function Commander (ronin) {
// Logs
if (msg && msg !== this._log.textContent) {
this._log.textContent = `${msg}`
console.log(msg)
// console.log(msg)
}
// Source
const _source = `${ronin.source} ${this._input.value.split('\n').length} lines`

View File

@ -7,7 +7,7 @@ function Library (ronin) {
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(format, quality)
const dataUrl = ronin.surface.el.toDataURL(format, quality)
const data = dataUrl.replace(/^data:image\/png;base64,/, '').replace(/^data:image\/jpeg;base64,/, '')
fs.writeFileSync(path, data, 'base64')
return path
@ -31,8 +31,8 @@ function Library (ronin) {
return { x, y, w, h, t }
}
this.circle = (x, y, r, t = 'circle') => { // Returns a circle shape.
return { x, y, r, t }
this.circle = (cx, cy, r, t = 'circle') => { // Returns a circle shape.
return { cx, cy, r, t }
}
this.line = (a, b, t = 'line') => { // Returns a line shape.
@ -345,6 +345,16 @@ function Library (ronin) {
return args
}
this.table = (arg) => {
console.table(arg)
return arg
}
this.log = (arg) => {
console.log(arg)
return arg
}
this.time = (rate = 1) => { // Returns timestamp in milliseconds.
return (Date.now() * rate)
}
@ -372,4 +382,10 @@ function Library (ronin) {
console.log(`time taken: ${Date.now() - start}ms`)
return result
}
// IO
this.osc = (path) => { // Returns the latest osc message at path
return path ? ronin.osc.msg[path] : ronin.osc.msg
}
}

View File

@ -1,7 +1,6 @@
'use strict'
function Lisp (lib = {}, includes = []) {
console.log(includes)
const path = require('path')
const fs = require('fs')

View File

@ -0,0 +1,23 @@
'use strict'
function Osc (ronin) {
const osc = require('osc')
this.msg = {}
this.start = function () {
const udpPort = new osc.UDPPort({
localAddress: '0.0.0.0',
localPort: 49162,
metadata: true
})
udpPort.on('message', this.onMsg)
udpPort.open()
ronin.log('OSC','Started.')
}
this.onMsg = (msg, timeTag, info) => {
this.msg[msg.address] = msg.args
// ronin.log(`${info.address}:${info.port} > ${msg.args}`, info)
}
}

View File

@ -22,7 +22,7 @@ function Ronin () {
this.surface = new Surface(this)
this.library = new Library(this)
this.interpreter = new Lisp(this.library, this.includes)
this.osc = new Osc(this)
// Parameters
this.always = false
@ -46,7 +46,7 @@ function Ronin () {
this.source.start()
this.commander.start()
this.surface.start()
console.log('Ronin', 'Started')
this.osc.start()
}
this.reset = function () {

View File

@ -100,7 +100,7 @@ function Surface (ronin) {
}
this.traceCircle = function (circle, context) {
context.arc(circle.x, circle.y, circle.r, 0, 2 * Math.PI)
context.arc(circle.cx, circle.cy, circle.r, 0, 2 * Math.PI)
}
this.traceText = function (text, context) {

1
examples/orca.lisp Normal file
View File

@ -0,0 +1 @@
(log (of (osc "/a") 0 "value"))

11
examples/osc.lisp Normal file
View File

@ -0,0 +1,11 @@
(clear)
(def x (of (osc "/test") "args" "0" "value"))
(def y (of (osc "/test") "args" "1" "value"))
(def r (of (osc "/test") "args" "2" "value"))
(fill
(circle x y r)
"red")
(stroke
(circle x y r)
5 "white")

51
examples/stars.lisp Normal file
View File

@ -0,0 +1,51 @@
; stars
(clear)
;
(defn deg-rad
(deg)
(mul deg
(div PI 180)))
;
(defn circle-pos
(cx cy r a) {:x
(add cx
(mul r
(cos a))) :y
(add cy
(mul r
(sin a)))})
;
(defn draw-spoke
(cx cy r a)
(
(stroke
(line
(pos cx cy)
(circle-pos cx cy r a)) 2 "white")))
;
(defn draw-star
(cx cy r c)
(
(times c
(λ
(i)
(
(draw-spoke cx cy r
(deg-rad
(mul i
(div 360 c)))))))))
; main
(times 100
(λ
()
(
(draw-star
(random 100
(of
(frame) :w))
(random 100
(of
(frame) :h))
(random 10 100)
(floor
(random 3 32))))))