index-bas.htm wywtk.com homepage What You Want To Know  Index to my pages about BBC BASIC

Quick little tutorial- erase a drawing

(Page's URL: bas5-how-to-erase.htm)

This will probably be the shortest "tutorial" in the whole series for a long time.

I hope you will find it easy to understand... but you may need to have worked through the earlier tutorials, from perhaps the start of how to do computer graphics with BBC BASIC for SDL.

This program repeatedly draws a rectangle on the screen... and then erases it.

"The trick"? The rectangles are drawn on a black background. After a rectangle is drawn, and a short WAIT so that the user can see it before it disappears, the "ink" in the "pen" is changed to black, and a black rectangle is drawn over the top of the one that was there before.

There IS a keyword to wipe the whole drawing area clean: CLS ("clear screen"). But what we are doing in the program below is more subtle, and opens the way for a more complicated program in the next essay.

Study the code before you put it in the computer and run it. Can you see what it is doing? (You should be able to! (After a bit of thought, maybe.)

MODE 12
PRINT "One moment please.."
SquaresToDoStill%=4

REPEAT
   REM- don't worry about why the RND stmts
   REM     are so complex.
   x%=10+RND(25)*20
   y%=800+RND(25)*20
   side%=30+RND(18)*20

   GCOL RND(14)+1
   PROC_DoSquare
   WAIT (70)

   GCOL 0
   PROC_DoSquare
   WAIT(50)

   SquaresToDoStill%=SquaresToDoStill%-1
UNTIL SquaresToDoStill%=0
PRINT "Pretty? Goodbye."
WAIT(200)
QUIT

END

REM Subroutine definition....

DEF PROC_DoSquare
MOVE x%,            y%
DRAW x%+side%,y%
DRAW x%+side%,y%+side%
DRAW x%,           y%+side%
DRAW x%,           y%
ENDPROC

That's it!

I said this tutorial would be short. Take a break before starting the next one... it is more demanding!!! It introduces you to arrays, an important type of variable.


A few words from the sponsors...

Please get in touch if you discover flaws in this page. Please mention the page's URL. (wywtk.com/prgm/bas/bas5-how-to-erase.htm).

If you found this of interest, please mention in forums, give it a Facebook "like", Google "Plus", or whatever. If you want more of this stuff, help!? There's not much point in me writing these things, if no one feels they are of any use.



index sitemap
What's New at the Site Advanced search
Search tool (free) provided by FreeFind... whom I've used since 2002. Happy with it, obviously!

Unlike the clever Google search engine, this one merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

Please also note that I have four other sites, and that this search will not include them. They have their own search buttons.

My SheepdogSoftware.co.uk site, where you'll find my main homepage. It has links for other areas, such as education, programming, investing.

My SheepdogGuides.com site.

My SkyWoof.com site.

My site at Arunet.




How to email or write this page's editor, Tom Boyd. Please cite page's URL if you write.


Valid HTML? Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org.

AND tested for... Valid CSS?



(eXTReMe tracker icon) Why is there a script or hidden graphic on this page? I have my web-traffic monitored for me by eXTReMe tracker. They offer a free tracker. If you want to try one, check out their site. Neither my webpages nor my programs incorporate spyware, but if the page has Google ads, they also involve scripts. Why do I mention the script? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....