-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprelude.txt
3329 lines (2914 loc) · 71.1 KB
/
prelude.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# vim: set expandtab:sw=2:ts=2
# --------------------------------------------------------------------------
# Copyright (c) 2012 Henry Strickland & Thomas Shanks
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# --------------------------------------------------------------------------
#
# If you edit this file, run "make", and be sure to Refresh (F5 in eclipse)
# the "res" folder in the terse-a1 project, before you build or run it.
#
# If you edit the Wrapper Markups (=cls =vars =meth) in comments in .java
# files, be sure to run "make", and refresh the appropriate Wrap*.java file.
#
# You need the "make" command and "tclsh" (the Tcl command line)
# istalled on your computer.
#
# --------------------------------------------------------------------------
meth str head:
IF(me len < a)
THEN(me)
ELSE(me cut: 0 to: a)
meth Obj null
me is: nil
meth Obj macro:MAYBE:NULL:
x= b value.
IF(x is: nil)THEN(c value)ELSE(x)
equals 'foo'
MAYBE('foo')NULL('bar')
equals 'bar'
MAYBE(nil)NULL('bar')
meth Bytes sha1
Sha1 en: me
meth Bytes hex
Hex en: me
meth Bytes deHex
Hex de: me
meth Str curly
Curly en: me
meth Bytes deCurly
Curly de: me
meth Str utf8
Utf8 en: me
meth Bytes deUtf8
Utf8 de: me
meth Str utf
Utf8 en: me
meth Bytes deUtf
Utf8 de: me
meth Obj ==
me eq: a
meth Obj !=
me ne: a
meth Obj <
me lt: a
meth Obj <=
me le: a
meth Obj >
me gt: a
meth Obj >=
me ge: a
equals 23
1 + 22
equals 'hello'
('h' ap: 'e') ap: ('l' ap: 'lo')
equals 'hello'
'he' ap: 'l' $ ap: 'lo'
equals 25
3 * 3 + 4 * 4
equals 142
m= Dict new. m at: 10 put: 100. (m at: 10) + 42
equals 142
m= Dict new. m at: 4 + 6 put: 10 * 10. (m at: 10) + 42
equals 'Vec'
Vec name
equals 4, 7, 9
2 * 2; 7; 3 * 3;
equals 'Vec'
() cls name
equals 0
() len
equals 'Vec'
(8;) cls name
equals 1
(8;) len
equals 'Vec'
(8,) cls name
equals 1
(8,) len
equals 25
x, y = Vec(3, 4). x * x + y * y.
equals 26
x, y = 3; 4. x * x + y * y $ + 1.
equals 26
x; y = 3, 4. x * x + y * y $ + 1.
meth Vec x
me at: 0
meth Vec y
me at: 1
meth Vec z
me at: 2
meth Vec w
me at: 3
meth Vec eq:
IF( a cls name equals: 'Vec' )THEN(
IF( me len == a len )THEN(
FOR( i: me len )MAP(
(me at: i) == (a at: i).
).
)ELSE(
'Vec.== got different length Vecs' err: VEC(me len, a len)
)
)ELSE(
'Vec.== expected Vec argument, but got' err: a cls
)
equals 1, 1, 0
Vec('foo', 100, 'z') == Vec('foo'; 100; 'zoo')
equals VEC( 100, 400, 900. )
FOR( y: 10, 20, 30 )MAP( y*y )
meth VecCls pairs:
z= Vec new.
FOR{ k,v: a }DO{
z at: k put: v.
}.
z.
equals 100, 400
FOR( x: 10, 20, 30 )IF( x < 25 )MAP( x*x )
equals 'once-upon-a-time'
('once', 'upon', 'a', 'time') join: '-'
meth Vec flat
z= Vec new.
me flattenTo: z.
z.
meth Obj flattenTo:
a ap: me.
me.
meth Vec flattenTo:
FOR(x: me) DO(
x flattenTo: a
).
me.
equals VEC(10, )
VEC(10, )flat
equals VEC(10, 20, 30, 40, 50)
(10, (20, 30), (), ( (), (40), ), 50)flat
cls Orphan Usr
meth Orphan handle:query:
'This class (', me cls name, ') is an Orphan.
Check its superclass.')jam err.
DICT{
'type', 'text';
'value', (
'This class <', me cls name, '> is an Orphan.
Check its superclass.')jam;
}
cls App Usr
cls Top App
meth Usr nonMain
meth App nonMain
meth TopCls footerButtons
Vec(
'|link|/RESET|[[RESET]]|';
'|link|/TOP|[[Top]]|';
'|link|/BROWSE|[[Browse]]|';
'|link|/Eval|[[Eval]]|';
'|link|/DemoLife|[[DemoLife]]|';
'|link|/DrawLine|[[DrawLine]]|';
'|link|/DemoLiveLissajous|[[DemoLiveLissajous]]|';
'|link|/DemoStar|[[DemoStar]]|';
'|link|/DemoLissajous|[[DemoLissajous]]|';
'|link|/DrawRect|[[DrawRect]]|';
'|link|/OldStar|[[OldStar]]|';
'|link|/DemoHt|[[DemoHt]]|';
'|link|/SwitchWorld|[[SwitchWorld]]|';
'|link|/ListUnicodePages|[[ListUnicodePages]]|';
)
meth Top handle:query:
"Default class for handling ':'."
DICT{
'type' , 'list';
'title' , 'TOP';
'value' , VEC{
'/BrowseCLASSES (NEW)';
'/EVAL CODE (DoIt, PrintIt)';
'/Browse & edit code (OLD)';
'/ADozenYaksApp';
'/FnordFlight';
'/FnordCheeseDemo';
'/GameTroids';
'/PongGame';
'/ListUnicodePages';
'/DemoLiveLifeRedBlue';
'/DemoLiveLissajous';
'/DemoLiveSierpinski';
'/DemoLivePaint';
'/BrowseWorlds (broken)';
'/SwitchWorld (broken)';
'/SnapshotWorld';
'/BrowseFiles';
'/BrowseHub';
'/DemoLiveLife';
'/DemoStar';
'/DemoLife';
'/DemoLissajous';
'/DrawLine';
'/DemoForm';
'/DrawRect';
'/OldStar';
'/FnordCannon';
'/FnordApp';
'/BlocksDemo';
'/FnordTwo';
'/FnordMotherShip';
'/GamePong';
'/GameFoo';
'/DrawAct';
'/Inspect (not yet useful)';
}}.
cls BrowseFiles App
meth BrowseFiles handle:query:
v= Ht linkLabelPairs:
FOR( fname,time,size: File dir )
MAP( ('/BrowseFile', fname) join: '.', fname ).
DICT(
'type', 'html';
'title', 'BrowseFIles';
'value', v;
)
cls BrowseFile App
meth BrowseFile handle:query:
ww= a split: '.' .
fn= (ww at: 1) ap: '.txt'.
c= File read: fn.
url= ('/EditFile.', fn)jam.
v= HT(
TAG('pre', c);
TAG('p');
TAG('hr');
TAG('a'; 'href', url; '[[EDIT]]');
).
DICT(
'type', 'html';
'title', 'BrowseFile: ' ap: fn;
'value', v;
)
cls BrowseHub App
meth BrowseHub handle:query:
v= Ht linkLabelPairs:
FOR( fname,time,size: Hub dir )
MAP( ('/BrowseHubFile', fname) join: '.', fname ).
DICT(
'type', 'html';
'title', 'BrowseHub';
'value', v;
)
cls BrowseHubFile App
meth BrowseHubFile handle:query:
ww= a split: '.' .
name= (ww at: 1) ap: '.txt'.
c= Hub read: name.
v= TAG('pre', c).
DICT(
'type', 'html';
'title', 'BrowseHubFile: ' ap: name;
'value', v;
)
cls Browse App
meth Browse handle:query:
ww= a split: '.' .
wl= ww len .
clss= Cls all .
"Start the list V with an UP link."
v= Vec('|link|/Top|[[TOP]]|', 'Go Top.';).
v len == 1 $must: (v, '#1').
v at: 0 $len == 2 $must: (v, '#2').
IF( wl == 1 )THEN(
"gk are Good Keys, those that are classes."
gk= FOR( i: clss dir )IF(
AND( clss at: i $ cls name ends: 'Cls';
OR( clss at: i $ name ends: 'Cls' $ not;
clss at: i $ cls name == 'ClsCls' ) )
)MAP( i ).
FOR( k: gk )DO(
kc= clss at: k .
kn= kc name .
tmp = ('|link|/Browse.', kn, '|', kn, '|') jam, kc meths dir join: ' '.
tmp len == 2 $must: (tmp, '#3').
v ap: tmp.
FOR( each: v )DO( each len == 2 $must: (v, each, '#4') ).
).
z= Dict new
$ at: 'type' put: 'list'
$ at: 'title' put: 'Browsing All Classes'
$ at: 'value' put: v
.
) .
IF( wl == 2 )THEN(
cn= ww at: 1 . "class name"
co= clss at: cn lower . "class object"
v ap: ( ('|link|/', cn, '|[[RUN]]|')jam, '[[RUN]]').
v ap: ( ('|link|/Browse.', cn, '|== CLASS ', cn, ' ==|')jam,
('==== class ', cn, ' ====')jam ).
d= co cls meths .
FOR( x: d dir )DO( "For each class method"
v ap: ( ( '|link|/EditMethod.', cn, 'Cls.', x, '|[[method]] cls ', x, '|' ) jam, d at: x $ str ) .
).
d= co meths .
FOR( x: d dir )DO( "For each instance method"
v ap: ( ( '|link|/EditMethod.', cn, '.', x, '|[[method]] ', x, '|' ) jam, d at: x $ str ) .
).
z= Dict new at: 'type' put: 'list'
$ at: 'title' put: ( 'Browsing Class' ap: cn )
$ at: 'value' put: v
.
) .
z .
cls EditMethod App
meth EditMethod nonMain
meth EditMethod handle:query:
ww= a split: '.' .
wl= ww len .
clss= Cls all .
IF( wl ne: 3 )THEN( 'wrong words len in EditMethod' err: ww ).
cn= ww at: 1 . "class name"
mn= ww at: 2 . "method name"
co= clss at: cn lower . "class object"
mo= co meths at: mn lower . "method object"
z= Dict new at: 'type' put: 'edit'
$ at: 'title' put: ( 'Editing Class' ap: cn $ ap: ' Method ' $ ap: mn )
$ at: 'value' put: ( mo str )
$ at: 'action' put: ( '/SubmitMethod' )
$ at: 'field1' put: 'ClassName'
$ at: 'value1' put: cn
$ at: 'field2' put: 'MethodName'
$ at: 'value2' put: mn
.
z .
cls SubmitMethod App
meth SubmitMethod nonMain
meth SubmitMethod handle:query:
clss= Cls all .
cname= b at: 'ClassName' .
mname= b at: 'MethodName' .
co= clss at: cname lower .
z= co definemethod: mname abbrev: '' doc: '' code: ( b at: 'text' ) .
url= ('/Browse.', cname,)jam.
'Browse url=' say: url.
z= Browse new handle: url query: DICT().
'Browse returns=' say: z.
z.
###########
### HelloName: Small question & answer demo.
cls HelloName App
meth HelloName handle:query:
DICT(
'type', 'edit';
'title', 'What''s Your Name?';
'value', '';
'action', '/SubmitHelloName';
).
cls SubmitHelloName App
meth SubmitHelloName nonMain
meth SubmitHelloName handle:query:
z= b at: 'text'.
DICT(
'type', 'text';
'title', 'I know your name.';
'value', ('Your name is ', z, '.') jam;
).
###########
cls Eval App
meth Eval handle:query:
DICT(
'type', 'edit';
'title', 'Eval Form';
'value', '';
'action', '/SubmitEval';
).
cls SubmitEval App
meth SubmitEval nonMain
meth SubmitEval handle:query:
z= Tmp new eval: ( b at: 'text' ).
DICT(
'type', 'text';
'title', 'doit: ' ap: (b at: 'text');
'value', z str;
).
cls EditFile App
meth EditFile handle:query:
fn= (a split: '.' $at: 1, '.txt')jam.
DICT(
'type', 'edit';
'title', 'Eval Form';
'value', File read: fn;
'action', ('/SubmitEditFile.', fn)jam;
).
cls SubmitEditFile App
meth SubmitEditFile nonMain
meth SubmitEditFile handle:query:
fn= (a split: '.' $at: 1, '.txt')jam.
x= b at: 'text'.
File write: fn value: x.
DICT(
'type', 'text';
'title', fn;
'value', ('Saved ', fn, ', ', x len, ' bytes.')jam
).
cls DrawLine App
meth DrawLine handle:query:
DICT( 'type', 'draw';
'title', 'Drawing a line';
'value', Vec(
VEC( 'line', 10, 400, 50, 300, 2 );
);
'width', 300;
'height', 500;
)
cls OldStar App
meth OldStar handle:query:
"Event Location."
ex, ey = b at: 'ex', b at: 'ey'.
"Default Location."
ex = IF( ex equals: nil )THEN( 300 )ELSE( ex num ).
ey = IF( ey equals: nil )THEN( 300 )ELSE( ey num ).
v = FOR( i: 100 )MAP( theta = i / 10 .
x= theta sin * 290 + 300.
y= theta cos * 290 + 300.
VEC('line', ex, ey, x, y).
) .
DICT( 'type', 'draw';
'title', 'Drawing a line';
'value', v;
'width', 600;
'height', 600;
).
cls DemoLife App
vars DemoLife
state
meth DemoLife canX
900
meth DemoLife canY
500
meth DemoLife numX
27
meth DemoLife numY
15
meth DemoLife delX
me canX idiv: me numX
meth DemoLife delY
me canY idiv: me numY
meth DemoLife initP
FOR( x: me numX )MAP(
FOR( y: me numY )MAP(
t = x + y * 13 .
OR((t imod: 4) == 0,
(t imod: 5) == 0,
(t imod: 7) == 0).
)
).
meth DemoLife draw
dx,dy= me delX, me delY.
IF(state is: nil) THEN(state = me initP).
nextState =
FOR( x: me numX )MAP(
FOR( y: me numY )MAP(
nei = 0.
FOR( i: 3) DO( i = i - 1 + x.
FOR( j: 3) DO( j = j - 1 + y.
nei = nei + ((state at: i) at: j).
).
).
"Notice cell x,y can count as a nei."
IF((state at: x) at: y)
THEN( OR(nei == 3; nei == 4;) )
ELSE( nei == 3 ).
).
).
state = nextState.
v = Vec new.
FOR( x: me numX )DO(
FOR( y: me numY )DO(
IF( (state at: x) at: y )THEN(
xx = x * dx + (dx idiv: 2).
yy = y * dy + (dy idiv: 2).
v ap: VEC( 'rect', xx - 12, yy - 12, 24, 24,).
)ELSE(
xx = x * dx + (dx idiv: 2).
yy = y * dy + (dy idiv: 2).
v ap: VEC( 'line', xx - 2, yy - 2,
xx + 2, yy + 2,).
).
).
).
v.
meth DemoLife handle:query:
DICT(
'type', 'draw';
'width', me canX;
'height', me canY;
'value', me draw;
'url', ( '/', me cls name, '.', me oid str ) jam;
).
cls DrawRect App
meth DrawRect handle:query:
v = Vec new.
FOR(x : 10) DO(
FOR(y : 10) DO(
v append: VEC('rect', 80 * x, 70 * y, 20, 15, 2, 'green').
v append: VEC('text', 80 * x + 25, 70 * y + 30, (x str, ',', y str) jam ).
).
).
DICT( 'type', 'draw';
'title', 'Drawing 100 Rectangles';
'value', v;
'width', 300;
'height', 500;
).
( 1234 cls DemoForm App
) 1234
( 1235 meth DemoForm handle:query:
br = Tag('br').
p = Tag('p').
i1 = Tag('input'; 'name', 'one'; 'value', 'uno').
i2 = Tag('input'; 'name', 'two'; 'value', 'dos').
i3 = Tag('input'; 'name', 'three'; 'value', 'tres').
s = Tag('input'; 'type', 'submit'; 'value', '250 OK').
form1 = Tag('form'; 'method', 'post'; 'action', '/DemoFormSubmit';
Ht entity: 'alpha'; i1; br;
Ht entity: 'beta'; i2; br;
Ht entity: 'gamma'; i3; br;
s).
i1 = Tag('input'; 'name', 'one'; 'value', 'eins').
i2 = Tag('input'; 'name', 'two'; 'value', 'zwei').
i3 = Tag('input'; 'name', 'three'; 'value', 'drei').
form2 = Tag('form'; 'method', 'get'; 'action', '/DemoFormSubmit';
Ht entity: 'alpha'; i1; br;
Ht entity: 'beta'; i2; br;
Ht entity: 'gamma'; i3; br;
s).
body = HT('form1:', TAG('pre', form1 str), p, form1, p,
'form2a:', TAG('pre', form2 str), p, form2, p,
'form2b:', TAG('pre', form2 str), p, form2, p,
'form2c:', TAG('pre', form2 str), p, form2, p,
'form2d:', TAG('pre', form2 str), p, form2, p,
'form2e:', TAG('pre', form2 str), p, form2, p,
).
DICT(
'type', 'html';
'value', Tag('html', Tag('body', body))).
) 1235
( 1236 cls DemoFormSubmit App
) 1236
( 1237 meth DemoFormSubmit handle:query:
br = Tag('br').
body = Ht(
Ht entity: 'alpha', ' == ', b at: 'one', br,
Ht entity: 'beta', ' == ', b at: 'two', br,
Ht entity: 'gamma', ' == ', b at: 'three', br,
('a={', a, '} b={', b, '}')jam, br,
).
DICT(
'type', 'html';
'value', Tag('html', Tag('body', body))).
) 1237
cls DemoHt App
meth DemoHt handle:query:
guts = Ht(
Tag('li', 'Test.'),
Tag('li', TAG('span'; 'style', 'color:yellow'; 'Hello')),
Tag('li', TAG('span'; 'style', 'background-color:brown'; 'World!')),
Tag('li', '[', TAG('a'; 'href', '/Top'; 'GO TOP'), ']'),
).
guts append: Ht(
FOR(i:100)MAP(
Tag('li', i))).
page = TAG('html',
TAG('body';
'bgcolor', '#222222';
'text', '#DDDDDD';
TAG('big',
TAG('big',
TAG('ul', guts))))).
DICT('type', 'html';
'title', 'DemoHt Title';
'value', page).
cls ListUnicodePages App
meth ListUnicodePages handle:query:
ww= a split: '.' .
IF( ww len == 2 )
THEN( me drawPage: (ww at: 1) num )
ELSE( me listPages ).
meth ListUnicodePages listPages
v = FOR(i : 256) MAP(
link = ('|link|/ListUnicodePages.', i str, '|Page ', i str, '|') jam.
label = ( 'Page ', i str ) jam.
(link, label).
).
DICT( 'type', 'list';
'title', 'Unicode Pages.';
'value', v;
).
meth ListUnicodePages drawPage:
txt = FOR(i : 256) MAP(
i = i + a*256.
(i str, ' [', i, '] ').
) implode.
DICT( 'type', 'text';
'title', 'Unicode Page ' append: a str;
'value', txt;
).
cls SwitchWorld App
meth SwitchWorld handle:query:
r = Rex new: 'w_([[a-z0-9]]+).txt'.
worlds = Vec new.
'File dir ==' say: File dir.
FOR(f : File dir) DO(
'r==' say: r.
'f0==' say: (f at: 0).
m = r match: (f at: 0).
'm==' say: m.
IF(m) THEN(
worlds append: (m at: 1).
'worlds' say: worlds.
).
).
links = Ht( FOR(w : worlds) MAP (
Ht(
Tag('a'; 'href', '/SwitchWorldSubmit?world=' ap: w; w) say,
' | '
) say ) say ) say.
'links' say: links.
br = Tag('br').
i1 = Tag('input'; 'name', 'world'; 'value', '').
s = Tag('input'; 'type', 'submit'; 'value', 'SwitchWorld').
form = Tag(
'form'; 'method', 'get'; 'action', '/SwitchWorldSubmit';
'Switch to a differnt world: '; i1; br;
s).
body = Ht(
'Worlds: ', links,
br, form
).
DICT(
'type', 'html';
'value', Tag('html', Tag('body', body))).
cls SwitchWorldSubmit App
meth SwitchWorldSubmit handle:query:
DICT(
'type', 'world';
'value', b at: 'world';
).
cls DrawApp App
vars DrawApp
scrw scrh path query stuff storage didInit
meth DrawApp nonMain
meth DrawApp handle:query:
scrw = 1000.
scrh = 480.
path = a.
query = b.
stuff = Vec new.
me basicInit.
me basicStep.
DICT(
'type', 'draw';
'title', me cls name;
'value', stuff;
'url', ( '/', me cls name, '.', me oid str ) jam;
).
meth DrawApp basicInit
IF (didInit not) THEN (
me init.
didInit = 1.
).
meth DrawApp basicStep
me step.
meth DrawApp init
me. "Subclass should override."
meth DrawApp step
me. "Subclass should override."
meth DrawApp line:to:
x1, y1 = a.
x2, y2 = b.
stuff ap: VEC('line', x1, y1, x2, y2).
meth DrawApp rect:to:
x1, y1 = a.
x2, y2 = b.
x, y = (x1 + x2) / 2, y1 + y2 / 2.
w, h = (x1 - x2) abs, (y1 - y2) abs.
stuff ap: VEC('rect', x, y, w, h).
meth DrawApp text:sw:
x, y = b.
stuff ap: VEC('text', x, y, a).
meth DrawApp store
storage = stuff.
meth DrawApp recall
stuff = storage.
cls DemoStar DrawApp
meth DemoStar init
me.
meth DemoStar step
FOR( i : Num pi * 60 ) DO(
theta = i * 0.1.
x = theta cos * 200 + 222.
y = theta sin * 200 + 222.
me line: (200, 200) to: (x, y).
"me text: i str sw: (x, y)."
)
cls DemoLissajous DrawApp
vars DemoLissajous
numPoints
meth DemoLissajous init
numPoints = 40.
me dumpVarMap.
'init: meths = ' say: (me cls meths).
meth DemoLissajous step
FOR(i : numPoints) DO(
b = i / 5 $ cos * 500 + 500,
i / 3 $ sin * 240 + 240.
me text: i str sw: b.
a = b.
).
numPoints = numPoints + 40.
cls LiveApp App
vars LiveApp
scr red blue green white black
meth LiveApp nonMain
meth LiveApp scr
scr.
meth LiveApp init
"nothing to do."
me.
meth LiveApp onLive
red= scr newInk: 900.
green= scr newInk: 90.
blue= scr newInk: 9.
white= scr newInk: 999.
black= scr newInk: 0.
'draw...' say: ('src=', scr) jam.
me draw.
scr post.
me.
meth LiveApp handle:query:
block= FN( scr: me onLive ).
DICT(
'type', 'live';
'value', block;
'event', me eventBlk).
meth LiveApp red
red.
meth LiveApp green
green.
meth LiveApp blue
blue.
meth LiveApp white
white.
meth LiveApp black
black.
meth LiveApp eventBlk
nil. "Return a blk FN(kind: xy: ...) if you accept events"
# Methods from Screen are available here.
meth LiveApp newInk:
scr newInk: a
meth LiveApp post
scr post
meth LiveApp clear:
scr clear: a
cls DemoLiveLissajous LiveApp
meth DemoLiveLissajous draw
w= me scr width / 2.
h= me scr height / 2.
me clear: 0.
prev= w*2, h.
n = 1000.
start = Sys secs.
FOR(i : n) DO(
xy= i / 19 $ cos * w + w,
i / 7 $ sin * h + h.
me newInk: i
$ line: prev to: xy
$ fontSize: 24
$ text: i str sw: xy.
prev= xy.
me post.
).
finish= Sys secs.
time= finish - start.
fps= n / time.
msg= (n, ' frames / ', time, 's = ', fps, ' fps') jam.
me white fontSize: 32 $ text: msg sw: (100,100).
cls DemoLiveLissajousSimple LiveApp
meth DemoLiveLissajousSimple draw
w= me scr width / 2.
h= me scr height / 2.
me clear: 313.
prev= w*2, h.
FOR(i : 1000) DO(
xy= i / 19 $ cos * w + w,
i / 7 $ sin * h + h.
me white line: prev to: xy.
prev= xy.
me post.
).
cls DemoLiveHappyRect LiveApp
meth DemoLiveHappyRect draw
w= me scr width.
h= me scr height.
me clear: 0.
WHILE(1) DO(
c = Num rand: 1000.
x1 = Num rand: w.
x2 = Num rand: w.
y1 = Num rand: h.
y2 = Num rand: h.
me newInk: c $ rect: x1@y1 to: x2@y2.
me post.
).
cls DemoLiveHappyLine LiveApp
meth DemoLiveHappyLine draw
w= me scr width.
h= me scr height.
me clear: 0.
WHILE(1) DO(
c = Num rand: 1000.
x1 = Num rand: w.
x2 = Num rand: w.
y1 = Num rand: h.
y2 = Num rand: h.
me newInk: c $ line: x1@y1 to: x2@y2.
me post.
).
cls DemoLiveSierpinski LiveApp
meth DemoLiveSierpinski draw
me clear: 323.
me post.
d1 = d2 = d3 = d4 = 0.
colors = 900, 90, 9.
ink = me newInk: (colors at: 0).
corners = 0, 0; 500, 380; 700, 100.
x, y = corners at: 0.
n = 100000.
k = 200.
me green thick: 2.
start = Sys secs.
FOR(i : n) DO(
r = Num rand: corners len.
cx, cy = corners at: r.
x = (x + cx) / 2.
y = (y + cy) / 2.
ink color: (colors at: d4) $dot: (x, y).
IF(i % k $not) THEN(me post).
d1, d2, d3, d4 = r, d1, d2, d3.
).
finish= Sys secs.
time= finish - start.
fps= n / k / time.
msg= (n / k, ' frames / ', time, 's = ', fps, ' fps') jam.