1- import JSInterpreter from "js-interpreter" ;
21import { Node } from "acorn" ;
2+ import JSInterpreter from "js-interpreter" ;
33import { deg2rad , Degrees , Vector2d } from "./geometry" ;
44
55import { Animation , Frame } from "./frames" ;
6- import { Stroke } from "./scene" ;
76import * as output from "./output" ;
7+ import { Stroke } from "./scene" ;
88
9- import MainLoop from "mainloop.js" // FIXME: we don't want you here!
9+ import MainLoop from "mainloop.js" ; // FIXME: we don't want you here!
1010import { Bezier } from "./bezier" ;
1111
1212export type State = {
@@ -147,7 +147,15 @@ export class Interpreter {
147147 }
148148
149149 private readonly init : InitFunc = ( interpreter , scope ) => {
150- setFn ( "forward" , ( distance : number , color ?: string ) => {
150+ let currentColor = "black" ;
151+ prop ( "color" , {
152+ get : fn ( ( ) => currentColor ) ,
153+ set : fn ( ( c : any ) => {
154+ currentColor = String ( c ) ;
155+ } ) ,
156+ } ) ;
157+
158+ setFn ( "forward" , ( distance : number , color = currentColor ) => {
151159 this . animation = new Animation ( MOVE_DURATION * distance / 10 , ( delta : number , keyFrame : Frame ) => {
152160 const from = keyFrame . position , angle = keyFrame . facingRadians ;
153161 const to = from . plus ( Vector2d . polar ( angle , distance * delta ) ) ;
@@ -158,7 +166,7 @@ export class Interpreter {
158166 return keyFrame . with ( { position : to } ) ;
159167 } ) ;
160168 } ) ;
161- setFn ( "back" , ( distance : number , color ?: string ) => {
169+ setFn ( "back" , ( distance : number , color = currentColor ) => {
162170 this . animation = new Animation ( MOVE_DURATION * distance / 10 , ( delta : number , keyFrame : Frame ) => {
163171 const from = keyFrame . position , angle = keyFrame . facingRadians ;
164172 const to = from . plus ( Vector2d . polar ( angle , - distance * delta ) ) ;
0 commit comments