-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.ts
More file actions
1074 lines (936 loc) · 23.4 KB
/
Copy pathexamples.ts
File metadata and controls
1074 lines (936 loc) · 23.4 KB
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
// @ts-ignore - esbuild text loader
import gorillaSource from '../programs/GORILLA.BAS';
// @ts-ignore - esbuild text loader
import nibblesSource from '../programs/NIBBLES.BAS';
// @ts-ignore - esbuild text loader
import remlineSource from '../programs/REMLINE.BAS';
export type Difficulty = 'beginner' | 'intermediate' | 'advanced';
export type Category = 'Tutorials' | 'Games' | 'Graphics' | 'Sound' | 'Algorithms' | 'Classic';
export interface Example {
name: string;
code: string;
category: Category;
difficulty: Difficulty;
description: string;
}
const examples: Example[] = [
// ─── Tutorials ───────────────────────────────────────────
{
name: "Hello World",
category: "Tutorials",
difficulty: "beginner",
description: "Your first QBasic program",
code: `PRINT "Hello, World!"
PRINT "Welcome to jbasic IDE!"
PRINT
PRINT "Press F5 to run your programs."
`
},
{
name: "Variables & Input",
category: "Tutorials",
difficulty: "beginner",
description: "Using variables and getting user input",
code: `' Variables and INPUT demo
name$ = "World"
PRINT "Default greeting: Hello, "; name$; "!"
PRINT
INPUT "What is your name"; name$
INPUT "How old are you"; age
PRINT
PRINT "Hello, "; name$; "!"
PRINT "In 10 years you will be"; age + 10; "years old."
' String vs numeric variables
' name$ is a string (ends with $)
' age is a number
`
},
{
name: "IF/THEN/ELSE",
category: "Tutorials",
difficulty: "beginner",
description: "Conditional logic and branching",
code: `' IF/THEN/ELSE demonstration
INPUT "Enter a number"; n
IF n > 0 THEN
PRINT n; "is positive"
ELSEIF n < 0 THEN
PRINT n; "is negative"
ELSE
PRINT "You entered zero"
END IF
PRINT
' Nested IF
INPUT "Enter your score (0-100)"; score
IF score >= 90 THEN
grade$ = "A"
ELSEIF score >= 80 THEN
grade$ = "B"
ELSEIF score >= 70 THEN
grade$ = "C"
ELSEIF score >= 60 THEN
grade$ = "D"
ELSE
grade$ = "F"
END IF
PRINT "Your grade: "; grade$
`
},
{
name: "FOR/NEXT Loops",
category: "Tutorials",
difficulty: "beginner",
description: "Counting loops and STEP keyword",
code: `' FOR/NEXT loop basics
PRINT "Counting to 10:"
FOR i = 1 TO 10
PRINT i;
NEXT i
PRINT
PRINT
PRINT "Even numbers (STEP 2):"
FOR i = 2 TO 20 STEP 2
PRINT i;
NEXT i
PRINT
PRINT
PRINT "Countdown (negative STEP):"
FOR i = 10 TO 1 STEP -1
PRINT i;
NEXT i
PRINT " Blast off!"
PRINT
PRINT "Nested loops - multiplication:"
FOR i = 1 TO 5
FOR j = 1 TO 5
PRINT USING "###"; i * j;
NEXT j
PRINT
NEXT i
`
},
{
name: "SUB & FUNCTION",
category: "Tutorials",
difficulty: "intermediate",
description: "Writing reusable procedures",
code: `' SUB and FUNCTION demonstration
' Call a SUB (no return value)
Greet "Alice"
Greet "Bob"
PRINT
' Call a FUNCTION (returns a value)
PRINT "5! ="; Factorial(5)
PRINT "10! ="; Factorial(10)
PRINT
PRINT "Max of 42 and 17 is"; Max(42, 17)
PRINT "Max of 3 and 99 is"; Max(3, 99)
' ─── Procedures ───
SUB Greet (who$)
PRINT "Hello, "; who$; "! Nice to meet you."
END SUB
FUNCTION Factorial (n)
IF n <= 1 THEN
Factorial = 1
ELSE
Factorial = n * Factorial(n - 1)
END IF
END FUNCTION
FUNCTION Max (a, b)
IF a > b THEN Max = a ELSE Max = b
END FUNCTION
`
},
{
name: "Arrays & Sorting",
category: "Tutorials",
difficulty: "intermediate",
description: "DIM arrays and bubble sort",
code: `' Arrays and sorting
CONST N = 10
DIM nums(N)
' Fill with random numbers
RANDOMIZE TIMER
PRINT "Unsorted:"
FOR i = 1 TO N
nums(i) = INT(RND * 100) + 1
PRINT nums(i);
NEXT i
PRINT
' Bubble sort
FOR i = 1 TO N - 1
FOR j = 1 TO N - i
IF nums(j) > nums(j + 1) THEN
SWAP nums(j), nums(j + 1)
END IF
NEXT j
NEXT i
PRINT
PRINT "Sorted:"
FOR i = 1 TO N
PRINT nums(i);
NEXT i
PRINT
' Find min, max, average
min = nums(1)
max = nums(N)
total = 0
FOR i = 1 TO N
total = total + nums(i)
NEXT i
PRINT
PRINT "Min:"; min; " Max:"; max; " Avg:"; total / N
`
},
{
name: "SELECT CASE",
category: "Tutorials",
difficulty: "beginner",
description: "Multi-way branching with SELECT CASE",
code: `' SELECT CASE — the QBasic switch statement
INPUT "Enter a month number (1-12)"; m
SELECT CASE m
CASE 1
PRINT "January - New Year!"
CASE 2
PRINT "February - Valentine's Day"
CASE 3 TO 5
PRINT "Spring! (March/April/May)"
CASE 6 TO 8
PRINT "Summer! (June/July/August)"
CASE 9 TO 11
PRINT "Fall! (September - November)"
CASE 12
PRINT "December - Holiday Season!"
CASE ELSE
PRINT "Not a valid month!"
END SELECT
PRINT
INPUT "Enter a character"; c$
SELECT CASE UCASE$(c$)
CASE "A", "E", "I", "O", "U"
PRINT c$; " is a vowel"
CASE "A" TO "Z"
PRINT c$; " is a consonant"
CASE "0" TO "9"
PRINT c$; " is a digit"
CASE ELSE
PRINT c$; " is a special character"
END SELECT
`
},
{
name: "TYPE (Structs)",
category: "Tutorials",
difficulty: "intermediate",
description: "User-defined types for structured data",
code: `' TYPE — user-defined data structures
TYPE Student
name AS STRING
age AS INTEGER
gpa AS SINGLE
END TYPE
DIM s AS Student
s.name = "Alice"
s.age = 20
s.gpa = 3.8
PRINT "Student: "; s.name
PRINT "Age:"; s.age
PRINT "GPA:"; s.gpa
' Array of TYPEs
CONST N = 3
DIM roster(N) AS Student
roster(1).name = "Bob"
roster(1).age = 19
roster(1).gpa = 3.5
roster(2).name = "Carol"
roster(2).age = 21
roster(2).gpa = 3.9
roster(3).name = "Dave"
roster(3).age = 20
roster(3).gpa = 3.2
PRINT
PRINT "Class roster:"
PRINT "─────────────────────────"
FOR i = 1 TO N
PRINT USING "\\ \\ Age: ## GPA: #.#"; roster(i).name; roster(i).age; roster(i).gpa
NEXT i
`
},
// ─── Games ───────────────────────────────────────────────
{
name: "Guess the Number",
category: "Games",
difficulty: "beginner",
description: "Classic number guessing game",
code: `RANDOMIZE TIMER
secret = INT(RND * 100) + 1
guesses = 0
PRINT "I'm thinking of a number between 1 and 100."
PRINT
DO
INPUT "Your guess"; guess
guesses = guesses + 1
IF guess < secret THEN
PRINT "Too low!"
ELSEIF guess > secret THEN
PRINT "Too high!"
ELSE
PRINT "You got it in"; guesses; "guesses!"
END IF
LOOP UNTIL guess = secret
`
},
{
name: "Rock Paper Scissors",
category: "Games",
difficulty: "beginner",
description: "Play against the computer",
code: `RANDOMIZE TIMER
wins = 0
losses = 0
ties = 0
PRINT "=== Rock Paper Scissors ==="
PRINT
DO
PRINT "1) Rock 2) Paper 3) Scissors 0) Quit"
INPUT "Your choice"; choice
IF choice = 0 THEN EXIT DO
IF choice < 1 OR choice > 3 THEN
PRINT "Invalid choice!"
GOTO skip
END IF
cpu = INT(RND * 3) + 1
choices$ = "Rock Paper Scissors "
you$ = MID$(choices$, (choice - 1) * 9 + 1, 9)
them$ = MID$(choices$, (cpu - 1) * 9 + 1, 9)
PRINT "You: "; you$; " Computer: "; them$
IF choice = cpu THEN
PRINT "Tie!"
ties = ties + 1
ELSEIF (choice = 1 AND cpu = 3) OR (choice = 2 AND cpu = 1) OR (choice = 3 AND cpu = 2) THEN
PRINT "You win!"
wins = wins + 1
ELSE
PRINT "Computer wins!"
losses = losses + 1
END IF
PRINT
skip:
LOOP
PRINT
PRINT "Final score:"
PRINT "Wins:"; wins; " Losses:"; losses; " Ties:"; ties
`
},
{
name: "Bouncing Ball",
category: "Games",
difficulty: "intermediate",
description: "ASCII art animation with collision",
code: `' Bouncing Ball Animation
CLS
x = 1
y = 1
dx = 1
dy = 1
width = 40
height = 20
FOR frame = 1 TO 200
CLS
' Draw border
PRINT STRING$(width + 2, "#")
FOR row = 1 TO height
IF row = y THEN
PRINT "#"; SPACE$(x - 1); "O"; SPACE$(width - x); "#"
ELSE
PRINT "#"; SPACE$(width); "#"
END IF
NEXT row
PRINT STRING$(width + 2, "#")
' Move ball
x = x + dx
y = y + dy
' Bounce off walls
IF x >= width OR x <= 1 THEN dx = -dx
IF y >= height OR y <= 1 THEN dy = -dy
SLEEP 0.05
NEXT frame
PRINT "Animation complete!"
`
},
{
name: "GORILLA.BAS",
category: "Games",
difficulty: "advanced",
description: "Classic QBasic gorilla banana-throwing game",
code: gorillaSource
},
{
name: "NIBBLES.BAS",
category: "Games",
difficulty: "advanced",
description: "Classic QBasic snake game",
code: nibblesSource
},
// ─── Graphics ────────────────────────────────────────────
{
name: "DRAW Graphics",
category: "Graphics",
difficulty: "intermediate",
description: "Turtle graphics with the DRAW statement",
code: `' DRAW Statement Demo
' Turtle-graphics style vector drawing
SCREEN 12
' Draw a house
PSET (200, 300), 0
DRAW "C14BM200,300"
DRAW "R100U80E50H50U80L100D80"
' Door
DRAW "C6BM235,300U50R30D50"
' Windows
DRAW "C11BM215,240U20R20D20L20"
DRAW "C11BM265,240U20R20D20L20"
' Draw a colorful star
DRAW "C12BM450,200"
FOR i = 1 TO 5
DRAW "R40"
DRAW "A1"
DRAW "R40"
DRAW "A0"
DRAW "A0"
NEXT i
' Draw spiral using scaled moves
DRAW "C10BM100,150"
FOR i = 1 TO 20
s$ = "S" + STR$(i)
DRAW s$ + "R4U4L4D4"
NEXT i
' Draw a row of diamonds
FOR d = 0 TO 4
x = 150 + d * 80
cmd$ = "C" + STR$(9 + d) + "BM" + STR$(x) + ",380"
DRAW cmd$
DRAW "E15F15G15H15"
NEXT d
LOCATE 1, 1
COLOR 15
PRINT "DRAW Statement Demo"
`
},
{
name: "Circles & Arcs",
category: "Graphics",
difficulty: "intermediate",
description: "CIRCLE command with arcs and aspect ratio",
code: `' CIRCLE command demonstration
SCREEN 12
' Basic circles
FOR r = 10 TO 100 STEP 10
CIRCLE (320, 200), r, 14
NEXT r
' Colored filled circles (nested circles simulate fill)
FOR r = 60 TO 1 STEP -1
c = (r MOD 15) + 1
CIRCLE (100, 100), r, c
NEXT r
' Arcs — partial circles
' Draw a pac-man shape
CIRCLE (500, 300), 50, 14, 0.5, 5.8
LINE (500, 300)-(545, 280), 14
LINE (500, 300)-(545, 320), 14
' Ellipses using aspect ratio
CIRCLE (320, 350), 80, 11, , , 0.5
CIRCLE (320, 350), 80, 13, , , 2
LOCATE 1, 1
COLOR 15
PRINT "CIRCLE Command Demo"
LOCATE 2, 1
PRINT "Concentric circles, color rings, pac-man, ellipses"
`
},
{
name: "Line Art",
category: "Graphics",
difficulty: "beginner",
description: "LINE command with boxes and patterns",
code: `' LINE command demonstration
SCREEN 12
' Starburst pattern
FOR angle = 0 TO 359 STEP 5
rad = angle * 3.14159 / 180
x2 = 320 + COS(rad) * 180
y2 = 200 + SIN(rad) * 180
c = (angle / 5) MOD 15 + 1
LINE (320, 200)-(x2, y2), c
NEXT angle
' Filled box
LINE (20, 20)-(150, 60), 4, BF
' Box outline
LINE (20, 70)-(150, 110), 14, B
' Nested boxes
FOR i = 0 TO 8
x1 = 450 + i * 8
y1 = 20 + i * 8
x2 = 620 - i * 8
y2 = 140 - i * 8
LINE (x1, y1)-(x2, y2), i + 1, B
NEXT i
LOCATE 1, 22
COLOR 15
PRINT "LINE Art Demo"
`
},
{
name: "Mandelbrot Set",
category: "Graphics",
difficulty: "advanced",
description: "Fractal visualization with PSET",
code: `' Mandelbrot Set Fractal
SCREEN 12
CONST maxIter = 32
' Viewport in complex plane
xMin = -2.2
xMax = 0.8
yMin = -1.2
yMax = 1.2
FOR py = 0 TO 199
FOR px = 0 TO 319
' Map pixel to complex number
cr = xMin + (xMax - xMin) * px / 319
ci = yMin + (yMax - yMin) * py / 199
' Iterate z = z^2 + c
zr = 0
zi = 0
iter = 0
DO WHILE iter < maxIter
tr = zr * zr - zi * zi + cr
zi = 2 * zr * zi + ci
zr = tr
IF zr * zr + zi * zi > 4 THEN EXIT DO
iter = iter + 1
LOOP
IF iter < maxIter THEN
PSET (px, py), (iter MOD 15) + 1
END IF
NEXT px
NEXT py
LOCATE 1, 1
COLOR 15
PRINT "Mandelbrot Set"
`
},
{
name: "Starfield",
category: "Graphics",
difficulty: "intermediate",
description: "Animated 3D starfield simulation",
code: `' 3D Starfield
SCREEN 12
CONST numStars = 80
DIM sx(numStars), sy(numStars), sz(numStars)
DIM ox(numStars), oy(numStars)
RANDOMIZE TIMER
' Initialize stars
FOR i = 1 TO numStars
sx(i) = (RND - 0.5) * 600
sy(i) = (RND - 0.5) * 400
sz(i) = RND * 300 + 1
ox(i) = 320
oy(i) = 200
NEXT i
FOR frame = 1 TO 300
FOR i = 1 TO numStars
' Erase old position
PSET (ox(i), oy(i)), 0
' Move star closer
sz(i) = sz(i) - 3
IF sz(i) <= 0 THEN
sx(i) = (RND - 0.5) * 600
sy(i) = (RND - 0.5) * 400
sz(i) = 300
END IF
' Project 3D to 2D
px = INT(sx(i) * 256 / sz(i)) + 320
py = INT(sy(i) * 256 / sz(i)) + 200
IF px >= 0 AND px < 640 AND py >= 0 AND py < 400 THEN
' Brightness based on distance
IF sz(i) < 50 THEN
c = 15
ELSEIF sz(i) < 150 THEN
c = 7
ELSE
c = 8
END IF
PSET (px, py), c
ox(i) = px
oy(i) = py
END IF
NEXT i
SLEEP 0.02
NEXT frame
`
},
{
name: "Sierpinski Triangle",
category: "Graphics",
difficulty: "intermediate",
description: "Chaos game fractal generation",
code: `' Sierpinski Triangle via Chaos Game
SCREEN 12
' Three vertices of the triangle
x1 = 320: y1 = 10
x2 = 40: y2 = 380
x3 = 600: y3 = 380
RANDOMIZE TIMER
' Start at random point
px = RND * 640
py = RND * 400
FOR i = 1 TO 30000
' Pick a random vertex
v = INT(RND * 3) + 1
SELECT CASE v
CASE 1: px = (px + x1) / 2: py = (py + y1) / 2
CASE 2: px = (px + x2) / 2: py = (py + y2) / 2
CASE 3: px = (px + x3) / 2: py = (py + y3) / 2
END SELECT
' Skip first 20 points (transient)
IF i > 20 THEN
PSET (INT(px), INT(py)), 10
END IF
NEXT i
LOCATE 1, 1
COLOR 15
PRINT "Sierpinski Triangle (Chaos Game)"
`
},
// ─── Sound ───────────────────────────────────────────────
{
name: "Musical Scale",
category: "Sound",
difficulty: "beginner",
description: "SOUND command plays musical notes",
code: `' Musical Scale using SOUND
PRINT "Playing a musical scale..."
PRINT
' Frequencies for C major scale (octave 4)
DATA 262, 294, 330, 349, 392, 440, 494, 523
DATA "C", "D", "E", "F", "G", "A", "B", "C"
DIM freq(8), note$(8)
FOR i = 1 TO 8
READ freq(i)
NEXT i
FOR i = 1 TO 8
READ note$(i)
NEXT i
' Play ascending scale
PRINT "Ascending:"
FOR i = 1 TO 8
PRINT note$(i); " ";
SOUND freq(i), 4
NEXT i
PRINT
' Play descending scale
PRINT "Descending:"
FOR i = 8 TO 1 STEP -1
PRINT note$(i); " ";
SOUND freq(i), 4
NEXT i
PRINT
PRINT
PRINT "Done!"
`
},
{
name: "PLAY Music",
category: "Sound",
difficulty: "intermediate",
description: "MML music with the PLAY command",
code: `' PLAY command — Music Macro Language
PRINT "PLAY Command Music Demo"
PRINT "========================"
PRINT
' Twinkle Twinkle Little Star
PRINT "Twinkle Twinkle Little Star..."
PLAY "T120 L4 O4"
PLAY "CC GG AA G2 FF EE DD C2"
PLAY "GG FF EE D2 GG FF EE D2"
PLAY "CC GG AA G2 FF EE DD C2"
PRINT
PRINT "Fur Elise (opening)..."
PLAY "T140 O5 L8"
PLAY "E D# E D# E O4 B O5 D C O4 A2"
PLAY "L8 C E A B2 E G# B O5 C2"
PRINT
PRINT "Jingle Bells..."
PLAY "T160 O4 L4"
PLAY "EEE2 EEE2 EGC.D8 E1"
PLAY "FFFL8FF4 L4FEEE8E8 EDDE D2G4"
PRINT
PRINT "Done!"
`
},
{
name: "Sound Effects",
category: "Sound",
difficulty: "intermediate",
description: "Laser, siren, and explosion effects",
code: `' Sound Effects
PRINT "Sound Effects Demo"
PRINT "==================="
PRINT
' Laser
PRINT "Laser..."
FOR f = 2000 TO 200 STEP -50
SOUND f, 0.3
NEXT f
SLEEP 0.5
' Siren (up and down)
PRINT "Siren..."
FOR cycle = 1 TO 3
FOR f = 400 TO 800 STEP 20
SOUND f, 0.3
NEXT f
FOR f = 800 TO 400 STEP -20
SOUND f, 0.3
NEXT f
NEXT cycle
SLEEP 0.5
' Explosion
PRINT "Explosion..."
FOR i = 1 TO 40
f = INT(RND * 200) + 50
SOUND f, 0.5
NEXT i
SLEEP 0.5
' Power up
PRINT "Power up..."
FOR f = 100 TO 1500 STEP 30
SOUND f, 0.2
NEXT f
PRINT
PRINT "Done!"
`
},
// ─── Algorithms ──────────────────────────────────────────
{
name: "FizzBuzz",
category: "Algorithms",
difficulty: "beginner",
description: "The classic programming challenge",
code: `FOR i = 1 TO 30
IF i MOD 15 = 0 THEN
PRINT "FizzBuzz"
ELSEIF i MOD 3 = 0 THEN
PRINT "Fizz"
ELSEIF i MOD 5 = 0 THEN
PRINT "Buzz"
ELSE
PRINT i
END IF
NEXT i
`
},
{
name: "Fibonacci",
category: "Algorithms",
difficulty: "beginner",
description: "Generate the Fibonacci sequence",
code: `INPUT "How many Fibonacci numbers"; n
PRINT
a = 0
b = 1
FOR i = 1 TO n
PRINT a;
temp = a + b
a = b
b = temp
NEXT i
PRINT
PRINT "Done!"
`
},
{
name: "Prime Sieve",
category: "Algorithms",
difficulty: "intermediate",
description: "Sieve of Eratosthenes prime finder",
code: `' Sieve of Eratosthenes
INPUT "Find primes up to"; limit
DIM sieve(limit)
' 0 = prime, 1 = composite
FOR i = 2 TO INT(SQR(limit))
IF sieve(i) = 0 THEN
FOR j = i * i TO limit STEP i
sieve(j) = 1
NEXT j
END IF
NEXT i
' Print results
count = 0
FOR i = 2 TO limit
IF sieve(i) = 0 THEN
PRINT i;
count = count + 1
END IF
NEXT i
PRINT
PRINT
PRINT "Found"; count; "primes up to"; limit
`
},
{
name: "Multiplication Table",
category: "Algorithms",
difficulty: "beginner",
description: "Formatted table with PRINT USING",
code: `PRINT " ";
FOR j = 1 TO 10
PRINT USING "####"; j;
NEXT j
PRINT
PRINT STRING$(44, "-")
FOR i = 1 TO 10
PRINT USING "##"; i;
PRINT " |";
FOR j = 1 TO 10
PRINT USING "####"; i * j;
NEXT j
PRINT
NEXT i
`
},
{
name: "Star Patterns",
category: "Algorithms",
difficulty: "beginner",
description: "Triangle and diamond text patterns",
code: `INPUT "Enter size (1-20)"; size
PRINT
' Triangle
FOR i = 1 TO size
PRINT STRING$(i, "*")
NEXT i
PRINT
' Reverse triangle
FOR i = size TO 1 STEP -1
PRINT SPACE$(size - i); STRING$(i, "*")
NEXT i
PRINT
' Diamond
FOR i = 1 TO size
PRINT SPACE$(size - i); STRING$(2 * i - 1, "*")
NEXT i
FOR i = size - 1 TO 1 STEP -1
PRINT SPACE$(size - i); STRING$(2 * i - 1, "*")
NEXT i
`
},
{
name: "Tower of Hanoi",
category: "Algorithms",
difficulty: "intermediate",
description: "Recursive solution to the classic puzzle",
code: `' Tower of Hanoi — recursive solution
INPUT "Number of disks (1-8)"; n
PRINT
moves = 0
Hanoi n, "A", "C", "B"
PRINT
PRINT "Solved in"; moves; "moves"
PRINT "(Minimum moves for"; n; "disks is"; 2 ^ n - 1; ")"
SUB Hanoi (n, src$, dst$, tmp$)
SHARED moves
IF n = 0 THEN EXIT SUB
Hanoi n - 1, src$, tmp$, dst$
moves = moves + 1
PRINT "Move disk"; n; "from"; src$; "to"; dst$
Hanoi n - 1, tmp$, dst$, src$
END SUB
`
},
{
name: "Simple Calculator",
category: "Algorithms",
difficulty: "beginner",
description: "Interactive calculator with SELECT CASE",
code: `PRINT "=== Simple Calculator ==="
PRINT
DO
INPUT "First number (0 to quit)"; a
IF a = 0 THEN EXIT DO
INPUT "Operator (+, -, *, /)"; op$
INPUT "Second number"; b
SELECT CASE op$
CASE "+"
PRINT a; "+"; b; "="; a + b
CASE "-"
PRINT a; "-"; b; "="; a - b
CASE "*"
PRINT a; "*"; b; "="; a * b