Skip to content

Commit

Permalink
example: funny questions
Browse files Browse the repository at this point in the history
  • Loading branch information
benchmarko committed Jan 13, 2025
1 parent 4af0afd commit 9bc8a61
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 49 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ keywords should be uppercase but all lowercase is also accepted (not-strict mode
### Done

- numbers with exponential notation
- *dim* and other more complex commands are included on-demand in the compiled JavaScript
- *DIM* and other more complex commands are included on-demand in the compiled JavaScript
- TIME: *300/1000
- DIM, NEXT with multiple arguments
- DATA, READ, RESTORE
Expand All @@ -216,11 +216,11 @@ keywords should be uppercase but all lowercase is also accepted (not-strict mode

### Not implemented

after auto border break call cat chain clear cog closein closeout cont copychr
after auto border break call cat chain clear clg closein closeout cont copychr
creal cursor dec defint defreal defstr deg delete derr di draw drawr edit ei eof erl err every fill fre
goto graphics himem ink inkey-$ inp joy key let line list load locate mask memory merge move mover new
on openin openout origin out paper peek pen plot plotr poke pos rad randomize release remain renum resume run
save sound spc speed sq swap symbol tab tag tagoff test testr troff tron unt using vpos wait width window write xpos ypos zone
on openin openout origin out paper peek pen plot plotr poke pos rad randomize release remain renum resume run
save sound spc speed sq swap symbol tab tag tagoff test testr troff tron unt vpos wait width window write xpos ypos zone

### Resources

Expand Down
218 changes: 174 additions & 44 deletions dist/examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -1642,75 +1642,84 @@ RETURN
cpcBasic.addItem("", `
REM funcspec - Functional Spectrum
REM
m=2
xd=2^(2-MIN(m,2)):yd=((m=3)+2)
cols=80/xd-1:rows=50/yd
m = 2
xd = 2 ^ (2 - MIN(m, 2))
yd = ((m = 3) + 2)
cols = 80 / xd - 1
rows = 50 / yd
MODE m
xoff=0:yoff=0
'example
k=6:GOSUB 260:FRAME
'choice
k=0
INPUT "Functional Spectrum choice (1-16)";k
IF k<1 OR k>16 THEN STOP
FOR xoff=-30 TO 30 STEP 10
CLS
xoff = 0
yoff = 0
'
k = 6: GOSUB 260: FRAME
'
REM Get user choice
k = 0
INPUT "Functional Spectrum choice (1-16)"; k
IF k < 1 OR k > 16 THEN STOP
'
REM Animate spectrum
FOR xoff = 0 TO -30 STEP -10
GOSUB 260
t=TIME+40:WHILE TIME<t:FRAME:WEND
NEXT
FOR xoff=30 TO 0 STEP -10
CLS
FOR xoff = -30 TO 30 STEP 10
GOSUB 260
NEXT
FOR xoff = 30 TO 0 STEP -10
GOSUB 260
t=TIME+40:WHILE TIME<t:FRAME:WEND
NEXT
END
'
260 'output
fchar=65+32
FOR z=1 TO rows
FOR s=1 TO cols
x=s-cols\\2+xoff:y=z-(rows\\2+1)+yoff
GOSUB 380:qu=fchar+ABS((p MOD 16)):PRINT CHR$(qu);
NEXT
'AnimateSpectrum
260 CLS
fchar = 65 + 32
xh = cols \\ 2 + xoff
yh = (rows \\ 2 + 1) + yoff
FOR z = 1 TO rows
FOR s = 1 TO cols
x = s - xh
y = z - yh
ON k GOSUB 410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560
qu = fchar + ABS((p MOD 16))
PRINT CHR$(qu);
NEXT s
PRINT
NEXT z
t = TIME + 40: WHILE TIME < t: FRAME: WEND
RETURN
'
'calculate
380 ON k GOSUB 410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560
RETURN
'
410 p=15*(EXP(x)+EXP(-x))/2+LOG(y+SQR(y*y+1))
REM Calculations
410 p = 15 * (EXP(x) + EXP(-x)) / 2 + LOG(y + SQR(y * y + 1))
RETURN
420 p=15*EXP(-(x*z+y*s)/200)
420 p = 15 * EXP(-(x * z + y * s) / 200)
RETURN
430 p=15*EXP(-(SIN(x)+COS(y))/150)
430 p = 15 * EXP(-(SIN(x) + COS(y)) / 150)
RETURN
440 p=15*EXP(-(x*x+COS(y*2))/100)
440 p = 15 * EXP(-(x * x + COS(y * 2)) / 100)
RETURN
450 p=15*EXP(-(COS(x*x+y*y))/150)
450 p = 15 * EXP(-(COS(x * x + y * y)) / 150)
RETURN
460 p=15*EXP(-(x*x+y*y)/150)
460 p = 15 * EXP(-(x * x + y * y) / 150)
RETURN
470 p=3*(ATN(x)+ATN(y))
470 p = 3 * (ATN(x) + ATN(y))
RETURN
480 p=15*3*((x*x+y*y)>18)*ATN(x/2+y/2)
480 p = 15 * 3 * ((x * x + y * y) > 18) * ATN(x / 2 + y / 2)
RETURN
490 p=3*((x*x+y*y)>18)*ATN(x/2+y/2)
490 p = 3 * ((x * x + y * y) > 18) * ATN(x / 2 + y / 2)
RETURN
500 p=3*(x*x*x-y*y)*SIN((x+y)/20)/(x*x+y*y+0.3)
500 p = 3 * (x * x * x - y * y) * SIN((x + y) / 20) / (x * x + y * y + 0.3)
RETURN
510 p=(SIN(x)-SIN(y))^3
510 p = (SIN(x) - SIN(y)) ^ 3
RETURN
520 p=SIN(x-y)+SQR(ABS(x*y))
520 p = SIN(x - y) + SQR(ABS(x * y))
RETURN
530 p=7*(SIN(x/5)+COS(y))
530 p = 7 * (SIN(x / 5) + COS(y))
RETURN
540 p=(COS(2*x)+1)*(COS(2*y)+1)
540 p = (COS(2 * x) + 1) * (COS(2 * y) + 1)
RETURN
550 p=3*x^2+5*x+y
550 p = 3 * x ^ 2 + 5 * x + y
RETURN
560 p=15*SQR(ABS(y))*COS(x)
560 p = 15 * SQR(ABS(y)) * COS(x)
RETURN
'
`);
Expand Down Expand Up @@ -2000,7 +2009,7 @@ REM Read the coordinates
5000 DIM xp(18),yp(18)
FOR i = 0 TO 18 STEP 1
READ xp(i),yp(i)
yp(i)=27-yp(i)
yp(i)=25+1-yp(i)
NEXT i
RETURN
'
Expand Down Expand Up @@ -2079,6 +2088,127 @@ RETURN
'
`);

cpcBasic.addItem("", `
REM questions - Funny Questions and Answers
MODE 2
GOSUB 2000
PRINT "Funny Questions and Answers"
PRINT
PRINT "What do you do when..."
PRINT
DIM a(n)
GOSUB 1000 ' Shuffle the indices
'FOR i = 1 TO n: PRINT USING "##"; a(i);: PRINT " ";: NEXT: PRINT
'
FOR i = 1 TO n
j = a(i)
PRINT i;
PRINT question$(i); "? -- ";
PRINT answer$(j); "."
PRINT
NEXT i
END
'
' Shuffle subroutine
1000 FOR i = 1 TO n
J = INT(RND * I + 1) :'1 ≤ j ≤ i
a(i) = i: 'a[i] ← source[i]: a[i] ← a[j]: a[j] ← source[i]
a(i) = a(j)
a(j) = i
NEXT i
RETURN
'
' Read questions and answers
2000 READ n
DIM question$(n), answer$(n)
FOR i = 1 TO n
READ question$(i), answer$(i)
NEXT i
READ endMarker$: IF endMarker$<>"end" THEN PRINT "Error in data: End not found": STOP
RETURN
'
DATA 75
DATA "You find a corpse", "Dig a grave"
DATA "You have a million in debt", "Hang myself"
DATA "A nuclear war breaks out", "Emigrate to Australia"
DATA "You're faced with doubt", "Decide on the right thing"
DATA "The police are after you", "Go underground"
DATA "You oversleep", "Faint"
DATA "You sink into a bog", "Scream as loud as I can"
DATA "You get visitors", "Flee"
DATA "Your bed collapses", "Keep sleeping"
DATA "You feel sad", "Start crying"
DATA "A horse kicks you", "Start singing"
DATA "You hear a joke", "Laugh myself to pieces"
DATA "You don't have time", "Take my time"
DATA "It rains", "Get my umbrella"
DATA "You're thirsty", "Get drunk"
DATA "You're imprisoned", "Free myself from all evil"
DATA "Your God abandons you", "Become a pastor"
DATA "The devil wants to take you", "Endure it all"
DATA "You miss the bus", "Ride my bike"
'
DATA "You get lost in a forest", "Climb the tallest tree"
DATA "Your computer crashes", "Meditate for wisdom"
DATA "You meet an alien", "Offer it a coffee"
DATA "You're attacked by zombies", "Teach them to dance"
DATA "You win the lottery", "Start a llama farm"
DATA "Your phone battery dies", "Write letters by hand"
DATA "Your car breaks down", "Push it to the nearest bakery"
DATA "You spill coffee on your shirt", "Call it a new trend"
DATA "You forget someone's name", "Call everyone 'friend'"
DATA "A lion escapes from the zoo", "Challenge it to a staring contest"
DATA "Your neighbor throws a loud party", "Join with a karaoke machine"
DATA "A time traveler visits you", "Ask for next week's lottery numbers"
DATA "Your houseplants start talking", "Ask for gardening advice"
DATA "You lose your wallet", "Check the fridge"
DATA "A robot malfunctions in your house", "Teach it how to bake cookies"
DATA "You drop your ice cream", "Turn it into abstract art"
DATA "A ghost appears in your room", "Play cards with it"
DATA "Your favorite show gets canceled", "Write your own episodes"
DATA "You run out of toothpaste", "Use peanut butter instead"
DATA "A penguin knocks on your door", "Offer it a warm scarf"
DATA "You step on a Lego", "Build a castle with the rest"
DATA "Your umbrella blows away", "Turn it into a kite"
DATA "You wake up as a cat", "Take a nap immediately"
DATA "You find a secret tunnel", "Throw a surprise party in it"
DATA "Your shadow starts moving on its own", "Start a dance duet"
DATA "A dragon lands in your backyard", "Teach it to barbecue"
'
DATA "You discover a hidden treasure chest", "Donate it to a squirrel"
DATA "A talking dog approaches you", "Ask it for stock market advice"
DATA "You wake up invisible", "Start a street mime act"
DATA "Your dinner burns", "Serve it as 'charcoal cuisine'"
DATA "Your mirror breaks", "Compliment your reflection anyway"
DATA "You find a magic lamp", "Wish for infinite socks"
DATA "Your shoes disappear", "Walk on your hands"
DATA "The sun stops shining", "Start a flashlight collection"
DATA "Your favorite food is banned", "Smuggle it in like a spy"
DATA "Your alarm clock doesn't go off", "Blame time itself"
DATA "You grow wings overnight", "Start delivering pizzas"
DATA "You shrink to the size of an ant", "Build a leaf canoe"
DATA "You accidentally clone yourself", "Send your clone to work"
DATA "Your refrigerator starts talking", "Negotiate over who eats the last slice of cake"
DATA "A giant spider knocks on your window", "Teach it to knit webs"
DATA "You lose all your clothes in the wind", "Wrap yourself in newspapers"
DATA "Your toaster starts launching bread", "Call it breakfast artillery"
DATA "Your house floats into the sky", "Use it to spot new coffee shops"
DATA "A vampire invites you to dinner", "Bring garlic as a side dish"
DATA "You find a door to another dimension", "Open a tourist agency for it"
DATA "Your goldfish grows ten times its size", "Ride it to work"
DATA "The moon falls out of the sky", "Use it as a disco ball"
DATA "You’re cursed to always speak in rhyme", "Become a professional poet"
DATA "You gain the ability to control weather", "Use it to schedule picnics"
DATA "You’re transported to the Middle Ages", "Open a fast-food chain"
DATA "Your car turns into a pumpkin", "Start a pumpkin pie business"
DATA "You find out gravity doesn’t affect you", "Take up juggling for fun"
DATA "You’re suddenly fluent in every language", "Argue with birds"
DATA "A genie gives you one wish", "Wish for unlimited bubble wrap"
DATA "You get trapped in a video game", "Make it a speedrun"
DATA "end"
'
`);

cpcBasic.addItem("", `
100 REM seconds - Seconds Test
110 REM Marco Vieth, 2019
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "locobasic",
"version": "0.1.29",
"version": "0.1.30",
"description": "# LocoBasic - Loco BASIC",
"type": "commonjs",
"scripts": {
Expand Down

0 comments on commit 9bc8a61

Please sign in to comment.