Re: Simple but nice BASIC code examples @Lavina: yeah, but not everyone can code at the level you or some coders can do, those codes in asssembler (=demos) are at the same level mathematics as art, if you get, what I mean.
Believe me, Litwr can do proper programming, and problably know several times more dialects than most of us.
Re: Simple but nice BASIC code examples @LITWR in my opinion any program is coding, no matter the actual language... coding = programming, or not? The important thing is the end product, that is what the demoscene is about; everything on the demoscene is a kind of art, digital art.
Re: Simple but nice BASIC code examples @Litwr I agree with you. Indeed pieces of graphical art. Would be cool to collect as much as possible of them over time. I would say this small programms should fit into a screen page.
Re: Simple but nice BASIC code examples @MMS Thank you. Great thread by the way!
10 REM **** Lissajous curves **** 20 color4,1:color0,1:graphic1,1:c=2 30 dx=35: dy=35: dt=3.1415926535/2 40 for a=1 to 4 50 for b=1 to 3 60 color1,c,5: c=c+1 70 for t=0 to 4*dt step .02 80 x = dx*2*a+dx*sin(a*t+t+1)*.75-dx+15 90 y = dy*2*b+dy*sin(b*t+t)*.75+10-dy-15 100 if t>0 then draw to x,y: else draw,x,y 110 next t, b, a 120 Getkey a$: Graphic0 : color 1,6,4 Run
Re: Simple but nice BASIC code examples @George wow, these triangles look really great! I've never seen them in different colors, what a nice extra! It looks fantastic in this form and color scheme.
Re: Simple but nice BASIC code examples @MMS Yes. I contacted the developer and he confirmed the bug.
COLORED SERPINSKI TRIANGLES
100 REM COLORED SERPINSKI TRIANGLES 110 GRAPHIC3,1:COLOR4,1:COLOR0,1:COLOR1,6,4:SCNCLR 120 SEED=RND(-PEEK(78)-PEEK(79)*256) 130 REM SCREEN SIZE AND MAIN TRIANGLE VERTICES 140 W=160:W2=80:H=200:H2=100:DIM X(2),Y(2) 150 X(0)=0:Y(0)=H:X(1)=W2:Y(1)=0:X(2)=W:Y(2)=H 160 REM ARRAY OF RANDOM HI-RES COLOURS 170 DIM C(3):C(0)=3:C(1)=6:C(2)=7:C(3)=8 180 FOR I=0 TO 3:J=INT(RND(1)*4) 190 T=C(I):C(I)=C(J):C(J)=T:NEXT 200 REM START POINT AND NUMBER OF DOTS 210 X=0:Y=199:DT=40000 220 REM PLOT POINTS HALFWAY TOWARDS RANDOM VERTICES 230 FOR I=0 TO DT 240 V=RND(1)*3:X=(X+X(V))/2:Y=(Y+Y(V))/2 250 IF Y =>H THEN Y=199 260 REM PICK COLOR FOR EACH TRIANGLE 270 COLOR1,C(0),6:IF Y>H2 THEN COLOR1,C(1),6 280 IF Y>H2 AND X>W2 THEN COLOR1,C(2),6 290 DRAW 1,X,Y:NEXT 300 GETKEY A$: GRAPHIC 0
Intro of the C16 and Plus/4 https://www.retropoly.de/c64er/1985/64er_1985-01.pdf
In fact there were so many great codes released over the last decades, really good source to learn. Those good codes are available not only for C64, but C16 too. Between 85 and 87 a lot of nice codes were released on our platform too in famous magazines, not only on 64'er but in English and US magazines.
Simons' BASIC is a good candidate for simple conversion, as the logic, the screen resolution, most functions/calculations, the commands are very similar and you can easily find a similar color what C64 / C128 had. The C64 BASIC 2.0 codes contain a lot of POKE commands just to set color or make sound, so (although I know most of them) I prefer something less close to register level programming
ZX Spectrum, CPC codes are also very good source (there are literally thousands of good examples), but needs more time to understand and learn the scale of the gfx screens or some special commands we do not have on Commodores.
On Facebook I am also a member of groups "BASIC Programming Languange", "BASIC on the ZX Spectrum", "Commodore 64 BASIC" and "commodore 64/128 programming". sometimes (like the very first Pine tree) some goodies pop up there too.
@George Very nice spiral code! and thank you for the hints Litwr also messaged me that he think the Plus/4 ugBASIC compiler is buggy. :-(
Re: Simple but nice BASIC code examples Fantastic Posts! Btw ugBasic seems to have a Bug with Hiresmode. Can anybody confirm?
Spiral
5 REM SPIRAL 10 GRAPHIC1,1:COLOR4,1:COLOR0,1:COLOR1,6,4:SCNCLR 20 FOR X=1 TO 321 30 FOR Y=-100 TO 100 40 W = ATN(Y/X) 50 R = SQR(X*X+Y*Y) 60 H = .5 + .5*SIN(2*W+LOG(R)*10) 70 IF H>=RND(1) THEN DRAW,160-X,100+Y:DRAW,159+X,100-Y 80 NEXT Y 90 NEXT X 100 GETKEY A$: GRAPHIC 0 RUN
Re: Simple but nice BASIC code examples MMS: I like your fractal. I, too, like fractals. I have a PC program on a floppy called CyberPlot. It graphs the results of 3D equations, and I like using it. In fact, I have some of my favorite plots in a text file. Unfortunately, all of my USB floppy drives are broken, and the only floppy drive that's not is internal to a Win98SE computer at my mother's house. I'm expecting a new drive in the mail later today, though.
BTW, is there a resource online that contains these codes and more?
Re: Simple but nice BASIC code examples Aaaah, thank you @George, a nice Mandelbrot. Fractals were my thesis work at the university. I like fractals
Herewith I attach the slightly modified version of the above 64'er program from G.Paret, the code produced a more familiar shape with other parameters
UPADTE 04.03: I agree with the comment I received the border would llok better in black. Very easy on 264 machines :-)
Up the Mandrels!
The code (I copied two of your "best practices" graphic 0 after drawing; use a "run" after the code, so it can run at once after copied just by pressing an ENTER):
10 graphic3,1:color0,1:color1,1: 20 color1,6,4:color2,6,6: color3,6,1:color4,1:rem recolor 30 xm=105:ym=105:xc=1:yc=0:T=20:S=60 35 xl=-0.15:xr=0.26:yo=0.47:yu=0.9 40 dx=(xr-xl)/xm:dy=(yu-yo)/ym 50 for n=0 to ym:y1=yo+n*dy:for m=0 to xm: x=xl+m*dx:y=y1:k=0 60 x2=x*x:y2=y*y:y=2*x*y-yc:x=x2-y2-xc:k=k+1 65 if (k < t) and (x2+y2 < s) then goto 60 70 u=m+53-n/2:u1=u+1:v=n+80:v1=v-3*(k-1) 75 draw3,u,v to u,v1:draw2,u1,v to u1,v1:draw1,u,v1 to u1,v1 80 next:next 90 getkey a$ 100 graphic0,1 run
Re: Simple but nice BASIC code examples You are welcome! This is a fantastic thread. Thats the magic of homecomputing Mandelbrot-Set
100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS 110 graphic1,1:color4,1:color0,1:color1,6,4:SCNCLR 120 FOR PY=0 TO 100 130 IM = 1.12-PY*2.24/200 140 FOR PX=0 TO 319 150 RE=PX/320*2.47-2 160 X=0:Y=0:IT=0 170 DO WHILE (X*X+Y*Y < =4) AND (IT < TH) 180 XT = X*X-Y*Y+RE 190 Y = 2*X*Y+IM 200 X = XT 210 IT = IT +1 220 LOOP 230 IF IT=TH THEN DRAW 1,PX,PY:DRAW 1,PX,199-PY 240 NEXT PX 250 NEXT PY 260 GETKEY K$ 270 GRAPHIC 0 RUN
Re: Simple but nice BASIC code examples 3) An other nice example of compact, recursive, fractal drawing routine. UPDATE: strange, but when I edited, it was a correct legit line, but after saving it, the end of long line disappeared. Frankly speaking I dunno what's happening :-) Thanks George for the warning. I try to correct it somehow.
UPDATE2: yeah, it seems the forum is a "little too smart" creating control characters from the code. I added spaces everywhere. If you still cannot get it to work, please refer to the Program code JPG I attach to the end...
It is made for C64 in Simon's BASIC. It is a slightly faster dialect than V3.5, but very similar logic. I had a feeling Commodore took some ideas from Simons' BASIC (released in 1983) as it is also released by Commodore on cartridge. I believe the cartridge should have been added to the C64C version free next to the machine in 1986, it extended the access to sound and graphics of the C64 machine so much.
That 62'er has a lot of goodies for Commodore 16 too, memory maps, handling of windows, etc. Too bad my German is not so great.
The 264 version (it is so compact it should run on C16 too): 10 graphic3,1:color0,1:color1,1: 20 color1,10,5:color2,8,6: color3,10,3:xm=105:ym=105:rem recolor 30 xc=0.77:yc=0.6:T=22:S=40 35 xl=-1.4:xr=1.4:yo=-0.9:yu=1.2 40 dx=(xr-xl)/xm:dy=(yu-yo)/ym 50 for n=0 to ym:y1=yo+n*dy:for m=0toxm:x=xl+m*dx:y=y1:k=0 60 x2=x*x:y2=y*y:y=2*x*y-yc:x=x2-y2-xc:k=k+1 65 if ( k< t ) and (x2+y2 < s) then goto 60 70 u=m+53-n/2:u1=u+1:v=n+80:v1=v-3*(k-1) 75 draw3,u,v to u,v1:draw2,u1,v to u1,v1:draw1,u,v1 to u1,v1 80 next:next 90 getkey a$
In line 20 you can recolor it to your taste. With the original C64 colors did not look so great.
The BASIC3.5 version without speedup certainly needs patience. With speedup too (I can run my YAPE at max 650%, good candidate for compilers)
Re: Simple but nice BASIC code examples Thank you for sharing the great code! It worked really well.
Yesterday I found a new BASIC dialect, called ugBASIC, and it is a compiler too. Till July 2023 it had no floating point support, but since then it is able to create and compile fast hires gfx, including this. Our compilers (including Austrospeed) cannot improve the speed of hires drawing routines I will download it, and check out how much faster is it compared to our built-in BASIC. Maybe the era of fast and easy development is here? :-)
(strange... why my links never work as intended? I use the exact format given in the Forum Help)
Re: Simple but nice BASIC code examples 100 REM ARCHIMEDES SPIRAL 110 REM 129 REM ANALOG MAGAZINE Issue 07, 1982-09 130 REM 140 graphic1,1:color4,1:color0,1:color1,6,4:SCNCLR 150 XP=144:XR=4.71238905 :XF=XR/XP 160 FOR ZI=-64 TO 64 170 ZT=ZI*2.25:ZS=ZT*ZT 180 XL=INT(SQR(20736-ZS)+0.5) 190 FOR XI=0-XL TO XL 200 XT=SQR(XI*XI+ZS)*XF 210 YY=(SIN(XT)+SIN(XT*3)*0.4)*56 220 X1=XI+ZI+160:Y1=90-YY+ZI 230 DRAW 1,X1, Y1 240 DRAW0,X1,Y1+1: DRAW0 TO X1, 191 250 NEXT XI:NEXT ZI 260 GOTO 260
Simple but nice BASIC code examples I decided to create a thread for those simple but nice / elegant BASIC codes I see on other plaforms and possible to transfer here, just the spread the greatness of the (Plus/4) BASIC
1) This code is from Ed Solie, on Applesoft BASIC. It was a one-liner. A little late, but still nice (the star could be improved a little)
10 GRAPHIC1,1 20 COLOR4,1:COLOR0,1:COLOR1,10,7 30 FOR I=0 TO 70 STEP 0.1 40 DRAW1,I*COS(I)+160,20-I*(SIN(I)*0.2-2) 50 NEXT I 60 DRAW1,156,20 TO 160,12 TO 164,20 TO 154,16 TO 166,16 TO 156,20 70 GETKEY A$ 80 COLOR1,1:COLOR0,2:GRAPHIC0,1