Very basic BASIC: drawing tilted ellipses (Commodore 64)

Following a request by a reader (Kick Off), I have had a quick look at how to draw tilted ellipses. Since I’m having not much spare time available lately, I am only going to present a very simple BASIC V2 implementation. Of course, assembly is much more suitable for graphics, but machine language coding takes a lot more time to me.

My reader suggested this problem: drawing an atom. So, we will have to draw the nucleus, the electrons and their orbits. At the moment, we will only deal with a static drawing, so no animation.

As a BASIC V2 project, even if we keep things simple, it is not that straightforward. Orbits may be represented by tilted ellipses. But drawing ellipses is quite slow in BASIC V2, and drawing tilted ellipses is even slower.

However, we are not interested on speed now: we just have to grasp the principles. Then, those interested on coding a machine language implementation will find useful information on this blog if they need it. The “Sphere” program is a good starting point I believe.

 

Math formulas required

For our program, we are going to use the parametric equations of a tilted ellipse:

\[ x(a)=R_{1} \cdot cos(a)cos(\theta)-R_{2} \cdot sin(a)sin(\theta) \]

\[ y(a)=R_{1}\cdot cos(a)sin(\theta)+R_{2}\cdot sin(a)cos(\theta) \]

where:

​​\( a \in [0, \: 2 \pi] \)​ is the angle used to draw the ellipse. Each point of the ellipse matches a value of this angle. So, this angle obviously keeps changing while the ellipse is being drawn.

\( \theta \)​: this angle tells us how much the ellipse is tilted. While drawing each ellipse, this angle doesn’t change.

 

BASIC V2 implementation

The above formulas are quite heavy for BASIC and they do take a lot of time for computations. On a machine language implementation, Werner’s formulas can be of help. But with BASIC, if we use them to reduce the number of multiplications, things get even slower. So, we will keep the formulas in this form. We only need to add the X, Y center coordinates of the bitmap screen to the terms. This is done in the code.

Instead of drawing each ellipse on a single FOR… NEXT cycle, we will precalculate a small number of points, then we will draw them. Once they are drawn, we will precalculate another set of points and we will draw it, and so on. Plotted points will be quite distant from one another: this way, even if we plot very few points at the beginning, the shape of the ellipse will be already evident. Then, as soon as we plot more points, they will get closer and closer, and the ellipse will “soon” reveal its final shape.

This approach makes the slowness of BASIC V2 hi-res graphics routines more acceptable. Of course, if you are using an emulator, warp-mode really helps anyway.

 

The program

You can download my simple experiment here:

DOWNLOAD: atom drawing (Commodore 64, BASIC V2)

Here is how this weird atom looks:

 

To make things simple, I have only used bitmap mode. Sprites may be an option on an improved version.

The drawing is made up of six ellipses and makes heavy use of mirroring techniques to improve performances. Still, please consider that this program is more for concepts than for speed (so, you are advised to use warp mode). The program takes a couple of minutes to complete.

The two last ellipses drawn by the program are not tilted and could be drawn by using simpler formulas. Still, I wanted to test the formulas above for horizontal and vertical ellipses as well.

Circles are drawn by using an algorithm from Commodore Hacking, issue 9.

A cheap and easy way to draw pseudo-filled circles is to just draw several concentric circumferences very close to each other. This is what the program does. There is some discontinuity, but it may be acceptable and after all, it acts as a sort of “shading”. Since circles are small, this rude technique works decently here.

NOTE: once this program has been executed, please turn your machine off then back on before attempting loading another program. This is required since pointers are changed to clear the bitmap screen fast. This is also the case with my other BASIC V2 bitmap graphics programs.

 

A better use of symmetry

The following improved version will make a better use of symmetry:

DOWNLOAD: atom drawing V2 (BASIC V2, Commodore 64)

As you can see, now the last two ellipses are also drawn at the same time. If you have an object with X (or Y) axis symmetry, you can obtain the same object with Y (or X) symmetry by simply swapping X and Y coordinates of points.

Please note that center points coordinates must be adjusted while performing that kind of swap. This is accomplished in line 436.

6 Replies to “Very basic BASIC: drawing tilted ellipses (Commodore 64)”

  1. Wow!!! You are a Great Retro64!! So the image is a static on the screen? Well, doesn’ matter, is always an good job, because i like this method. Anyway i would like animation also. Thank regards.

    1. Hello, I’m glad you like my program, although it’s a very simplified version. When I’ll have more time, I’ll do something closer to your idea 🙂 And thank you for your idea, it has been a nice little project to do. Bye!

  2. Hi retro64. I’m glad too… I leave my second e-mail, because i have a problems to access with my first e-mail:(*****) :-((

    1. Sorry me my e-mail is kickoff073@[no-spam]libero.it (this is work!) But the another e-mail: kickoff073@[no-spam]virgilio.it (is suffered to the access login for me).

  3. Hi retro64, i just tried the your program drawing_atom.d64. Well, is awesome. But i have a problems, so i would like send my e-mail with my modified program to you. You will find the screenshots from my c64 computer and my sheet programma Also inside.

  4. Hi retro64, i just tried the your program drawing_atom.d64. Well, is awesome. But i have a problems, so i would like send my e-mail with my modified program to you. You will find the screenshots from my c64 computer and my sheet programma Also inside.

    Ciao retro64, ho appena provato il tuo programma drawing_atom.d64. Bene, è fantastico. Ma ho un problema, quindi vorrei inviarti la mia e-mail con il mio programma modificato. Troverai gli screenshot dal mio computer c64 e il mio programma Anche all’interno.

Leave a Reply

Your email address will not be published. Required fields are marked *

Insert math as
Block
Inline
Additional settings
Formula color
Text color
#333333
Type math using LaTeX
Preview
\({}\)
Nothing to preview
Insert