aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-11-17 13:21:28 +1200
committerDevine Lu Linvega <[email protected]>2018-11-17 13:21:28 +1200
commitceb3be7bca3cbbe6ff08fa4373e2775a0a0a72b6 (patch)
treeb65df5c5e9ee7df90ec2e0e2c43f8d2ed1285fb3
parent85ab1cca1d89ad29783667d395b90fc83bed8d5b (diff)
downloadOrca-ceb3be7bca3cbbe6ff08fa4373e2775a0a0a72b6.tar.gz
Orca-ceb3be7bca3cbbe6ff08fa4373e2775a0a0a72b6.zip
Improving inputs
-rw-r--r--README.md12
-rw-r--r--desktop/core/lib/_base.js17
-rw-r--r--desktop/core/lib/a.js9
-rw-r--r--desktop/core/lib/b.js20
-rw-r--r--desktop/core/lib/c.js9
-rw-r--r--desktop/core/lib/f.js9
-rw-r--r--desktop/core/lib/i.js13
-rw-r--r--desktop/core/lib/l.js11
-rw-r--r--desktop/core/lib/m.js9
-rw-r--r--desktop/core/lib/t.js24
-rw-r--r--desktop/core/lib/x.js18
-rw-r--r--desktop/core/lib/y.js9
-rw-r--r--desktop/core/pico.js1
-rw-r--r--examples/benchmark.pico45
14 files changed, 106 insertions, 100 deletions
diff --git a/README.md b/README.md
index 481cfd6..5214f43 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,18 @@ npm install
npm start
```
+## Ports Specs
+
+```
+Haste < Function > Input(s)
+ v
+ Output
+```
+
+- **Haste port** values are collected before runtime.
+- **Inputs** are collected at normal runtime.
+- **Outputs**.
+
## Notes
- `0x92 & 0xf0 = 144`, Ch3 noteOn
diff --git a/desktop/core/lib/_base.js b/desktop/core/lib/_base.js
index 25a4eea..5e4b45e 100644
--- a/desktop/core/lib/_base.js
+++ b/desktop/core/lib/_base.js
@@ -7,7 +7,7 @@ function FnBase (pico, x, y, glyph = '.', passive = false) {
this.name = 'unknown'
this.glyph = passive ? glyph.toUpperCase() : glyph
this.info = 'Missing docs.'
- this.ports = { inputs: {}, bang: null }
+ this.ports = { input: {}, haste: {}, bang: null }
this.docs = 'Hello!'
if (!passive) {
@@ -27,6 +27,21 @@ function FnBase (pico, x, y, glyph = '.', passive = false) {
pico.add(this.x, this.y + 1, g)
}
+ // Lock Ports
+ this.locks = function () {
+ for (const id in this.ports.haste) {
+ const port = this.ports.haste[id]
+ pico.lock(this.x + port.x, this.y + port.y)
+ }
+ for (const id in this.ports.input) {
+ const port = this.ports.input[id]
+ pico.lock(this.x + port.x, this.y + port.y)
+ }
+ if (this.ports.output) {
+ pico.lock(this.x, this.y + 1)
+ }
+ }
+
this.haste = function () {
}
diff --git a/desktop/core/lib/a.js b/desktop/core/lib/a.js
index ff70bff..589c4f8 100644
--- a/desktop/core/lib/a.js
+++ b/desktop/core/lib/a.js
@@ -8,12 +8,13 @@ function FnA (pico, x, y, passive) {
this.name = 'add'
this.info = 'Creates the result of the addition of east and west fns, southward.'
- this.ports.inputs.a = { x: 1, y: 0 }
- this.ports.inputs.b = { x: 2, y: 0 }
+ this.ports.input.a = { x: 1, y: 0 }
+ this.ports.input.b = { x: 2, y: 0 }
+ this.ports.output = true
this.operation = function () {
- const a = this.listen(this.ports.inputs.a, true)
- const b = this.listen(this.ports.inputs.b, true)
+ const a = this.listen(this.ports.input.a, true)
+ const b = this.listen(this.ports.input.b, true)
const res = this.toChar(a + b)
this.output(`${res}`)
}
diff --git a/desktop/core/lib/b.js b/desktop/core/lib/b.js
index 6a00d5c..511ed2c 100644
--- a/desktop/core/lib/b.js
+++ b/desktop/core/lib/b.js
@@ -5,24 +5,20 @@ const FnBase = require('./_base')
function FnB (pico, x, y, passive) {
FnBase.call(this, pico, x, y, 'b', passive)
- this.name = 'Banger'
+ this.name = 'banger'
this.info = 'Bangs southward in the presence of `1`, `N`, `S`, `W`, `E` or `Z` northward.'
- this.ports = [{ x: -1, y: 0, bang: true }, { x: 0, y: 1, output: true }]
- this.operation = function () {
- const n = this.west()
+ this.ports.input.val = { x: 1, y: 0 }
+ this.ports.output = true
- if (!n) { return }
+ this.operation = function () {
+ const val = this.listen(this.ports.input.val)
+ const chr = ['1', 'w', 's', 'n', 'e', '*']
- if (n.glyph === '1' || n.glyph === 'w' || n.glyph === 's' || n.glyph === 'n' || n.glyph === 'e' || n.glyph === '*' || n.glyph === 'z') {
- this.fire()
+ if (chr.indexOf(val.toLowerCase()) > -1) {
+ this.output('*')
}
}
-
- this.fire = function () {
- pico.add(this.x, this.y + 1, '*')
- pico.lock(this.x, this.y + 1)
- }
}
module.exports = FnB
diff --git a/desktop/core/lib/c.js b/desktop/core/lib/c.js
index fd258c4..ca2dbc4 100644
--- a/desktop/core/lib/c.js
+++ b/desktop/core/lib/c.js
@@ -8,12 +8,13 @@ function FnC (pico, x, y, passive) {
this.name = 'clock'
this.info = 'Adds a constant value southward.'
- this.ports.inputs.min = { x: 1, y: 0 }
- this.ports.inputs.max = { x: 2, y: 0 }
+ this.ports.input.min = { x: 1, y: 0 }
+ this.ports.input.max = { x: 2, y: 0 }
+ this.ports.output = true
this.operation = function () {
- const min = this.listen(this.ports.inputs.min, true)
- const max = this.listen(this.ports.inputs.max, true)
+ const min = this.listen(this.ports.input.min, true)
+ const max = this.listen(this.ports.input.max, true)
const key = (pico.f % max) + min
const res = pico.allowed[key] ? pico.allowed[key] : 0
this.output(`${res}`)
diff --git a/desktop/core/lib/f.js b/desktop/core/lib/f.js
index 1aac6d7..560db9a 100644
--- a/desktop/core/lib/f.js
+++ b/desktop/core/lib/f.js
@@ -8,12 +8,13 @@ function FnF (pico, x, y, passive) {
this.name = 'if'
this.info = 'Bangs if east and west fns are equal, southward.'
- this.ports.inputs.a = { x: 1, y: 0 }
- this.ports.inputs.b = { x: 2, y: 0 }
+ this.ports.input.a = { x: 1, y: 0 }
+ this.ports.input.b = { x: 2, y: 0 }
+ this.ports.output = true
this.operation = function () {
- const a = this.listen(this.ports.inputs.a, true)
- const b = this.listen(this.ports.inputs.b, true)
+ const a = this.listen(this.ports.input.a, true)
+ const b = this.listen(this.ports.input.b, true)
const res = a === b ? '1' : '0'
this.output(`${res}`)
}
diff --git a/desktop/core/lib/i.js b/desktop/core/lib/i.js
index a3e817f..2ae8735 100644
--- a/desktop/core/lib/i.js
+++ b/desktop/core/lib/i.js
@@ -8,14 +8,15 @@ function FnI (pico, x, y, passive) {
this.name = 'increment'
this.info = 'Increments southward numeric fn on bang.'
- this.ports.inputs.min = { x: 1, y: 0 }
- this.ports.inputs.max = { x: 2, y: 0 }
- this.ports.inputs.mod = { x: 0, y: 1 }
+ this.ports.input.min = { x: 1, y: 0 }
+ this.ports.input.max = { x: 2, y: 0 }
+ this.ports.input.mod = { x: 0, y: 1 }
+ this.ports.output = true
this.operation = function () {
- const min = this.listen(this.ports.inputs.min, true)
- const max = this.listen(this.ports.inputs.max, true)
- const mod = this.listen(this.ports.inputs.mod, true)
+ const min = this.listen(this.ports.input.min, true)
+ const max = this.listen(this.ports.input.max, true)
+ const mod = this.listen(this.ports.input.mod, true)
const key = mod + 1 >= (max || 9) ? min : mod + 1
const res = pico.allowed[key] ? pico.allowed[key] : 0
this.output(`${res}`)
diff --git a/desktop/core/lib/l.js b/desktop/core/lib/l.js
index c6557f7..e49090c 100644
--- a/desktop/core/lib/l.js
+++ b/desktop/core/lib/l.js
@@ -7,17 +7,12 @@ function FnL (pico, x, y, passive) {
this.name = 'loop'
this.info = 'Loop a number of characters ahead.'
- // this.ports.push({ x: -1, y: 0, input: true })
- // if (pico) {
- // this.w = this.west()
- // this.len = this.w ? pico.valueOf(this.w.glyph) : 0
- // for (let x = 1; x <= this.len; x++) {
- // this.ports.push({ x: x, y: 0, output: true })
- // }
- // }
+ this.ports.haste.len = { x: -1, y: 0 }
this.haste = function () {
+ this.len = this.listen(this.ports.haste.len, true)
+
for (let x = 1; x <= this.len; x++) {
pico.lock(this.x + x, this.y)
}
diff --git a/desktop/core/lib/m.js b/desktop/core/lib/m.js
index cbdf37c..96ac87f 100644
--- a/desktop/core/lib/m.js
+++ b/desktop/core/lib/m.js
@@ -8,12 +8,13 @@ function FnM (pico, x, y, passive) {
this.name = 'modulo'
this.info = 'Creates the result of the modulo operation of east and west fns, southward.'
- this.ports.inputs.val = { x: 1, y: 0 }
- this.ports.inputs.mod = { x: 2, y: 0 }
+ this.ports.input.val = { x: 1, y: 0 }
+ this.ports.input.mod = { x: 2, y: 0 }
+ this.ports.output = true
this.operation = function () {
- const val = this.listen(this.ports.inputs.val, true)
- const mod = this.listen(this.ports.inputs.mod, true)
+ const val = this.listen(this.ports.input.val, true)
+ const mod = this.listen(this.ports.input.mod, true)
const key = val % (mod !== 0 ? mod : 1)
const res = pico.allowed[key] ? pico.allowed[key] : 0
this.output(`${res}`)
diff --git a/desktop/core/lib/t.js b/desktop/core/lib/t.js
index 9b2da12..e58facb 100644
--- a/desktop/core/lib/t.js
+++ b/desktop/core/lib/t.js
@@ -7,32 +7,22 @@ function FnT (pico, x, y, passive) {
this.name = 'track'
this.info = 'Read character at position.'
- // this.ports.push({ x: -1, y: 0, input: true }, { x: -2, y: 0, input: true }, { x: 0, y: 1, output: true })
- // if (pico) {
- // this.lenCh = pico.glyphAt(this.x - 1, this.y)
- // this.len = this.lenCh ? pico.valueOf(this.lenCh) : 0
- // this.valCh = pico.glyphAt(this.x - 2, this.y)
- // this.val = this.valCh ? pico.valueOf(this.valCh) : 0
-
- // if (this.lenCh === '.' || this.valCh === '.') { return }
-
- // if (!this.len || this.len < 1 || this.val < 0) { return }
- // this.ports.push({ x: (this.val % this.len) + 1, y: 0, output: true })
- // }
+ this.ports.haste.len = { x: -1, y: 0 }
+ this.ports.haste.key = { x: -2, y: 0 }
this.haste = function () {
- pico.lock(this.x - 1, this.y)
- pico.lock(this.x, this.y - 1)
- pico.lock(this.x, this.y + 1)
+ this.len = this.listen(this.ports.haste.len, true)
+ this.key = this.listen(this.ports.haste.len, true)
+
for (let x = 1; x <= this.len; x++) {
pico.lock(this.x + x, this.y)
}
}
this.operation = function () {
- if (!this.len || this.len < 1 || this.val < 0) { return }
- const x = (this.x + 1) + (this.val % this.len)
+ if (!this.len || this.len < 1 || this.key < 0) { return }
+ const x = (this.x + 1) + (this.key % this.len)
const index = pico.glyphAt(x, this.y)
pico.add(this.x, this.y + 1, index)
}
diff --git a/desktop/core/lib/x.js b/desktop/core/lib/x.js
index ba12531..4e939d6 100644
--- a/desktop/core/lib/x.js
+++ b/desktop/core/lib/x.js
@@ -7,22 +7,12 @@ function FnX (pico, x, y, passive) {
this.name = 'split'
this.info = 'Bangs eastward when westward fn is 0, and southward when fn is 1.'
- // this.ports.push({ x: -1, y: 0 })
- // this.ports.push({ x: 0, y: 1, output: true })
- // this.ports.push({ x: 1, y: 0, output: true })
- this.operation = function () {
- if (this.west('0')) {
- this.fire(1, 0)
- }
- if (this.west('1')) {
- this.fire(0, 1)
- }
- }
+ this.ports.input.val = { x: 1, y: 0 }
- this.fire = function (x, y) {
- pico.add(this.x + x, this.y + y, '*')
- pico.lock(this.x + x, this.y + y)
+ this.operation = function () {
+ const val = this.listen(this.ports.input.val)
+ this.output(val === '1' ? '1' : '0')
}
}
diff --git a/desktop/core/lib/y.js b/desktop/core/lib/y.js
index 402e31f..02c6134 100644
--- a/desktop/core/lib/y.js
+++ b/desktop/core/lib/y.js
@@ -8,12 +8,13 @@ function FnY (pico, x, y, passive) {
this.name = 'type'
this.info = 'Compares the type(num/alpha/special) of westward and eastward fns, and return 1 or 0 southward.'
- this.ports.inputs.a = { x: 1, y: 0 }
- this.ports.inputs.b = { x: 2, y: 0 }
+ this.ports.input.a = { x: 1, y: 0 }
+ this.ports.input.b = { x: 2, y: 0 }
+ this.ports.output = true
this.operation = function () {
- const a = this.listen(this.ports.inputs.a)
- const b = this.listen(this.ports.inputs.b)
+ const a = this.listen(this.ports.input.a)
+ const b = this.listen(this.ports.input.b)
if (!a && !this.east()) {
this.output('1')
diff --git a/desktop/core/pico.js b/desktop/core/pico.js
index 5e0c91b..50128c4 100644
--- a/desktop/core/pico.js
+++ b/desktop/core/pico.js
@@ -82,6 +82,7 @@ function Pico (w, h) {
const fn = fns[id]
if (this.isLocked(fn.x, fn.y)) { continue }
if (fn.passive || fn.bang()) {
+ fn.locks()
fn.haste()
}
}
diff --git a/examples/benchmark.pico b/examples/benchmark.pico
index 0c62f15..a48d84a 100644
--- a/examples/benchmark.pico
+++ b/examples/benchmark.pico
@@ -1,22 +1,23 @@
-.................................................
-...A.......C.......F.......I.......M.......Y.....
-.................................................
-.................................................
-...A2......C2......F2......I2......M2......Y2....
-.................................................
-.................................................
-...A.2.....C.2.....F.2.....I.2.....M.2.....Y.2...
-.................................................
-.................................................
-...A22.....C22.....F22.....I22.....M22.....Y22...
-.................................................
-.................................................
-...A23.....C23.....F23.....I23.....M23.....Y23...
-.................................................
-.................................................
-...A2K.....C2K.....F2K.....I2K.....M9K.....Y2K...
-.................................................
-.................................................
-...AK2.....CK2.....FKK.....IK2.....MK6.....YKK...
-.................................................
-................................................. \ No newline at end of file
+...................................................................................
+...................................................................................
+...A.....B....C.....F.....I......Lc...M.......Tc...X....Y..........................
+...................................................................................
+...................................................................................
+...A2....B1...C2....F2....I2....0Lc...M2.....3Tc...X1...Y2.........................
+...................................................................................
+...................................................................................
+...A.2...B0...C.2...F.2...I.2...1Lc...M.2...4.Tc...X0...Y.2........................
+...................................................................................
+...................................................................................
+...A22...Bw...C22...F22...I22...2Lc...M22...03Tc...Xa...Y22........................
+...................................................................................
+...................................................................................
+...A23...Bs...C23...F23...I23...3Lc...M23...13Tc........Y23........................
+...................................................................................
+...................................................................................
+...A2K...Be...C2K...F2K...I2K.........M9K...c3Tc........Y2K........................
+...................................................................................
+...................................................................................
+...AK2...Bw...CK2...FKK...IK2.........MK6...50T.........YKK........................
+...................................................................................
+................................................................................... \ No newline at end of file