School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,181 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,614 people online right now. Registration is fast and FREE... Join Now!




> FreeBASIC graphics tutorial, An introduction to graphics in freeBASIC

paperclipmuffin
Group Icon



post 7 May, 2009 - 11:21 PM
Post #1


Paperclip Muffin's freeBASIC tutorial: Graphics
- - - - - -
Hi, and welcome to my first freeBASIC tutorial.
Why another freeBASIC tut, you ask? Well, although there are many out there, they are all either ultra-beginner for the "Hello, World!" program or assume you are a veteran and go straight into great detail. This, however, is different. I will assume you know the basics of BASIC, but only the basics. Here I will explain the stuff you need to know in this tutorial
gap. However, rapidly moving on...
- - - - - -
*-=THE ACTUAL TUTORIAL=-*
Before you can add graphics to your program, you need to set your screen mode. This can be done very easily:
CODE

screen 13

The SCREEN means graphics mode.

SCREEN 0 Sets the screen mode to text mode

SCREEN 1 Sets the screen mode to graphics mode 320x200 with 4 colours (!!!)

SCREEN 2 Sets the screen mode to monochrome (only two colours!!!) graphics mode 640x200

SCREEN 7 Sets the screen mode to graphics mode 320x200 with 16 colours (very useful in the past)

SCREEN 8 Sets the screen mode to graphics mode 640x200 with 16 colours (not as useful)

SCREEN 9 Sets the screen mode to graphics mode 640x350 with 16 colours (VERY useful in the past)

SCREEN 11 Sets the screen mode to graphics mode 640x480 with 2 colours (blue and black ????)

SCREEN 12 Sets the screen mode to graphics mode 640x480 with 16 colours

SCREEN 13 Sets the screen mode to graphics mode 320x200 with 256 colours!

SCREEN 13…21 These set the screen mode to graphics mode with at least 320x240 with 256 colours. You can also specify how many bits per pixel there are.


Now let's add something a lot more exciting:
CODE

screen 13
circle (150,100),8
sleep

Here we tell the computer to draw a circle at coordinates 150x100, which is the centre on the 300x200 screen, and it will
have a diameter of 8. Then sleep. Pretty simple, eh? Let's spice it up a bit:
CODE

screen 13
circle (150,100),20,2
circle (150,100),10,3
sleep

Now we have COLOUR! The 2 and 3 determine the colour of our circles. Try making your own program with more, differently
coloured circles.
Finally, the grand finale. We will create a circle-text hybrid program with input. Behold:
CODE

screen 13
    do
    circle (42,155),22,2
    locate 20, 5
    print "Press t"
loop until inkey()="t"
do
    circle (100,155),22,3
    locate 20, 10
    print "Now press y"
loop until inkey()="y"
do
    circle (158,155),22,4
    locate 20, 19
    print "Now u"
loop until inkey()="u"
    circle (218,155),22,5
    locate 20, 26
    print "Okey Dokey!"
sleep

Locate will put any text you then request to be printed at a particular point on the computer screen. Cool, huh? However, a flaw in this approach is that the locate coordinates are different to and sometimes do not match the
circle coordinates. Now you know about screen, circle and locate you can fool about and make your own graphical programs in freeBASIC.
Good luck! wink2.gif

This post has been edited by paperclipmuffin: 13 May, 2009 - 11:53 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!




Fast ReplyReply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 07:43PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month