Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bplus

Pages: 1 ... 535 536 [537]
8041
Programs / Re: Brainfuck Interpreter
« on: July 24, 2017, 01:34:09 pm »
If you are serious about writing your own interpreter, you should look at the attached file:

Erik.

Thanks Erik, I will check this out!

You might like this:
http://www.thejoyfulprogrammer.com/qb64/forum/showthread.php?tid=814&rndtime=1500917497749477912


To All,

I am pursuing this topic mainly in a PL called SmallBASIC (one word BASIC in all CAPs) an Interpreter only , NOT MS Small Basic (2 words last word not all caps).

Here (SmallBASIC Forum):
https://smallbasic.sourceforge.io/?q=node/1743

Here (Retrogamecoding.org in board where any Basic is welcome):
http://retrogamecoding.org/board/index.php?topic=592.0

Here (The QB64 Edition, a sub forum of [banned user]):
http://www.thejoyfulprogrammer.com/qb64/forum/showthread.php?tid=948&rndtime=1500919068149440136

I will pursue here too but first I want to see what Aureal is up to!  :)


8042
Programs / Re: Brainfuck Interpreter
« on: July 23, 2017, 11:24:03 pm »
After reading more, I too have another idea to go at this sort of thing.

8043
QB64 Discussion / Re: Compound assignments
« on: July 23, 2017, 02:39:42 pm »
Come to think some more about it.

Compatibility issue is a cop-out. It's not going to interfere with old code. It might interfere with how things are handled under the hood, I don't know!

_-= or _+= is just plain ugly, a good way to turn off those in favor, but can't be serious.

To save myself from rant, I will take word for it that there are deeper issues to be considered, so I will leave it to the tech guys to discuss those issues.

8044
QB64 Discussion / Re: Compound assignments
« on: July 23, 2017, 01:20:07 pm »
I never been a fan of any of the ++ or -- notation, especially when the language lets you put the symbols on either side of the variable. What is so special about "1" anyway? Why don't we have +++ and --- to skip along by 2?

I have always thought that += and -= were pretty nice though, its just that QB64 doesn't need them. There are a handful of deep reasons that I won't rant about, so the cop-out explanation is: Seeing how anything that breaks QB45 compatibility would need an underscore by tradition, I don't think that _+= and _-= are visually appealing. Of course I'm half joking, but not the other half. I'm at least 51% confident that those with the proper chops to do so won't be adding any exotic assignment operators to QB64 at the end of the day.

Come to think of it, according to certain opinions that I think are correct, using the equal sign as an assignment operator is a design mistake repeated hundreds of times since its first instance. The next good language won't overload the = symbol.

I was in favor of the idea until I read this. Considered me swayed the other way!

8045
Programs / Re: Plasma Waves
« on: July 23, 2017, 01:11:40 pm »
Hey Ashish!

I don't know if you know this but I am a fan. You and all the regulars from the [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there].

8046
Programs / Re: Brainfuck Interpreter
« on: July 23, 2017, 01:05:01 pm »
Thanks for keeping us posted bplus. I was going to respond over at the "other" forum but didn't because... reasons... namely all of my posts need to be approved first. Still waiting for a few posts (from days ago) to make it past the admin over there. No telling what a PG-13 site would do with a title like BrainFuck. Ya know, the same place that throws me ads for mail-in Thai brides. Very child-friendly as a concept.

"The Lords work in mysterious ways." - (This is definitely NOT from the Bible)

Since translating this crazy little interpreter, I am very curious now how one might go about making up a program that does anything like print "Hello World!". I did offer it up as a challenge at two other forums, because I have only the tiniest clue from reading Wiki on subject. I would like to pursue this further. An IDE? Modifications to plug-in "subroutines"?

I hope Aureal is also intrigued and that I haven't hi-jacked his thread.

8047
Programs / Re: Plasma Waves
« on: July 23, 2017, 03:38:33 am »
And since there any errors (at least I can't find any)[/size] in the program, you can do
Code: QB64: [Select]
to speed it up a bit

Thanks for tip!

8048
Programs / Re: Brainfuck Interpreter
« on: July 23, 2017, 03:28:12 am »
This is 2nd time I've seen talk of this, this month, so I checked out Rosetta Code and did a double translation.
Code: QB64: [Select]
  1. 'BF translation.bas for QB64 fork (B+=MGA) 2017-07-23
  2. ' BF in QB.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-07-22
  3. ' I just translated some QB code from Rosetta to SmallBASIC
  4. ' and tested a couple of programs Hello World, Goodbye World
  5. ' count down also found at Rosetta Code
  6. '======================================================================
  7. ' QB64 has excellent Help wiki, thanks to all who put that together!
  8. '======================================================================
  9. _TITLE "Brainf***, Rosetta Code - Quick Basic translation to SB then to QB64 (fork)"
  10. 'for directory stuff
  11. CONST ListMAX% = 20
  12. COMMON SHARED dirList$()
  13. COMMON SHARED DIRCount% 'returns file count if desired
  14.  
  15. memsize% = 20000
  16. DIM memory%(memsize%)
  17. instChars$ = "+-<>.,[]" 'valid characters
  18. loadDirList "bf*.txt"
  19.  
  20.     ptr% = 0 'memory pointer
  21.     source$ = ""
  22.     CLS
  23.     IF DIRCount% THEN
  24.         FOR i% = 1 TO DIRCount%
  25.             PRINT i%, dirList$(i%)
  26.         NEXT
  27.     ELSE
  28.         PRINT "Sorry, no bf*.txt files found."
  29.         SLEEP
  30.         END
  31.     END IF
  32.     PRINT: INPUT "Enter line number of BF Filename you desire "; ln%
  33.     IF ln% < 1 OR ln% > DIRCount% THEN END
  34.     filename$ = dirList$(ln%)
  35.  
  36.     OPEN filename$ FOR INPUT AS #1
  37.     DO
  38.         LINE INPUT #1, FLINE$
  39.         source$ = source$ + FLINE$
  40.     LOOP UNTIL EOF(1)
  41.     CLOSE #1
  42.  
  43.     IF LEN(source$) < 1 THEN
  44.         PRINT "No source code to BF."
  45.         SLEEP
  46.         END
  47.     END IF
  48.  
  49.     'let's clean the code up, check bracket balance
  50.     bktCnt% = 0
  51.     code$ = ""
  52.     FOR i% = 1 TO LEN(source$)
  53.         char$ = MID$(source$, i%, 1)
  54.         'check to see if this is a valid instruction character
  55.         IF INSTR(instChars$, char$) THEN
  56.             code$ = code$ + char$
  57.             'count brackets
  58.             IF char$ = "[" THEN bktCnt% = bktCnt% + 1
  59.             IF char$ = "]" THEN bktCnt% = bktCnt% - 1
  60.         END IF
  61.     NEXT
  62.  
  63.     IF bktCnt% THEN 'mismatched brackets
  64.         PRINT "Uneven brackets"
  65.         SLEEP
  66.         END
  67.     ELSE
  68.         PRINT "Code:": PRINT code$: PRINT: PRINT "Output:"
  69.     END IF
  70.     'clear last if any
  71.     ERASE memory%
  72.     DIM memory%(memsize%)
  73.     inLine$ = "" 'input buffer
  74.     FOR i% = 1 TO LEN(code$) 'loop through the code
  75.         instruction$ = MID$(code$, i%, 1) 'get the instruction we're on
  76.         SELECT CASE instruction$
  77.             CASE "+"
  78.                 memory%(ptr%) = memory%(ptr%) + 1
  79.             CASE "-"
  80.                 memory%(ptr%) = memory%(ptr%) - 1
  81.             CASE "."
  82.                 PRINT CHR$(memory%(ptr%));
  83.             CASE ","
  84.                 IF inLine$ = "" THEN LINE INPUT inLine$ 'buffer input
  85.                 inChar$ = LEFT$(inLine$, 1) 'take the first char off the buffer
  86.                 inLine$ = MID$(inLine$, 2) 'delete it from the buffer
  87.                 memory%(ptr%) = ASC(inChar$) 'use it
  88.             CASE ">"
  89.                 ptr% = ptr% + 1
  90.                 IF ptr% > memsize% THEN
  91.                     PRINT "Memory pointer out of range"
  92.                     SLEEP
  93.                     END
  94.                 END IF
  95.             CASE "<"
  96.                 ptr% = ptr% - 1
  97.                 IF ptr% < 0 THEN
  98.                     PRINT "Memory pointer out of range"
  99.                     SLEEP
  100.                     END
  101.                 END IF
  102.             CASE "["
  103.                 IF memory%(ptr%) = 0 THEN
  104.                     bktCnt% = 1 'count the bracket we're on
  105.                     i% = i% + 1 'move the code pointer to the next char
  106.                     WHILE bktCnt% <> 0
  107.                         'count nested loops till we find the matching one
  108.                         IF MID$(code$, i%, 1) = "]" THEN bktCnt% = bktCnt% - 1
  109.                         IF MID$(code$, i%, 1) = "[" THEN bktCnt% = bktCnt% + 1
  110.                         i% = i% + 1 'search forward
  111.                     WEND
  112.                 END IF
  113.             CASE "]"
  114.                 IF memory%(ptr%) <> 0 THEN
  115.                     bktCnt% = -1 'count the bracket we're on
  116.                     i% = i% - 1 'move the code pointer back a char
  117.                     WHILE bktCnt% <> 0
  118.                         'count nested loops till we fine the matching one
  119.                         IF MID$(code$, i%, 1) = "]" THEN bktCnt% = bktCnt% - 1
  120.                         IF MID$(code$, i%, 1) = "[" THEN bktCnt% = bktCnt% + 1
  121.                         i% = i% - 1 'search backwards
  122.                     WEND
  123.                 END IF
  124.         END SELECT
  125.     NEXT
  126.     PRINT: PRINT: INPUT "Press y for yes to do another "; yes$
  127.     IF yes$ <> "y" THEN END
  128.  
  129. ' modified function from Help files
  130. SUB loadDirList (spec$)
  131. CONST TmpFile$ = "DIR$INF0.INF"
  132. STATIC Ready%, Index%
  133. IF NOT Ready% THEN REDIM dirList$(ListMAX%): Ready% = -1 'DIM array first use
  134. IF spec$ > "" THEN 'get file names when a spec is given
  135.     SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  136.     Index% = 0: dirList$(Index%) = "": ff% = FREEFILE
  137.     OPEN TmpFile$ FOR APPEND AS #ff%
  138.     size& = LOF(ff%)
  139.     CLOSE #ff%
  140.     IF size& = 0 THEN KILL TmpFile$: EXIT SUB
  141.     OPEN TmpFile$ FOR INPUT AS #ff%
  142.     DO WHILE NOT EOF(ff%) AND Index% < ListMAX%
  143.         Index% = Index% + 1
  144.         LINE INPUT #ff%, dirList$(Index%)
  145.     LOOP
  146.     DIRCount% = Index% 'SHARED variable can return the file count
  147.     CLOSE #ff%
  148.     KILL TmpFile$
  149. ELSE IF Index% > 0 THEN Index% = Index% - 1 'no spec sends next file name
  150.  

I think the interpreter is probably easier to write than a program. Very interesting subject!

Included in zip are some short programs to get a directory listing in files list.

8049
Programs / Re: Plasma Waves
« on: July 22, 2017, 03:41:57 pm »
Hey, it does work without CLS. I like that best!

Thanks!

8050
Programs / Re: Plasma Waves
« on: July 22, 2017, 12:57:56 pm »
Hi, it looks nice. The better effect is achieved by deleting CLS after WHILE 1 and inserting CLS after the _DISPLAY command.

Well without any winks, I can't tell if you are pulling my leg or that there really is a difference?

In the loop you are executing the same sequence of commands, so I don't see a difference on paper.

OK I try.

Oh wow! what a difference. Oops, I forgot to delete the first CLS; you can try that.

I think you are pulling my leg. :)

BTW I am using Walter's QB64 fork, if that makes any difference. I am newbie to QB64 and confuse it with FB which is what I started learning to compile SmallBASIC programs before Walter invited SmallBASIC forum people over to his to have and show file attachments and screen shots...

8051
Programs / Plasma Waves
« on: July 21, 2017, 11:18:54 pm »
Press spacebar for new sea:
Code: QB64: [Select]
  1. 'Wavy with Plama.bas for QB64 fork (B+=MGA) 2017-05-05
  2. ' Wavy with Plasma Treatment.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-03
  3. ' from: animated circles started by Admin at SdlBasic 2017-05-03
  4. ' I added Plasma treatment and spacebar  changer
  5.  
  6.  
  7. '===================================================================
  8.  
  9. ' Instructions: press spacebar for new injection of plasma
  10.  
  11. '==================================================================
  12.  
  13. CONST sqr12! = .5 ^ .5
  14. CONST xmax = 1100
  15. CONST ymax = 700
  16. CONST DPI = 3.141516 * 2
  17. CONST PHIDELTA = DPI / 15
  18. CONST PHISTEP = DPI / 50
  19. CONST RADIUS = 20
  20. CONST SMALL_R = 20
  21. CONST DISTANCE = 23
  22. CONST W = xmax
  23. CONST H = ymax
  24.  
  25. SCREEN _NEWIMAGE(xmax, ymax, 32)
  26. _TITLE "Wavy with Plasma trans by bplus, Press Spacebar for New Plasma Injection."
  27. DIM SHARED pR, pG, pB AS INTEGER
  28. DIM x, y, xball, yball AS INTEGER
  29. DIM current_phi, phiIndex, phi AS DOUBLE
  30. current_phi = 0
  31. cN = 1
  32. resetPlasma
  33.     CLS
  34.     _LIMIT 10
  35.     IF _KEYHIT = 32 THEN cN = 1: resetPlasma
  36.     current_phi = current_phi + PHISTEP
  37.     FOR x = 0 TO (W + RADIUS) STEP DISTANCE
  38.         FOR y = 0 TO (H + RADIUS) STEP DISTANCE
  39.             'COLOR _RGB(120, 80, 80)
  40.             'CIRCLE (x, y), RADIUS
  41.             phiIndex = ((x + y) MOD (2 * W)) / RADIUS
  42.             phi = phiIndex * PHIDELTA + current_phi
  43.             xball = COS(phi) * RADIUS + x
  44.             yball = SIN(phi) * RADIUS + y
  45.             changePlasma
  46.             'LINE (x, y)-(xball, yball)
  47.             fcirc2 xball, yball, SMALL_R
  48.         NEXT
  49.     NEXT
  50.     _DISPLAY
  51.  
  52. SUB changePlasma ()
  53. cN = cN + 1
  54. COLOR _RGB(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
  55.  
  56. SUB resetPlasma ()
  57. pR = RND ^ 2: pG = RND ^ 2: pB = RND ^ 2
  58.  
  59. '========================================== sqrSeg Method for filled circle
  60. SUB fcirc2 (xx%, yy%, r%)
  61. 'const sqr12! = .5^.5  'in main const section
  62. r2% = r% * r%
  63. sqr12r% = sqr12! * r%
  64. LINE (xx% - sqr12r%, yy% - sqr12r%)-(xx% + sqr12r%, yy% + sqr12r%), , BF
  65. FOR x% = 0 TO sqr12r%
  66.     y% = SQR(r2% - x% * x%)
  67.     LINE (xx% - x%, yy% + sqr12r%)-(xx% - x%, yy% + y%)
  68.     LINE (xx% - x%, yy% - sqr12r%)-(xx% - x%, yy% - y%)
  69.     LINE (xx% + x%, yy% + sqr12r%)-(xx% + x%, yy% + y%)
  70.     LINE (xx% + x%, yy% - sqr12r%)-(xx% + x%, yy% - y%)
  71. FOR x% = sqr12r% TO r%
  72.     y% = SQR(r2% - x% * x%)
  73.     LINE (xx% - x%, yy% + y%)-(xx% - x%, yy% - y%)
  74.     LINE (xx% + x%, yy% + y%)-(xx% + x%, yy% - y%)
  75.  
  76. SUB fcirc (xx%, yy%, r%)
  77. r2% = r% * r%
  78. FOR x% = 0 TO r%
  79.     y% = INT(SQR(r2% - x% * x%))
  80.     LINE (xx% - x%, yy% + y%)-(xx% - x%, yy% - y%)
  81.     LINE (xx% + x%, yy% + y%)-(xx% + x%, yy% - y%)
  82.  
  83.  

Oh, I guess I was experimenting with circle drawing here too.

8052
QB64 Discussion / Re: Burning ship explorer
« on: July 21, 2017, 11:17:13 pm »
Nice, I've got some waves for your ship.

8053
QB64 Discussion / Re: Entropic Time Sim
« on: July 21, 2017, 03:46:40 pm »
Whew! I was worried when I didn't see an exit. ;-))

Pages: 1 ... 535 536 [537]