Qbasicnews.com

Full Version: QB text-based graphical screensaver in *just* 7 lines.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Much _grandly_ dearest all of you QB45/QB71 community,

I welcome you all to my very latest and next challenge in QB which is this: create a text-based graphical screensaver in QuickBASIC or MS-DOS QBasic in only seven (7) lines! Big Grin After the success of Relsoft’s 9-liners, I thought I am gonna now test you on this one just to see how VERY EXCELLENT you *really* are at your text-based graphics coding in QB, only to get all of you so warmed up and ready to sharpen up your programming skills a little bit. So here we go, shall we? Wink !!

_______________________________________________________

H E R E • A R E • T H E • R U L E S :
  • 1 » Your program *must* be “Pure-QB”-based only. No external libraries at all, please.

    2 » Your program must also have no more and no less than seven (7) lines total.

    3 » You are welcome to use ANY text mode that is built into QB itself (e.g. 40x25, 80x43, 80x50). ^_^ !

    4 » No colon-joined lines, subs/functions, or Call Interrupts allowed. Ever.

    5 » Remark lines ( ' ) do not count as a line. You are to, however, use at least one of the remark lines at the VERY start of your coding to name your project, who you are that created it, and what your project is really all about.

    6 » Aside from the allowable text modes, leave all of the other modes alone for this challenge, please.

    7 » For the output of your program, you are only allowed (in *any* color(s) you want!) to display any of the four (4) characters:
    [Image: Textgraphic1.gif]
    ........and that is all. No other characters.

    8 » After you are all finished on your project, paste it up on your reply of this thread so that we can see it! Wink

    9 » You are ABSOLUTELY welcome to enter as many times as you like!! Big Grin

    10 » The deadline for this special challenge is Monday, November 1, 2004.

Here now is a *real* example from me on how it is to be done:
Code:
'8 0 x 5 0   T E L E V I S I O N   S T A T I C
'---------------------- QB 7-line Text Demo #2
'
'Presented to you by Adigun Azikiwe Polack.
'
'In this QB 7-liner example here, it presents a much better
'simulation of static the way it was meant to be portrayed
'on a classic television set.  This is my improved and much
'better attempt at a seven line QB demo (whereas my first
'one failed to make the grade), and is overall one to learn
'by.  Enjoy!!!  ;*) !
'
'- Adigun Azikiwe Polack
'  September 20, 2004


1 WIDTH 80, 50
2 COLOR 8, 0
3 x = INT(RND(1) * 78) + 1
4 y = INT(RND(1) * 48) + 1
5 LOCATE y, x
6 IF INT(RND(1) * 4) + 1 = 1 THEN PRINT CHR$(176) ELSE IF INT(RND(1) * 4) + 1 = 2 THEN PRINT CHR$(177) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(178) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(219)
7 GOTO 2
_______________________________________________________


So, what are you waiting for? Prepare to devise up your RATHER BEST screensaver/demo of this kind, whether it is plasma- or fire-based or what have you!! I mean, hey, I want to see some really fine ones from you, as I am truly encouraging you as passionately as I can to do this!!! Cool !!

Talk to you all again, and do your very best!!! :king: !!



WISHING YOU ALL DEFINITELY GOOD FORTUNE ON THIS INTERESTING CHALLENGE,

[Image: AAPname.gif]
Adigun Azikiwe Polack
One of the Founders of “Aura Flow”
Continuing Developer of “Frantic Journey”
Current Developer of “Star Angelic Slugger”
Webmaster of the “AAP Official Projects Squad”



EDIT (on September 20, 2004): Last night, I posted to you an incorrect example which was:

Code:
' T W I N   W H I R L W I N D   O F   C O L O R S
' -------------------- The 7-line Text Demo in QB
'
' Presented by Adigun Azikiwe Polack.
'
' This is my first ever 7-liner about a double randomly-colored
' whirlwind kicking into your QB screen!!  It presents to you an
' amazing sample of just how good you can be at programming a
' splendid text-based graphical 7-liner in QuickBASIC/QBasic
' yourself!!!  ^_^=b !!
'
' - Adigun Azikiwe Polack
'   September 19, 2004


1 X = 1
2 C = INT(RND(1) * 31) + 1
3 LOCATE , X
4 PRINT "   " + CHR$(176) + CHR$(177) + CHR$(178) + CHR$(219) + CHR$(219) + CHR$(178) + CHR$(177) + CHR$(176) + "                                " + CHR$(176) + CHR$(177) + CHR$(178) + CHR$(219) + CHR$(219) + CHR$(178) + CHR$(177) + CHR$(176)
5 X = (INT(RND(1) * 25) + 1)
6 COLOR C
7 GOTO 2

In the very first three (3) replies of this thread, they commented about that code placed just above this piece of text, so *please* disregard that example and go for that other example of mine where the rules are. Thanks!! Big Grin !



______________________________________
[Image: NewQBCPCbanner.jpg]
T H E • T H I R D • C A L I B E R • H A S • C U R R E N T L Y • A R R I V E D ! ! ! Big Grin !!

Now encouraging even more positive originality than ever before, and even featuring exclusive QB challenges based on the 2004 Athens Olympic Games, too!!! ;*) !

Got game for the QuickBASIC Caliber Programming Compo 2004/2005? Then I challenge you to please visit http://dhost.hopto.org/aapproj/qbcpc/. That means YOU, pal! Wink
Adigun:
Your example submission does'nt abide by the rules, so it should be diaqualified.

Code:
4 PRINT "   " + CHR$(176) + CHR$(177) + CHR$(178) + CHR$(219) + CHR$(219) + CHR$(178) + CHR$(177) + CHR$(176) + "                                " + CHR$(176) + CHR$(177) + CHR$(178) + CHR$(219) + CHR$(219) + CHR$(178) + CHR$(177) + CHR$(176)
5 X = (INT(RND(1) * 25) + 1)

You used space chars , so you don't fullfill rule nr 7.
Wow... i think i got epilepsy after running that in full screen. O_O *dizzy*
dizzy :o

x.x
To all of you that replied:

I am *very* sorry about my first example causing some epilepsy and dizziness problems. Sad That is why from my opening post of this thread, I have just today changed the example to my brand-new one to fix the problem. Big Grin !



And to you, Antoni:

You are absolutely right about the space marks and stuff, so thank you very much for spotting that error. :wtnod: ! You know, according to the rules that I have placed up there, the output of the space marks are sure grounds for disqualification here, so, I appreciate your helpful support here!! Cool



See you all later, and enjoy yourselves!!



[Image: AAPname.gif]
- Adigun Azikiwe Polack
One of the Founders of “Aura Flow”
Continuing Developer of “Frantic Journey”
Current Developer of “Star Angelic Slugger”
Webmaster of the “AAP Official Projects Squad”
Here you go. This is my first submission. Wrote it at work, so don't expect much. ^_^

EDIT: I recognize that if you let this program run a very long time you could theoretically overflow the char.x& and char.y& variables just on random chance. However, I wanted to submit this quickly and didn't have the time to put a cap check on the first two lines of the program.

*peace*

Meg.

Code:
'Seven Line Screensaver (submission #1)
'written 09/20/2004 Meg Berry

1 char.x& = char.x& + INT(RND * 3) - 1
2 char.y& = char.y& + INT(RND * 3) - 1
3 char.n& = INT(RND * 3) + 176
4 LOCATE 1 + ABS(char.y& MOD 24), 1 + ABS(char.x& MOD 80)
5 COLOR INT(RND * 2) + SQR(ABS((1 + ABS(char.y& MOD 24)) - 12) ^ 2 + ABS((1 + ABS(char.x& MOD 80)) - 40) ^ 2) \ 3
6 PRINT CHR$(char.n&);
7 IF INKEY$ = "" THEN GOTO 1

Adigun, if I may make a comment on your code:

Quote:1 WIDTH 80, 50
2 COLOR 8, 0
3 x = INT(RND(1) * 78) + 1
4 y = INT(RND(1) * 48) + 1
5 LOCATE y, x
6 IF INT(RND(1) * 4) + 1 = 1 THEN PRINT CHR$(176) ELSE IF INT(RND(1) * 4) + 1 = 2 THEN PRINT CHR$(177) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(178) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(219)
7 GOTO 2

you could combine lines 3-5 into one line:
Code:
LOCATE INT(RND(1) * 48) + 1, INT(RND(1) * 78) + 1

This would free up two lines of program to use for something else!
Quote:To all of you that replied:

I am *very* sorry about my first example causing some epilepsy and dizziness problems.


Dont worry man, the screen saver was fine, just running so fast it made me dizzy. Nothing wrong with it though! Keep up the good work, in programming and in setting us all challenges =)

Meg: Well spotted Wink
To Dark_prevail:

Thank you so much on that, my man, as it is truly such an honor to have you and others like that around here!! ^_- !



And going now to you, Meg:

Quote:Adigun, if I may make a comment on your code:

Quote:1 WIDTH 80, 50
2 COLOR 8, 0
3 x = INT(RND(1) * 78) + 1
4 y = INT(RND(1) * 48) + 1
5 LOCATE y, x
6 IF INT(RND(1) * 4) + 1 = 1 THEN PRINT CHR$(176) ELSE IF INT(RND(1) * 4) + 1 = 2 THEN PRINT CHR$(177) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(178) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(219)
7 GOTO 2

you could combine lines 3-5 into one line:
Code:
LOCATE INT(RND(1) * 48) + 1, INT(RND(1) * 78) + 1

This would free up two lines of program to use for something else!

Wow, YOU’RE REALLY CLEVER! I mean, it is such awesome strategies like yours that will no doubt help and even inspire people to create even more spectactular 7-liners of this kind that I am currently talking about, so *very* splendidly done for you now!!! d=^-^=b !

(As for your first 7-line submission, Meg, all you forgot to do was to describe to me in the remark line(s) what your thing was all about, so could you correct your code a little bit with that before I accept your entry, okay please? Thanks so much!!)



See you both once again, and to the rest of you, I will welcome your creative entries (just be sure to read the rules of this challenge *first* at the beginning of this thread before you contribute one, please!). Once again, best of ace coding to you all!! ;*)



[Image: AAPname.gif]
- Adigun Azikiwe Polack
One of the Founders of “Aura Flow”
Continuing Developer of “Frantic Journey”
Current Developer of “Star Angelic Slugger”
Webmaster of the “AAP Official Projects Squad”
Hah! In my 7-line submission, lines 3 and 6 are redundant! >:D Now I have another line to work with :)

*peace*

Meg

EDIT:

Adigun, I've been looking at both of our programs, and finding ways to optimize them and free up more lines.

Your initial program:
Quote:1 WIDTH 80, 50
2 COLOR 8, 0
3 x = INT(RND(1) * 78) + 1
4 y = INT(RND(1) * 48) + 1
5 LOCATE y, x
6 IF INT(RND(1) * 4) + 1 = 1 THEN PRINT CHR$(176) ELSE IF INT(RND(1) * 4) + 1 = 2 THEN PRINT CHR$(177) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(178) ELSE IF INT(RND(1) * 4) + 1 = 3 THEN PRINT CHR$(219)
7 GOTO 2

Can be recoded like this:
Code:
1 WIDTH 80, 50
2 COLOR 8, 0
3 LOCATE INT(RND * 48) + 1, INT(RND * 78) + 1
4 PRINT MID$("░▒▓█", INT(RND * 4) + 1, 1);
5 GOTO 3

The four characters in the string there are CHR$(176), CHR$(177), CHR$(178), and CHR$(219) but I'm not sure they display correctly.

I'm working on an updated submission that uses these changes, as well.

EDIT: This is my most current program
Code:
'7-line screensaver (submission #2)
'This program crawls around the screen displaying one of four characters.
'Color is either randomly black or is selected by formula which determines
'the location's distance from the center of the screen.

'change the x and y coordinate by random values (-1, 0, +1)
1 char.x& = char.x& + INT(RND * 3) - 1
2 char.y& = char.y& + INT(RND * 3) - 1

3

'locate the x and y coordinates on the screen.  Allow for wrap-around.
4 LOCATE 1 + ABS(char.y& MOD 24), 1 + ABS(char.x& MOD 80)

'set the color
5 IF INT(RND * 50) = 0 THEN COLOR 0 ELSE COLOR INT(RND * 2) + SQR(ABS((1 + ABS(char.y& MOD 24)) - 12) ^ 2 + ABS((1 + ABS(char.x& MOD 80)) - 40) ^ 2) \ 3

'print a random character
6 PRINT MID$("░▒▓█", INT(RND * 4) + 1, 1);

'exit if a key is hit, otherwise a delay/loop
7 IF INKEY$ <> "" THEN SYSTEM ELSE IF INT(RND * 1000) = 0 THEN GOTO 1 ELSE GOTO 7

This still has line 3 free. Not sure what to do with it, yet.
This is another 6-liner, but it's really cramming a lot of stuff onto a few lines.

Code:
'7-Line Screensaver (Submission #3)
'This program uses two huge IF/ELSE lines to perform multiple commands
'per line.  It uses SCREEN 13 and sets up a green fading palette to display
'the four allowed characters.  The location crawls about the screen and the
'color fades from black to bright green.
'
'Written by Meg Berry 09/21/2004

'randomize timer, set screen mode, setup pallette
1 IF i% = 0 THEN RANDOMIZE TIMER ELSE IF i% = 1 THEN SCREEN 13 ELSE IF i% = 3 THEN CLS  ELSE IF i% >= 4 AND i% <= 259 THEN OUT &H3C9 + ((i% MOD 4) = 0), -((i% MOD 2) = 0) * (i% \ 4 - 1) ELSE IF i% = 260 THEN x& = 20 ELSE IF i% = 261 THEN y& = 12  ELSE IF i% = 262 THEN c& = 30
2 i% = i% + 1
3 IF i% < 263 THEN GOTO 1

'adjust x%, y%, and c%; locate screen position, change color, print character
4 IF j% = 0 THEN x& = x& + INT(RND * 3) - 1 ELSE IF j% = 1 THEN y& = y& + INT(RND * 3) - 1 ELSE IF j% = 2 THEN LOCATE 1 + ABS(y& MOD 24), 1 + ABS(x& MOD 40) ELSE IF j% = 3 THEN c& = c& + INT(RND * 5) - 2 ELSE IF j% = 4 THEN COLOR ABS(c& MOD 64) ELSE IF j% = 5 THEN PRINT MID$("░▒▓█", INT(RND * 4) + 1, 1);
5 IF j% < 5 THEN j% = j% + 1 ELSE j% = 0
6 IF INKEY$ <> "" THEN SYSTEM ELSE IF INT(RND * 1000) = 0 THEN GOTO 4 ELSE GOTO 6

EDIT: Adigun, using this "counter" IF/ELSE method, you could rewrite your original program in just 3 lines:
Code:
1 IF i = 0 THEN WIDTH 80, 50 ELSE IF i = 1 THEN COLOR 8, 0 ELSE IF i = 2 THEN LOCATE INT(RND * 48) + 1, INT(RND * 78) + 1 ELSE IF i = 3 THEN PRINT MID$("░▒▓█", INT(RND * 4) + 1, 1);
2 IF i < 3 THEN i = i + 1 ELSE i = 2
3 GOTO 1

c(>.³)b

*peace*

Meg.
Pages: 1 2 3