CPCWiki forum

General Category => Programming => Topic started by: cwpab on 09:49, 27 March 24

Title: Best 5-line Basic program to show a non-technical person how programming works?
Post by: cwpab on 09:49, 27 March 24
As the title says. You guys have a lot of knowledge, I only know some basic Basic commands. Yeah, "basic" appears 2 consecutive times in that sentence with different meanings.

It would be great if the program shows the "INK" command to switch between different font and background colors, so that the non-technical persons can be more interested and have a more visual memory of how programming lines work.

I tried myself, but I was only able to produce an epiplepsy inducing program. I would probably need some way to make the text stay there a few tenths of seconds instead of just a millionth of second so that the quick color changes are not harmful, or something.

But it has to be simple, no complex instructions. Any ideas?
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: McArti0 on 12:55, 27 March 24
Like this?

10 speed ink 1,1
20 border 4,9:print "<== Border Dark grey ****"
30 ink 0,13: print "*** Ground grey ****"
40 ink 1,22,17:pen 1:print "**** Bright grey ****"
50 ink 2,26:pen 2:print "**** White *****"
60 ink 3,0:pen 3:print "**** Black *****"
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: The Electric Monk on 13:18, 27 March 24
Quote from: cwpab on 09:49, 27 March 24As the title says. You guys have a lot of knowledge, I only know some basic Basic commands. Yeah, "basic" appears 2 consecutive times in that sentence with different meanings.

It would be great if the program shows the "INK" command to switch between different font and background colors, so that the non-technical persons can be more interested and have a more visual memory of how programming lines work.

I tried myself, but I was only able to produce an epiplepsy inducing program. I would probably need some way to make the text stay there a few tenths of seconds instead of just a millionth of second so that the quick color changes are not harmful, or something.

But it has to be simple, no complex instructions. Any ideas?

Your instructions are a bit unclear - not sure what you want to show people. But in general, if your text needs to stay on screen longer, add a for/next loop, like
FOR i=1 to 5000:NEXT before continuing. The example will wait until 5 seconds have passed.
If your problem is that the colors are flashing, change the parameters of SPEED INK. SPEED INK 1,1:BORDER 0,26 will make the border flash black and white like crazy. SPEED INK 100,100 will flash much slower. 1 unit is one 50th of a second here.
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: Prodatron on 13:25, 27 March 24
Quote from: McArti0 on 12:55, 27 March 24Like this?
Cool, so many greys on the CPC :)  Btw, the last line should by numbered with 60.
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: McArti0 on 13:40, 27 March 24
1 DEF FNrgb(r,g,b)=b*1+r*3+g*9
2 BORDER FNrgb(0,1,1), FNrgb(1,1,0)
3 for t= 20 to 1 step -1:speed ink t,t
4    For d=1 to 20:frame:next
5 next
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: cwpab on 14:26, 27 March 24
Thanks all! Yeah, maybe I didn't explain myself too well.

What I mean is: what kind of "hello world" program for Locomotive Basic (consisting of 2, 3, 4, 5  or maybe 9-10 lines, but not 20; and having simple instructions like "print" or "ink" but nothing too complex on first sight) would you create to show a non-technical person how those "mysterious program" with lots of lines work?

For example, I played with the random instruction, but apparently it always shows the same 5-6 colors or something... And the line(s) to make the random a "modern random" are a bit too complex (at least on first sight).

I guess the result I want would be some kind of silly text that flashes and/or scrolls while changing colors (and maybe the background too unless that's too epilepsy inducing).

This way, I can open an online CPC emulator, dictate these few lines to someone I know, and make this person quickly understand how programming feels.
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: McArti0 on 15:12, 27 March 24
Quote from: cwpab on 14:26, 27 March 24I played with the random instruction
RANDOMIZE TIME
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: eto on 15:32, 27 March 24
before dealing with inks, I would first try to teach the basics of output, input, variables and program control. Maybe a little game.
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: ZorrO on 15:44, 27 March 24
Short nice Basic changing colors, here you are:
https://www.cpcwiki.eu/forum/programming/basic-programming-tips/msg206871/#msg206871
https://www.cpcwiki.eu/forum/programming/basic-programming-tips/msg158838/#msg158838
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: eto on 17:00, 27 March 24
Quote from: eto on 15:32, 27 March 24before dealing with inks, I would first try to teach the basics of output, input, variables and program control. Maybe a little game.
something like this
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: The Electric Monk on 18:34, 27 March 24
Something very simple with two easily understood variables: The arrow keys change the colors of the pen and the border. The learner will get instant feedback, plus repetition of the code that looks for the arrow key presses in lines 40 to 70 will show the learner how each key affects each variable.

10 MODE 0:bo=13:in=13:INK 0,0:PAPER 0:PEN 1
20 PRINT"Press arrow keys to change colors"
30 LOCATE 1,10:BORDER bo:INK 1,in:PRINT"Border";bo;"Ink";in
40 IF INKEY(8)=0 THEN IF bo=0 THEN GOTO 40 ELSE bo=bo-1:GOTO 30:REM arrow left
50 IF INKEY(1)=0 THEN IF bo=26 THEN GOTO 40 ELSE bo=bo+1:GOTO 30:REM arrow right
60 IF INKEY(2)=0 THEN IF in=0 THEN GOTO 40 ELSE in=in-1:GOTO 30:REM arrow up
70 IF INKEY(0)=0 THEN IF in=26 THEN GOTO 40 ELSE in=in+1:GOTO 30:REM arrow down
80 GOTO 40
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: cwpab on 19:26, 27 March 24
I appreciate the answers, and they're certainly interesting to me...

But please note we're talking about an extremely non-technical person that doesn't have the time for complex instructions.  ;D

I would prefer some sort of "hello world" with colors that don't destroy your eyes. Someone suggested a "for i=0 to x" to delay the next "goto"... I may try that, maybe I get a 3 line program to show some text changing colors.
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: The Electric Monk on 20:10, 27 March 24
Final offer :D

10 MODE 0:BORDER 0:INK 0,0:PEN 1
20 i=1
30 PRINT "Hello world!"
40 INK 1,i
50 FOR t=1 TO 1000:NEXT t
60 i=i+1:IF i=27 THEN END ELSE GOTO 40
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: McArti0 on 20:18, 27 March 24
StopDelayTime=time+600 : While time<StopDelayTime : Wend
Title: Re: Best 5-line Basic program to show a non-technical person how programming works?
Post by: McArti0 on 20:22, 27 March 24
10 RUN "BOMBJACK.BAS"

simple code. ;D
Powered by SMFPacks Menu Editor Mod