Mscript update #1

Merged
sixteenmillimeter merged 21 commits from mscript into master 2018-06-17 03:25:21 +00:00
2 changed files with 16 additions and 21 deletions
Showing only changes of commit 371c7afb25 - Show all commits

View File

@ -35,9 +35,7 @@ class Mscript {
this.proj = 0; this.proj = 0;
this.color = ''; this.color = '';
this.loops = []; this.loops = [];
this.fades = [];
this.rec = -1; this.rec = -1;
this.fade_rec = -1;
this.two = ''; this.two = '';
this.arr = []; this.arr = [];
@ -104,7 +102,7 @@ class Mscript {
* Apply a basic two character command * Apply a basic two character command
*/ */
basic_cmd (line) { basic_cmd (line) {
if (this.loops.length > 0) { if (this.rec !== -1) {
//hold generated arr in state loop array //hold generated arr in state loop array
this.loops[this.rec].arr this.loops[this.rec].arr
.push.apply(this.loops[this.rec].arr, .push.apply(this.loops[this.rec].arr,
@ -176,7 +174,7 @@ class Mscript {
*/ */
move_cam (line) { move_cam (line) {
this.target = parseInt(line.split('CAM ')[1]); this.target = parseInt(line.split('CAM ')[1]);
if (this.loops.length > 0) { if (this.rec !== -1) {
if (this.target > this.cam) { if (this.target > this.cam) {
this.dist = this.target - this.cam; this.dist = this.target - this.cam;
for (let x = 0; x < this.dist; x++) { for (let x = 0; x < this.dist; x++) {
@ -215,7 +213,7 @@ class Mscript {
*/ */
move_proj (line) { move_proj (line) {
this.target = parseInt(line.split('PROJ ')[1]); this.target = parseInt(line.split('PROJ ')[1]);
if (this.loops.length > 0) { if (this.rec !== -1) {
if (this.target > this.proj) { if (this.target > this.proj) {
this.dist = this.target - this.proj; this.dist = this.target - this.proj;
for (let x = 0; x < this.dist; x++) { for (let x = 0; x < this.dist; x++) {
@ -290,9 +288,6 @@ class Mscript {
this.loops[this.rec].fade = true; this.loops[this.rec].fade = true;
this.loops[this.rec].fade_count = 0; this.loops[this.rec].fade_count = 0;
this.loops[this.rec].fade_len = len; this.loops[this.rec].fade_len = len;
}
end_fade (line) {
} }
/** /**
* Extract the fade length integer from a FADE cmd * Extract the fade length integer from a FADE cmd
@ -318,15 +313,16 @@ class Mscript {
let cur = []; let cur = [];
let diff; let diff;
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
if (start[i] >= end[i]) { if (x === len - 1) {
cur[i] = end[i];
} else if (start[i] >= end[i]) {
diff = start[i] - end[i]; diff = start[i] - end[i];
cur[i] = start[i] - Math.round((diff / len) * x); cur[i] = start[i] - Math.round((diff / (len - 1)) * x);
} else { } else {
diff = end[i] - start[i]; diff = end[i] - start[i];
cur[i] = start[i] + Math.round((diff / len) * x); cur[i] = start[i] + Math.round((diff / (len - 1)) * x);
} }
} }
console.log(diff, len, x)
return this.rgb_str(cur); return this.rgb_str(cur);
} }
@ -356,37 +352,37 @@ class Mscript {
} }
} }
} else if (cmd === 'CF') { } else if (cmd === 'CF') {
if (this.loops.length < 1) { if (this.rec === -1) {
this.cam += val; this.cam += val;
} else { } else {
this.loops[this.rec].cam += val; this.loops[this.rec].cam += val;
} }
} else if (cmd === 'CB') { } else if (cmd === 'CB') {
if (this.loops.length < 1) { if (this.rec === -1) {
this.cam -= val; this.cam -= val;
} else { } else {
this.loops[this.rec].cam--; this.loops[this.rec].cam--;
} }
} else if (cmd === 'PF') { } else if (cmd === 'PF') {
if (this.loops.length < 1) { if (this.rec === -1) {
this.proj += val; this.proj += val;
} else { } else {
this.loops[this.rec].proj += val; this.loops[this.rec].proj += val;
} }
} else if (cmd === 'PB') { } else if (cmd === 'PB') {
if (this.loops.length < 1) { if (this.rec === -1) {
this.proj -= val; this.proj -= val;
} else { } else {
this.loops[this.rec].proj--; this.loops[this.rec].proj--;
} }
} else if (cmd === 'BF') { } else if (cmd === 'BF') {
if (this.loops.length < 1) { if (this.rec === -1) {
this.cam += val; this.cam += val;
} else { } else {
this.loops[this.rec].cam += val; this.loops[this.rec].cam += val;
} }
} else if (cmd === 'BB') { } else if (cmd === 'BB') {
if (this.loops.length < 1) { if (this.rec === -1) {
this.cam -= val; this.cam -= val;
} else { } else {
this.loops[this.rec].cam -= val; this.loops[this.rec].cam -= val;

View File

@ -8,11 +8,10 @@ const mscript = new Mscript();
const mscriptOld = require('../lib/mscript/index.old.js'); const mscriptOld = require('../lib/mscript/index.old.js');
mscript.interpret(`F 20 100,100,100 50,255,0 mscript.interpret(`F 72 0,0,0 10,20,30
CF CF
END END
CF PF 10
PF
`, (output) => { `, (output) => {
console.dir(output) console.dir(output)
}); });