Sample code
01 Hello World
10 REM comment line start with REM
20 PRINT"hello world!"
30 END // another comment using //
Line 10 : REM: Does nothing. It is used to add a comment to the code, as to make it easier to understand.
Line 20 : PRINT: Write the text hello world at the cursor position, and moves the cursor to the next line.
Line 30 : END: Stops the BASCI program. The // comment can be at any line and is used to include explanatory remarks in a program.
The screen output will be:
02 Keyboard Input
10 INPUT"What is your age ?",A
20 INPUT"What is your name ?",A$
30 PRINT "Your name is ",A$," and your age is ",A
Line 10 : INPUT: Write text text What is your age ? on the console at the cursor position. User can type a number, which is stored in variable A.
Line 20 : INPUT: Write the text What is your name ? at the cursor position, and stores the input in string variable A$
Line 30 : PRINT: Write the result on the console.
The screen output will be:
What is your age ? 24
What is your name ? Joe
Your name is Joe and your age is 24
_
03 IF THEN
10 LET A = 2
20 IF A > 1 THEN PRINT "A is ",A
30 IF A = 1 THEN GOTO 50
40 PRINT"Test completed"
50 END
Line 10 : LET: Give variable A the value 2.
Line 20 : IF: Check is A is larger than 2, and if this is the case write the value A on the console .
Line 20 : IF: Check is A is equal to 2, and if this is the next line is number 50.
Line 40 : PRINT: Write a text on the console.
Line 50 : END: Stops the BASCI program.
The screen output will be:
04 GOTO
10 REM goto and gosub example
20 PRINT"hello world!"
30 LET A = 44
40 IF A >= 44 THEN GOTO 100
50 PRINT"we jump over this line"
100 PRINT"hello again A is",A
110 GOSUB 200
120 PRINT"end of test A is ",A
130 END
200 PRINT"in a sub routine"
210 LET A = A + 1
220 RETURN
Line 30 : LET: Give variable A the value 44.
Line 40 : IF: Check is A is larger than 44 or equal, and if this is the case next line is 100.
Line 110 : GUSUB: Next line is 200 , and we push the current next line 120 on the program stack.
Line 220 : RETURN: We pop the program stack, and read next line is 120.
The screen output will be:
hello, world!
hello again A is 44
in a sub routine
end of test A is 45
_
05 Colors
10 CLS RED
20 PRINT"hello world"
30 COLOR BLUE, ORANGE
40 PRINT"hello world"
50 COLOR RED
60 PRINT"hello world"
70 END
Line 10 : CLS: Clear the screen and color it red.
Line 30 : COLOR: Select a blue text color and a orange background color.
Line 50 : COLOR: Select a red text color.
The screen output will be:
hello, world
hello, world
hello, world
06 Mouse
10 PRINT "TAP THE SCREEN"
20 GET MOUSE X,Y,V
30 GET GMOUSE A,B,C
40 IF V <> 0 THEN GOTO 70
50 WAIT 200
60 GOTO 20
70 PRINT "CONSOLE",X," ",Y," GRAPHIC ",A," ",B
80 GOTO 20
90 END
Line 20 : GET MOUSE: If user has tapped the screen, V will be 1 and X,Y will be the position. (X is 1 - 40, and Y is 1 - 24).
Line 30 : GET GMOUSE: As line 10, but A is 0 - 399, and B is 0 - 399. Upper left corner is 0,0
Line 50 : WAIT: Stop the program for 200 milliseconds.
The screen output will be:
TAP THE SCREEN
CONSOLE 25 13 GRAPHIC 258 221
07 Graphics
10 CLS BLACK
20 COLOR GREEN
30 LET A = 2
40 IF A >= 20 THEN GOTO 70
50 PSET A ,10
55 LET A = A + 1
60 GOTO 40
70 COLOR ORANGE
80 BOX 80,100,100,140
90 COLOR BLUE
100 BOX 200,200,220,201
110 END
Line 40 : IF: Makes the loop , line 40 to 60 run until A is 20.
Line 50 : PSET: Write a green pixel at postion A,10, where A in the first loop is 2.
Line 80 : BOX: Write a filled rectangle in color orange, has width 20 and height 40.
Line 100 : BOX: Write a filled rectangle in blue , has width 20 and height 1. In other words a horizontal line.
The screen output will be:
08 Mathematic
10 CLS BLACK
20 LET A = 3.14
30 LET B = COS(A)
40 LET C = SIN(A)
50 LET D = TAN(A)
60 PRINT A
70 PRINT B
80 PRINT C
90 PRINT D
100 PRINT COS(3.14/2)
105 REM result values are in radians
110 END
Line 20 : LET: Define variable A to 3.14 , which is nearly Pi.
Line 30 : LET: Give variable B the radians value for Cosine A.
Line 100 : PRINT: PRINT can also take a calculation as input and write the result on the console.
The screen output will be:
3.140000
-0.999999
0.001593
-0.001593
0.000796
Fractals
10 LET L = 50
20 LET I = 0
30 LET J = 0
40 REM WAIT 60
50 LET U = I / 200 - 1.500000
60 LET V = J / 200 - 1
70 LET X = U
80 LET Y = V
90 LET N = 0
100 LET R = X * X
110 LET Q = Y * Y
120 IF R + Q > 4 THEN GOTO 180
130 IF N >= L THEN GOTO 180
140 LET Y = 2 * X * Y + V
150 LET X = R - Q + U
160 LET N = N + 1
170 GOTO 100
180 COLOR BLACK
190 IF N < 10 THEN GOTO 300
200 LET C = 8 * (N - 10) / (L - 10)
210 IF C = 8 THEN COLOR RED
220 IF C = 1 THEN COLOR MAGENTA
230 IF C = 2 THEN COLOR BLUE
240 IF C = 3 THEN COLOR BROWN
250 IF C = 4 THEN COLOR WHITE
260 IF C = 5 THEN COLOR YELLOW
270 IF C = 6 THEN COLOR GREEN
280 IF C = 7 THEN COLOR PURPLE
290 IF C < 1 THEN COLOR BLACK
300 PSET I,J
310 LET J = J + 1
320 IF J = 400 THEN GOTO 340
330 GOTO 50
340 LET I = I + 1
350 IF I =< 400 THEN GOTO 30
360 END
This example runs very slowly, as there are a lot of calculations. It is not the writing to the screen at line 300 making is slow.
Line 10 : LET: Using another value for variable L, will change the display. Try a value 80.
Line 40 : REM: I have comment out the wait line.
Turning the green Debugging switch off in the Debugger will make the program run faster.
The screen output will be:
Snake
10 COLOR WHITE, BLACK
20 CLS
30 CURSOR 10,9
40 PRINT "SNAKE, TAP TO START "
50 CURSOR 2,11
60 PRINT "TURN LEFT = TAP LEFT PART OF SCREEN "
70 CURSOR 2,12
80 PRINT "TURN RIGHT = TAP RIGHT PART OF SCREEN "
90 GET MOUSE X,Y,V
100 IF V <> 0 THEN GOTO 130
110 WAIT 100
120 GOTO 90
130 CLS
140 LET T = 0 // T is score count
150 LET X = 20 // snake head position
160 LET Y = 12 // snake head position
170 LET // moving direction
180 REM D is LEFT=1 RIGHT=2 UP=3 DOWN=4
190 CURSOR X,Y
200 GET DATA X ,Y ,A$
210 IF A$= "X" THEN GOTO 480
220 PRINT "X" ,
230 LET T = T + 1
240 IF D = 3 THEN LET Y = Y - 1
250 IF D = 4 THEN LET Y = Y + 1
260 IF D = 2 THEN LET X = X + 1
270 IF D = 1 THEN LET X = X - 1
280 IF X < 1 THEN GOTO 480
290 IF X > 40 THEN GOTO 480
300 IF Y < 1 THEN GOTO 480
310 IF Y > 24 THEN GOTO 480
320 WAIT 100
330 GET MOUSE A,B,C
340 IF C = 0 THEN GOTO 190
350 IF A > 20 THEN GOTO 420
360 IF D = 3 THEN LET H = 1
370 IF D = 4 THEN LET H = 2
380 IF D = 2 THEN LET H = 3
390 IF D = 1 THEN LET H = 4
400 LET D = H
410 GOTO 190
420 IF D = 3 THEN LET H = 2
430 IF D = 4 THEN LET H = 1
440 IF D = 2 THEN LET H = 4
450 IF D = 1 THEN LET H = 3
460 LET D = H
470 GOTO 190
480 REM We stop
490 CLS RED
495 BEEP
500 WAIT 1000
530 CLS BLACK
535 CURSOR 10,10
540 PRINT "*** SNAKE SCORE ",T,"*** "
550 END
Line 100 : IF: In line 90 - 120 we wait on the user to tap the screen
Line 110: WAIT: As not to loop very fast, there is a WAIT in the loop.
Line 190: CURSOR: We get the current cursor position, it is the snake head.
Line 200: GET DATA: Read the console value at the cursor, and save it to a string A$.
Line 210 : IF: If the CURSOR is at a X , the snake touch itself, and the game must end.
The screen output will be:
Pong
10 LET E = 0 // SCORE
15 LET X = 10 // BALL
20 LET Y = 3 // BALL
30 LET U = - 1 // BALL SPEED
40 LET V = 1 // BALL SPEED
50 LET Z = 20 // BAT POSITION
60 LET K = 0 // BAT SPEED
70 LET T = 0
90 WAIT 20
100 LET T = T + 1
110 LET F = Z
120 GET MOUSE A ,B ,C
130 IF C = 0 THEN GOTO 170
140 IF A < 20 THEN LET K = - 1
160 IF A >= 20 THEN LET K = 1
170 LET Z = Z + K
180 IF Z < 1 THEN LET K = 1
190 IF Z < 1 THEN LET Z = 1
200 IF Z > 34 THEN LET K = - 1
210 IF Z > 34 THEN LET Z = 34
220 COLOR BLACK ,BLACK
230 CURSOR F ,24
240 PRINT "AAAAAA" ,
250 CURSOR Z ,24
260 COLOR ORANGE ,ORANGE
270 PRINT "XXXXXX" ,
280 IF T < 5 THEN GOTO 90
290 COLOR BLACK ,BLACK
300 CURSOR X,Y
310 PRINT "_" ,
320 LET X = X + V
330 LET Y = Y + U
340 COLOR RED,RED
350 CURSOR X,Y
360 GET DATA X ,Y ,P$
370 PRINT "_" ,
380 IF P$ <> "X" THEN GOTO 410
390 LET E = E + 1
400 BEEP
410 IFY <= 1 THEN LET U = - U
420 IFY >= 24 THEN LET U = - U
430 IFX <= 1 THEN LET V = - V
440 IFX >= 40 THEN LET V = - V
450 CURSOR 12 ,1
460 COLOR WHITE ,BLACK
470 PRINT " *** SCORE " ,E ," ***"
480 GOTO 70
Line 90 : WAIT: In line 90 - 280 we check for screen input and move the bat left or right. We could select not to have the loop running 5 times, and just one WAIT 100, but this will give delays in input handling.
Line 360: GET DATA: Read character at the cursor position to a string
Line 380: IF: If the data from line 360 is a X, it must be the bat, and we can make a beep and add one to the score counter E.
Try to remove the WAIT in line 90 and it will run very fast
The screen output will be:
Next