CODINGLISTINGS ★ Fourier Synthesis ★

Graphic - Fourier Synthesis|Your Computer)Coding Listings
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

The Landscape Creator is a program which creates detailed coloured landscape views, quickly and spontaneously. I developed this idea first on the Spectrum 48K, and now the program has been redesigned to fully exploit the beautiful graphics capability of the Amstrad CPC-464.

It is a simulation of "creativity": the computer makes all decisions relating to a wide range of parameters concerning the hills, trees, flowers, lakes, islands, and buildings. The number of variable parameters is such that the resulting scene gives endless, unexpected surprises with a wide range of possible colour schemes.

I developed this idea because, generally, very little "computer art" is actually generated by the computer. In nearly all cases the computer merely displays the picture, which is arranged by the programmer. We now have graphics packages which make it much easier for the operator to control the results on the screen. However, the result could just as well — or even better — be done with paint on canvas.

It is a much more interesting challenge to get the machine to create its own pictures, based on a "knowledge" of the subject to be portrayed. This involves intricate mathematical modelling, and really begins to unleash the power and the intelligence of the microchip and do things in a way only the computer can.

We have all seen some impressive colour graphics in computer games. In most cases these graphics make extensive use of user defined characters, which are rectangular elements — usually 8 by 8 pixels — used as building bricks. In contrast to this, the use of mathematical functions and probability theory allows us enormously improved flexibility, enabling the spontaneous creation of different scenes, giving endless surprises, even to the programmer!

It is easy enough to write a program to rearrange a number of graphic shapes — say to select a building from a choice of five, choose a mountain from a choice of five, etc. etc. and put them together. But to simulate the idea of "creativity", we need to use a whole hierarchy of routines, building up the picture from the smallest elements, with freedom of choice at every stage in the process. User-defined characters are of limited use in this kind of exercise.

My objective in the Landscape Creator was to have the minimum of fixed quantities: to allow the greatest freedom for variations, without deéparting from some basic properties of landscapes. This same idea I used in Country Cottages, a fun game for two players where you buy cottages and try your skill in managing the awful tenants.

The cottages, the landscapes and the tenants are different every time you play the game. However, the Landscape Creator was designed from scratch, to produce greater variations, better colour schemes, better appearance of water and vegetation.

The number of calculations involved is quite horrendous. Just doing a single pixel involves over 50 machine-code instructions. Though Amstrad Basic is very comprehensive and quite fast, the Landscape Creator has so many calculations to do that machine code was essential.

Routines for plotting

The Amstrad Firmware manual gives the addresses of inbuilt machine-code routines for plotting. These are easy to use and nicely crashproofed — but are therefore not as fast as would be desired. The Landscape Creator utilises its own extremely fast, compact plotting routines. Also the basic arithmetic routines were designed for the job.

In the Landscape Creator, the object was to have the maximum variety of pictures. Whether it is creating a rugged skyline, an island, a patch of buttercups, or a castle, a flexible routine is used which combines probability functions with appropriate mathematics.

The program needs some "knowledge" about the structure of landscapes, so that the different features will have reasonable shapes and fit sensibly together. Trees and buildings must not hang in mid-air; hills must not have enormous holes through them; land must not be drawn when it is below water! Foreground objects may hide more distant objects — not the reverse — and so on. Distant hills could have a grey or bluish colour; whereas the foreground can have much brighter colours.

Lakes and sea can use a mixture of colours reflecting the hills and sky beyond. The precise formulation of the fundamental properties of a landscape is a subjective process — and this is where the art comes in — and the inspiration for this task came from the Highlands of Scotland and also Cumbria.

The Amstrad version of the program displays several advances compared to the Spectrum version. A tremendous advantage of Amstrad graphics is that any pixel can be any colour. You can have 16 colours in Mode 0, with a resolution of 160 pixels horizontally by 200 vertically. For better resolution, Mode 1 gives you 320 horizontally, but only four colours. I chose Mode 0 with its much greater range of colours. If you want better resolution horizontally than vertically, then you could turn the monitor on its side, and swap your x and y axes.

Pixels can be any colour

Whatever mode you select, any pixel can be any of the available colours. This gives enormous freedom compared to most home computers. Foreground features can be drawn with no effect at all on the background colours. The colours actually used on the screen can be chosen from a selection of 27.

Machine code is notoriously difficult to experiment with and so I am providing a simple program in Amstrad Basic for you to try out. It uses the RND function to generate a recipe for a mixture of sine waves with different wavelengths and phrases. The sum of all the different waves is a complex curve which can have enormous variability. It is a well-known method called Fourier Synthesis.

Each waveform here is drawn with a different colour and — Hey Presto! — the Fourier Scries we learned in stuffy lecture theatres comes to life in brilliant colours.

The number of sine waves used in nn. You can try putting in a larger number, say nn=20 or nn = 50. The curve becomes more and more complex — but very much slower. This method is very good for smooth curves, but becomes too cumbersome and slow for very rough crinkly lines.

Next month we will explore more possibilities with the RND function, and also peer into the fascinating world of "fractals", functions which are particularly suitable for describing the very rough mountain skylines we like to gaze upon.

I can supply the Landscape Creator doubly recorded on cassette, for the Amstrad or the Spectrum 48K. Send £5 for the Amstrad version, or £3 for the Spectrum version, to — Brian James.

Your Computer

★ PUBLISHER: Your Computer
★ YEAR: 1985
★ AUTHOR: Brian James

★ AMSTRAD CPC ★ DOWNLOAD ★

Je participe au site:
» Newfile(s) upload/Envoye de fichier(s)
★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Coding Src's » Physikprogramm Ph 10.6 (CPC Amstrad International)
» Coding Src's » Singer (Amstrad Computer User)
» Coding Src's » Zeichenroutine fur Kreise und Ellipsen
» Coding Src's » Graphic - Wave Interference (Popular Computing Weekly)
» Coding Src's » Graphic - Rosette (CPC Amstrad International)
» Coding Src's » Rotating Polygons (Computing with the Amstrad)

QUE DIT LA LOI FRANÇAISE:

L'alinéa 8 de l'article L122-5 du Code de la propriété intellectuelle explique que « Lorsque l'œuvre a été divulguée, l'auteur ne peut interdire la reproduction d'une œuvre et sa représentation effectuées à des fins de conservation ou destinées à préserver les conditions de sa consultation à des fins de recherche ou détudes privées par des particuliers, dans les locaux de l'établissement et sur des terminaux dédiés par des bibliothèques accessibles au public, par des musées ou par des services d'archives, sous réserve que ceux-ci ne recherchent aucun avantage économique ou commercial ». Pas de problème donc pour nous!

CPCrulez[Content Management System] v8.7-desktop/cache
Page créée en 903 millisecondes et consultée 545 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.