I haven't done much BASIC programming for a while, so for fun, today I adapted one of my JohnsonScript demos for BBCSDL.
Here's the original JohnsonScript code: https://github.com/TheGoldenManDenis/Jo ... glowballs3
(JohnsonScript is my own simple programming language I made myself, with an interpreter written in C and support for graphics through Xlib)
And here's the BBCSDL version:
Code: Select all
10 numballs%=10 -1
20 step%=16
30 res%=500
40 wh% = res%-res%MODstep%
50 VDU 23,22,wh%;wh%;8,16,16,0
60 GCOL 4
70 REMGCOL128+15
80 *refresh off
90 OFF
100 res%=res%*2
110 step%=step%*2
120
130 DIM balls{(numballs%)x,y,r,c&(4),xmo,ymo}
140 FORI%=0TOnumballs%
150 balls{(I%)}.x=RND(res%)
160 balls{(I%)}.y=RND(res%)
170 balls{(I%)}.r=res%/2+RND(res%/2)
180 balls{(I%)}.c&(0)=RND(256)
190 balls{(I%)}.c&(1)=RND(256)
200 balls{(I%)}.c&(2)=RND(256)
210 balls{(I%)}.xmo=(RND(1000)/1000-0.5)*2*12
220 balls{(I%)}.ymo=(RND(1000)/1000-0.5)*2*12
230 NEXT
240
250 REPEAT
260
270 CLG
280 MOUSEX%,Y%,B%:IFB%THENGOTO140
290
300 REM move balls
310 FORI%=0TOnumballs%
320 PROCmoveandlimit(balls{(I%)}.x, balls{(I%)}.xmo)
330 PROCmoveandlimit(balls{(I%)}.y, balls{(I%)}.ymo)
340 NEXT
350
360 REM render balls
370 FORI%=0 TO res% STEP step%
380 FORJ%=0TOres%STEPstep%
390 col%=0
400 FOR K%=0 TO numballs%
410 C%=FNglowballc( balls{(K%)}, I%,J% )
420 IF C% THEN col%=FNadd_col(col%,C%)
430 NEXT
440 IFcol%THEN
450 COLOUR4,col%>>16,col%>>8,col%
460 RECTANGLEFILL J%,I%,step%
470 ENDIF
480 NEXT
490 NEXT
500
510 *refresh
520
530 UNTILFALSE
540
550 DEF FNadd_col(a%,b%)
560 LOCAL out%
570 out%=?(^a%) + ?(^b%): IFout%>255: ?(^a%)=255ELSE?(^a%)=out%
580 out%=?(^a%+1) + ?(^b%+1): IFout%>255: ?(^a%+1)=255ELSE?(^a%+1)=out%
590 out%=?(^a%+2) + ?(^b%+2): IFout%>255: ?(^a%+2)=255ELSE?(^a%+2)=out%
600 =a%
610
620 DEF FNglowballc( b{},xx,yy )
630 LOCAL r,d,out,o%
640 r = b{}.r * 0.5
650 d = FNdist(b{}.x, b{}.y, xx,yy)
660 IF d>r:=0
670 out=1-d/r
680 = ((b{}.c&(0)*out)<<16) OR ((b{}.c&(1)*out)<<8) OR ((b{}.c&(2)*out))
690
700 DEF FNdist(x,y,xx,yy)
710 =SQR( (x-xx)^2 + (y-yy)^2 )
720
730 DEFPROCmoveandlimit(RETURN xy, RETURN mo)
740 xy += mo
750 IF xy>res% xy=res%: mo=-mo
760 IF xy<0 xy=0: mo=-mo
770 ENDPROC
Here's a video I recorded of the JohnsonScript version (it looks the same as the BBCSDL one) https://www.youtube.com/watch?v=EJ7Q6qNTnTs
PM