@@ -268,7 +268,6 @@ function LSystem(){
268
268
if ( Date . now ( ) - startTime > timeLimit ) {
269
269
document . getElementById ( "timeLimitLabel" ) . className += "alert " ;
270
270
setTimeout ( function ( ) {
271
- console . log ( document . getElementById ( "timeLimitLabel" ) . className ) ;
272
271
document . getElementById ( "timeLimitLabel" ) . className = document . getElementById ( "timeLimitLabel" ) . className . replace ( "alert " , '' ) ;
273
272
} , 100 ) ;
274
273
console . log ( "Replacing reached time limit after " + ( Date . now ( ) - startTime ) + "ms." ) ;
@@ -288,12 +287,47 @@ function LSystem(){
288
287
289
288
document . getElementById ( "replacementInfo" ) . innerHTML += "<p>" + a + " of " + iterations + " replacement iterations, " + ( Date . now ( ) - startTime ) + "ms</p>" ;
290
289
290
+ //ins = optimiseTurns(ins);
291
+ // Turns out this doesn't speed up drawing at all
292
+
291
293
//document.body.className = document.body.className.replace("wait ", '');
292
294
293
295
return ins ;
294
296
295
297
}
296
298
299
+ function optimiseTurns ( ins ) {
300
+
301
+ var startTime = Date . now ( ) ;
302
+
303
+ var out = "" ;
304
+ var sum = 0 ;
305
+
306
+ for ( i = 0 ; i < ins . length ; i ++ ) {
307
+ if ( ins [ i ] == "+" ) {
308
+ sum ++ ;
309
+ } else if ( ins [ i ] == "-" ) {
310
+ sum -- ;
311
+ } else {
312
+ if ( sum > 0 ) {
313
+ while ( sum -- ) {
314
+ out += "+" ;
315
+ }
316
+ } else if ( sum < 0 ) {
317
+ while ( sum ++ ) {
318
+ out += "-" ;
319
+ }
320
+ }
321
+ sum = 0 ;
322
+ out += ins [ i ] ;
323
+ }
324
+ }
325
+
326
+ console . log ( "Reduced instruction length to " + Math . round ( 10000 * out . length / ins . length ) / 100 + "% in " + ( Date . now ( ) - startTime ) + "ms." ) ;
327
+
328
+ return out ;
329
+ }
330
+
297
331
function draw ( ) {
298
332
299
333
//document.body.className += "wait ";
@@ -319,7 +353,6 @@ function LSystem(){
319
353
if ( Date . now ( ) - startTime > timeLimit ) {
320
354
document . getElementById ( "timeLimitLabel" ) . className += "alert " ;
321
355
setTimeout ( function ( ) {
322
- console . log ( document . getElementById ( "timeLimitLabel" ) . className ) ;
323
356
document . getElementById ( "timeLimitLabel" ) . className = document . getElementById ( "timeLimitLabel" ) . className . replace ( "alert " , '' ) ;
324
357
} , 100 ) ;
325
358
console . log ( "Drawing reached time limit after " + ( Date . now ( ) - startTime ) + "ms." ) ;
@@ -335,16 +368,21 @@ function LSystem(){
335
368
case "-" :
336
369
turtle . turn ( - angle ) ;
337
370
break ;
371
+ case "." :
372
+ turtle . invert ( ) ;
373
+ break ;
338
374
case "[" :
339
375
turtle . push ( ) ;
340
376
break ;
341
377
case "]" :
342
378
turtle . pop ( ) ;
343
379
break ;
344
380
default :
345
- if ( ins [ i ] . match ( / [ A - Z ] / ) ) {
381
+ if ( ins [ i ] . match ( / [ A - L ] / ) ) {
346
382
turtle . move ( distance ) ;
347
383
moveCount ++ ;
384
+ } else if ( ins [ i ] . match ( / [ M - Z ] / ) ) {
385
+ turtle . jump ( distance ) ;
348
386
}
349
387
break ;
350
388
}
@@ -513,6 +551,9 @@ function LSystem(){
513
551
popup = document . getElementById ( "importPopup" ) ;
514
552
document . getElementById ( "overlay" ) . style . display = "flex" ;
515
553
popup . style . display = "flex" ;
554
+
555
+ document . getElementById ( "importArea" ) . focus ( ) ;
556
+ document . getElementById ( "importArea" ) . select ( ) ;
516
557
}
517
558
518
559
document . getElementById ( "importButton" ) . onclick = function ( ) {
@@ -544,8 +585,6 @@ function LSystem(){
544
585
545
586
if ( instructions ) {
546
587
draw ( ) ;
547
- } else {
548
- console . log ( "foo" ) ;
549
588
}
550
589
}
551
590
0 commit comments