Exercises

The purpose of these exercises is to improve your programming skills or just do them for fun! Why you ask?  Many programmers started making their first programs in BASIC and making new programs in BASIC brings back so many beautiful memories. 

I’ll try to make things simple and I’ll add more hints by time.

I’ll be happy to receive your feedback.

The first exercise is a challenging one (well, at least in respective to other exercises), and requires some mathematical capabilities.

Exercise 1: 3d Plotter

Sample program PLOT2D.BAS plots 2d functions. Make a similar program that draws 3d functions as grid. Something like:

y =  y(x, z) = a x^n + b  z^m + c

here a, b,  n and m are some non-zero constants. (in general you could use polynomials for x and z)

The idea is simple first you need to be able to map a 3d point (x, y, z) into 2d space (x, y). Then loop to draw the grid line by line.

I remember my first 3d plotter. It was written in BASIC with Z80 CPU (3.58MHz) and it takes around 20 min to finish drawing with reasonable quality. But using new high-end mobile processers, I expect it will take less than two minutes with good quality.

Exercise 2: Ball collision

Sample BOUNCE.BAS simulates moving only one ball. 

Make another moving ball. 

What if the two balls overlap? shouldn't they  collide? 

Make collision detection and make the two balls react.

Collision detection of two balls is simple, check if the two circles overlap. This can be calculated: the distance between the center of the two circles is less than the sum of the radius of the two circles.

Reacting to ball collision could be as simple as reversing the moving direction of the balls. Advanced methods use Physics (Kinematics) Laws.

Make the user set how many balls he wants before starting simulation (without collision)

Exercise 3: 2D Polar Plotter

Make a program to plot polar functions of the form r = f(theta)

where r is the radius, theta is the angle, and f() is some polar function.

Exercise 4: Quiz update

Rewrite Quiz example so that the questions and answers are read from external file. Make another program that helps you to add/remove/update questions.

Exercise 5: Improve PAINT.BAS example

This example allows you to draw lines and dots. Add functionality that allow you to save/load the painting. Enable the user to select drawing color and the option to clear the painting.

FILEIO.BAS is a good place to start learning how to read/write data from/to files.

Good Luck!

More Exercises to come....