[tw5] TW-Enhanced BAM Programming: TW for GUI and storage, BASIC for processing

This new sample showcases TiddlyWiki providing the GUI to interact with a running BASIC programming.

So one-way (TiddlyWiki to BASIC) sharing/communication.

Give the Sunshine Application a try. Nothing fancy, just proof-in-the-pudding concept.

1 Like

This post might be better viewed in Google Groups.

Below: BASIC program source code, Tiddler’s TW code, and finally a sample image.

BASIC program:

Screen 21 ' main_program_start: gosub init_vals gosub drawbackground gosub drawbackgroundlines gosub drawsun gosub drawforegroundlines do while true sleep 1 action$ = GetLocalStorageItem("Sunshine_Action") if action$ <> "" then if action$ = "DrawBackground" then gosub drawbackground elseif action$ = "DrawBackgroundLines" then gosub drawbackgroundlines elseif action$ = "DrawSun" then gosub drawsun elseif action$ = "DrawForegroundLines" then gosub drawforegroundlines end if SetLocalStorageItem("Sunshine_Action", "" ) end if loop end ' init_vals: s = 0.0625 SetLocalStorageItem("Sunshine_BackgroundColor", "0xffffdd") SetLocalStorageItem("Sunshine_BackgroundLinesColor", "0xffcc33") SetLocalStorageItem("Sunshine_SunColor", "0xff0000") SetLocalStorageItem("Sunshine_ForegroundLinesColor", "0xffcc33") return drawbackground: backgroundColor = val(GetLocalStorageItem("Sunshine_BackgroundColor")) line(0,0)-(1280, 1024), backgroundColor, BF sleep s return drawbackgroundlines: backgroundLinesColor = val(GetLocalStorageItem("Sunshine_BackgroundLinesColor")) for y = 0 to 1000 step 10 for x = 0 to 1300 step 15 line (0,0) - (x,y), backgroundLinesColor next x sleep s next y return drawsun: circle (100,100), 200, &hffffff, , , ,F sunColor = val(GetLocalStorageItem("Sunshine_SunColor")) circle (100,100), 200, sunColor, , , ,F sleep s return drawforegroundlines: backgroundLinesColor = val(GetLocalStorageItem("Sunshine_ForegroundLinesColor")) for y = 0 to 1000 step 40 for x = 0 to 1300 step 60 line (0,0) - (x,y), backgroundLinesColor next x sleep s next y return

Tiddler:

`\define my-actions(do_this)
<$macrocall $name=SetLocalStorageItem k=Sunshine_Action v=$do_this$/>
\end

  • Notes
    ** First, start the BASIC program by clicking on the console below
    *** The BASIC program will draw the default image, then wait for your instructions
    ** In Settings and Controls below, adjust colors of the four different layers, pressing draw the draw button for each layer in whatever order you like, knowing that whatever is drawn in each layer will overwrite whatever is in the are of that layers
Settings and Controls
Background

<$edit-text tiddler="$:/temp/Sunshine_App/background" field=“color” type=“color” default="#ffffdd" inputActions="<$macrocall $name=SetLocalStorageItem k=Sunshine_BackgroundColor v={{{ [[$:/temp/Sunshine_App/background]get[color]search-replace[#],[0x]] }}}/>"/>
<$button actions=<> >
Draw Background
</$button>

Background Lines

<$edit-text tiddler="$:/temp/Sunshine_App/backgroundlines" field=“color” type=“color” default="#ffcc33" inputActions="<$macrocall $name=SetLocalStorageItem k=Sunshine_BackgroundLinesColor v={{{ [[$:/temp/Sunshine_App/backgroundlines]get[color]search-replace[#],[0x]] }}}/>"/>
<$button actions=<> >
Draw Background Lines
</$button>

Circle

<$edit-text tiddler="$:/temp/Sunshine_App/sun" field=“color” type=“color” default="#ff0000" inputActions="<$macrocall $name=SetLocalStorageItem k=Sunshine_SunColor v={{{ [[$:/temp/Sunshine_App/sun]get[color]search-replace[#],[0x]] }}}/>"/>
<$button actions=<> >
Draw Circle
</$button>

Foreground Lines

<$edit-text tiddler="$:/temp/Sunshine_App/foregroundlines" field=“color” type=“color” default="#ffcc33" inputActions="<$macrocall $name=SetLocalStorageItem k=Sunshine_ForegroundLinesColor v={{{ [[$:/temp/Sunshine_App/foregroundlines]get[color]search-replace[#],[0x]] }}}/>"/>
<$button actions=<> >
Draw Foreground Lines
</$button>

<$tiddler tiddler={{Sunshine.BAS!!title}}> {{ ||Basic Console Window Template }}
`

Image created by the BASIC program, adjusted with the colors specified with TiddlyWiki widgets:

BlueSunshine.png

Charlie,

To format code examples so they are viewable on https://talk.tiddlywiki.org/,
enclose the code portion of your post inside triple backticks placed on separate lines
immediately before and after the code, like this:

this content will appear as a code block
when viewed on https://talk.tiddlywiki.org/

-e

1 Like

Thanks Eric,

Even when done right, I find code no fun to look at in TiddlyTalk. But for those who do prefer look at code in TiddlyTalk, I’ll try to remember that.

Three ticks before and after. Three ticks before and after.
Three ticks before and after. Three ticks before and after.
Three ticks before and after. Three ticks before and after.
Three ticks before and after. Three ticks before and after.
Three ticks before and after. Three ticks before and after…

Very interesting proof-in-the-pudding concept.

FYI if now wondering if. If the same approach could be used to interact with generic O/S scripting lingos like Powershell.

I’m not really any kind of programmer, but I thought the immediacy of the example brilliant!

One thing I do do is convert large texts farmed from the net to TW format. I’m thinking the approach you illustrate here could make that easier?

Just an appreciative comment
TT

G’day g’day,

Just to be clear in case anybody thinks otherwise: this is BASIC interpreted by wwwBASIC.js (well, my tweaked version), the BASIC program and the javascript all dynamically rolled into an HTML “page” by TiddlyWiki and fed into an iframe via srcdoc parameter.

For those adept at javascript, “BASIC Anywhere Machine” could be turned into “Javascript Anywhere Machine” in no time at all.

Any programming language, scripting or other, that has a javascript interpreter could be used instead of wwwBASIC.js

Whatever it is, it ought to be something that can be dynamically fed to an iframe by TiddlyWiki, in a TiddlyWiki tiddler.

Well, with the kind of architecture I’ve setup for BASIC Anywhere Machine.

I’m not sure what I’ve built here could be adapted to run scripts outside of TiddlyWiki.

That said, feeding the right kind of javascript to an iframe, maybe there are javascript libraries out there that allow interacting with OS-level scripts, but I highly doubt it. Maybe TiddlyWiki in a nodejs setup?

All of that tossed aside, thanks much for the appreciative comment. All it takes is for one person (on this third rock from the sun) to find something I’m doing even just semi-interesting: gets my geek mojo going.

2 Likes