CPCWiki forum

General Category => Programming => Topic started by: Devilmarkus on 13:04, 05 December 10

Title: 1K BASIC demo
Post by: Devilmarkus on 13:04, 05 December 10
Here's a 1k BASIC demo I wrote today:
10 RANDOMIZE 2011:MODE 0:FOR t=0 TO 15:INK t,0:NEXT:INK 1,26:INK 2,9:INK 3,18
20 k=20:FOR x=0 TO 640 STEP 4:p=RND*2:PLOT x,0,2:DRAW x,20+k+p:PLOT x,20+p+k,1:DRAW x,22+p+k:IF x>300 AND x<600 THEN k=k+0.25 ELSE IF x<150 THEN k=k-0.5
30 pf=INT(RND*2011):IF pf>500 THEN GOTO 60 ELSE IF pe<4 THEN pe=4
40 g=INT(RND*8)+1:FOR y=400 TO 22+p+k STEP -g:PLOT x+RND*16,y,pe:y=y-RND*8:pe=pe+1:IF pe > 15 THEN pe=4
50 NEXT y
60 FOR l=0 TO RND*4:PLOT x,RND*(18+p+k),(RND*1)+2:NEXT:NEXT
70 a=4+s:FOR t=4 TO 15:IF t=a THEN INK t,26 ELSE INK t,0
80 NEXT:CALL &BD19:s=s+1:IF s>11 THEN s=0
90 GOTO 70


Have Fun!
Title: Re: 1K BASIC demo
Post by: Johnny Olsen on 14:53, 05 December 10
nicely, but we already have enough of it here in Denmark   :)
Title: Re: 1K BASIC demo
Post by: Gryzor on 15:12, 05 December 10
Amstrad Action time of the year! :)
Title: Re: 1K BASIC demo
Post by: Devilmarkus on 17:49, 05 December 10
Quote from: Johnny Olsen on 14:53, 05 December 10
nicely, but we already have enough of it here in Denmark   :)

Yeah, we, too :D
Title: Re: 1K BASIC demo
Post by: AMSDOS on 09:04, 06 December 10
Devilmarkus wrote:

Here's a 1k BASIC demo I wrote today:

10 RANDOMIZE 2011:MODE 0:FOR t=0 TO 15:INK t,0:NEXT:INK 1,26:INK 2,9:INK 3,18
20 k=20:FOR x=0 TO 640 STEP 4:p=RND*2:PLOT x,0,2:DRAW x,20+k+p:PLOT x,20+p+k,1:DRAW x,22+p+k:IF x>300 AND x<600 THEN k=k+0.25 ELSE IF x<150 THEN k=k-0.5
30 pf=INT(RND*2011):IF pf>500 THEN GOTO 60 ELSE IF pe<4 THEN pe=4
40 g=INT(RND*+1:FOR y=400 TO 22+p+k STEP -g:PLOT x+RND*16,y,pe:y=y-RND*8:pe=pe+1:IF pe > 15 THEN pe=4
50 NEXT y
60 FOR l=0 TO RND*4:PLOT x,RND*(18+p+k),(RND*1)+2:NEXT:NEXT
70 a=4+s:FOR t=4 TO 15:IF t=a THEN INK t,26 ELSE INK t,0
80 NEXT:CALL &BD19:s=s+1:IF s>11 THEN s=0
90 GOTO 70


Have Fun!

And you want me to do that in Turbo Pascal? I don't think it'll let me RANDOMIZE 2011!  ???  You deliberately put in those GOTOs just to annoy me didn't you?  ;)
Title: Re: 1K BASIC demo
Post by: Devilmarkus on 10:18, 06 December 10
Quote from: CP/M User on 09:04, 06 December 10
And you want me to do that in Turbo Pascal? I don't think it'll let me RANDOMIZE 2011!  ???  You deliberately put in those GOTOs just to annoy me didn't you?  ;)

Sure...  :P
Title: Re: 1K BASIC demo
Post by: redbox on 10:35, 06 December 10
Ah cr*p, your snow routine is better than mine and you did it in 1k of BASIC.  ;D
Title: Re: 1K BASIC demo
Post by: Devilmarkus on 10:50, 06 December 10
Well maybe because I use colour cycling instead of plotting the snow pixels each frame ;)

Here's V2! (Still 1k but nicier)
10 RANDOMIZE 2011:MODE 0:FOR t=0 TO 15:INK t,0:NEXT:INK 1,26:INK 2,9:INK 3,18
20 k=20:FOR x=0 TO 640 STEP 4:p=RND*2:PLOT x,0,2:DRAW x,20+k+p:PLOT x,20+p+k,1:DRAW x,22+p+k:IF x>300 AND x<600 THEN k=k+0.25 ELSE IF x<150 THEN k=k-0.5
30 pf=INT(RND*2011):IF pf>500 THEN GOTO 60 ELSE IF pe<4 THEN pe=4
40 g=INT(RND*8)+2:FOR y=400 TO 22+p+k STEP -g:PLOT x+RND*16,y,pe:y=y-RND*8:pe=pe+1:IF pe > 15 THEN pe=4
50 NEXT y
60 FOR l=0 TO RND*4:PLOT x,RND*(18+p+k),(RND*1)+2:NEXT:NEXT
70 u=8
80 a=4+s:b=4+u:FOR t=4 TO 15:IF t=a THEN INK t,26 ELSE IF t=b THEN INK t,13 ELSE INK t,0
90 NEXT:CALL &BD19:s=s+1:IF s>11 THEN s=0
100 u=u+1:IF u>11 THEN u=0
110 GOTO 80

Title: Re: 1K BASIC demo
Post by: AMSDOS on 10:52, 06 December 10
redbox wrote:

Ah cr*p, your snow routine is better than mine and you did it in 1k of BASIC.  ;D

You should do it in PL/M it's supposed to be faster than Assembly[nb]According to this guy (http://www.vintage-computer.com/vcforum/showthread.php?2404-Programming-languages&p=160204#post160204)[/nb]!

Colour Cycling is also quite a breeze in Assembly!  ;)
Title: Re: 1K BASIC demo
Post by: Devilmarkus on 10:54, 06 December 10
and here's v3 *lol*

10 RANDOMIZE 2011:MODE 0:FOR t=0 TO 15:INK t,0:NEXT:INK 1,26:INK 2,9:INK 3,18:BORDER 0
20 k=20:FOR x=0 TO 640 STEP 4:p=RND*2:PLOT x,0,2:DRAW x,20+k+p:PLOT x,20+p+k,1:DRAW x,22+p+k:IF x>300 AND x<600 THEN k=k+0.25 ELSE IF x<150 THEN k=k-0.5
30 pf=INT(RND*2011):IF pf>500 THEN GOTO 60 ELSE IF pe<4 THEN pe=4
40 g=INT(RND*8)+2:FOR y=400 TO 22+p+k STEP -g:PLOT x+RND*16,y,pe:y=y-RND*8:pe=pe+1:IF pe > 15 THEN pe=4
50 NEXT y
60 FOR l=0 TO RND*4:PLOT x,RND*(18+p+k),(RND*1)+2:NEXT:NEXT
70 u=8
80 a=4+s:b=4+u:FOR t=4 TO 15:IF t=a THEN INK t,26 ELSE IF t=b THEN INK t,13 ELSE INK t,0
90 NEXT:CALL &BD19:s=s+1:IF s>11 THEN s=0
100 u=u+1:IF u>11 THEN u=0
110 n=RND*640:m=RND*50:IF TEST(n,m)>1 AND TEST(n,m)<4 THEN PLOT n,m,1
120 GOTO 80


Who now can also add some trees?
Title: Re: 1K BASIC demo
Post by: AMSDOS on 11:07, 06 December 10
Cute, you need some grey snowflakes on the lawn though!  :laugh:
Title: Re: 1K BASIC demo
Post by: redbox on 11:46, 06 December 10
Quote from: Devilmarkus on 10:50, 06 December 10
Well maybe because I use colour cycling instead of plotting the snow pixels each frame ;)

Ah, the chink in your armour  ;)

I have a background picture that isn't damaged, but I guess that's not within the confines of BASIC 1k-ers  8)
Title: Re: 1K BASIC demo
Post by: Devilmarkus on 13:01, 06 December 10
Well... 2k! And I am no perfectionist in drawing trees, but:
10 RANDOMIZE 2011:MODE 0:FOR t=0 TO 15:INK t,0:NEXT:INK 1,26:INK 2,9:INK 3,18:BORDER 0:INK 4,2:INK 5,1
20 LOCATE 1,1:PEN 15:PRINT"HAPPY 2011":FOR x=0 TO 320 STEP 4:FOR y=400 TO 384 STEP -2:IF TEST(x,y)<>0 THEN PLOT x*2,-150+(y),4:PLOT x*2+4,-150+(y),4:PLOT x*2+4,-150+(y)+2,5:PLOT x*2,-150+(y)+2,5
30 NEXT:NEXT:LOCATE 1,1:PRINT"           ":PEN 1
40 k=20:FOR x=0 TO 640 STEP 4:p=RND*2:PLOT x,0,2:DRAW x,20+k+p:PLOT x,20+p+k,1:DRAW x,22+p+k:IF x>300 AND x<600 THEN k=k+0.25 ELSE IF x<150 THEN k=k-0.5
50 pf=INT(RND*2011):IF pf>1102 THEN GOTO 90 ELSE IF pe<6 THEN pe=6
60 g=INT(RND*8)+1:FOR y=400 TO 22+p+k STEP -g:l=x+RND*16:IF TEST(l,y)=0 THEN PLOT l,y,pe
70 y=y-RND*8:pe=pe+1:IF pe > 15 THEN pe=6
80 NEXT y
90 FOR l=0 TO RND*4:PLOT x,RND*(18+p+k),(RND*1)+2:NEXT:NEXT
100 u=8:GOSUB 170
110 a=6+s:b=6+u:FOR t=6 TO 15:IF t=a THEN INK t,26 ELSE IF t=b THEN INK t,13 ELSE INK t,0
120 NEXT:CALL &BD19:s=s+1:IF s>9 THEN s=0
130 u=u+1:IF u>9 THEN u=0
140 n=RND*640:m=RND*90:IF TEST(n,m)>1 AND TEST(n,m)<4 THEN PLOT n,m,1
150 v=v+1:IF v=10 THEN GOSUB 270:v=0
160 GOTO 110
170 WHILE (xx < 640)
180 h=RND*70+20:w=RND*30+20
190 g=RND*10+10:FOR y=g TO g+h STEP 2
200 FOR x=1 TO w STEP 4
210 a=INT(RND*3):IF a=0 THEN PLOT xx+x,y,2 ELSE IF a=1 THEN PLOT xx+x,y,3 ELSE PLOT xx+x,y,0
220 IF a=2 THEN PLOT xx-x,y,2 ELSE IF a=3 THEN PLOT xx-x,y,3 ELSE PLOT xx-x,y,0
230 w=w-RND*0.5:NEXT:NEXT
240 xx=xx+RND*100+20
250 WEND
260 RETURN
270 q=INT(RND*4)
280 IF q=0 THEN INK 4,2:INK 5,1
290 IF q=1 THEN INK 4,6:INK 5,3
300 IF q=2 THEN INK 4,18:INK 5,9
310 IF q=3 THEN INK 4,24:INK 5,12
320 IF q=4 THEN INK 4,17:INK 5,4
330 RETURN
Title: Re: 1K BASIC demo
Post by: Gryzor on 10:15, 07 December 10
The snow is really nice, and the trees look beautiful too - but they should get slowly covered with snow!

Also, why does it take so long to draw the landscape at the beginning? I'm going through the code but can't find what calculation is taking up so much time...?
Title: Re: 1K BASIC demo
Post by: Bryce on 10:34, 07 December 10
Because it's trees and landscape of course! Mountains take thousands of centuries to form, and trees need years before they are fully developed! Water on the other hand can freeze to snow within seconds. I didn't think I'd have to explain these things to you Gryzor! It's obvious!

Bryce.
Title: Re: 1K BASIC demo
Post by: arnoldemu on 10:46, 07 December 10
Quote from: Bryce on 10:34, 07 December 10
Because it's trees and landscape of course! Mountains take thousands of centuries to form, and trees need years before they are fully developed! Water on the other hand can freeze to snow within seconds. I didn't think I'd have to explain these things to you Gryzor! It's obvious!

Bryce.
Did anyone wait for it to run? I am sure the snow would turn into a glacier, and then you would see it slowly carve a big valley, then it would melt and reveal a beautiful mountain environment with happy rabbits and lots of grass and clear air...
Title: Re: 1K BASIC demo
Post by: Gryzor on 10:48, 07 December 10
Yes, but it's also obvious that NATURE does not have a Z80 in it.

Speaking of which. Yesterday I was paying a visit to a big retailer and I found aNES clone in PSOne form; nothing special, maybe a dozen games for 16 euros, but the funny thing was how it proclaimed that it had a blistering fast processor at 88MHz!!!!
Title: Re: 1K BASIC demo
Post by: Gryzor on 10:48, 07 December 10
Quote from: arnoldemu on 10:46, 07 December 10
Did anyone wait for it to run? I am sure the snow would turn into a glacier, and then you would see it slowly carve a big valley, then it would melt and reveal a beautiful mountain environment with happy rabbits and lots of grass and clear air...


And the occasional frozen body of a prehistoric hunter, eh?
Title: Re: 1K BASIC demo
Post by: Devilmarkus on 10:55, 07 December 10
 :D Yes, Bryce, of course!

No, the answer is quite simple:
Because BASIC is slooooow...
Powered by SMFPacks Menu Editor Mod