CODINGLISTINGS ★ ART AND THE AMSTRAD (COMPUTING TODAY) ★

Art and the Amstrad (Computing Today)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 ★ 

Two subroutines are provided this month which do clever things on an Amstrad screen Later we'll add other program segments that will result in a high quality drawing package.

OK, I'll come clean. The original plan was to have AmArt complete, whole and in its entirety in this issue. Unfortunately the two routines listed here, which provide a BASIC fill routine and a versatile arc-drawing procedure, involved such quantities of logical thought and O-Level algebra (most of which I had forgotten) that the whole thing couldn't be finished in time. Nevertheless, you can be sure that the finished product will be well worth waiting for.

ARC DE TRIOMPHE

This routine was a real pain to figure out The situation is this: given three non- colinear points, draw the arc of a circle that passes through all three, taking the two outer points as the endpoints of the arc. My first attempt involved a calculation using similar triangles, a small one contained within the arc-segment and the other with a vertex at the centre (unknown) of the required circle. Since one triangle was much smaller than the other, and the screen coordinate system has a finite minimum unit length, rounding errors gave fairly inaccurate results. Back to the school exercise book The next throught that occurred to me was that I had three known x, y coordinate pairs lying on the circle, and three unknowns: the x and y coordinates of the centre of the circle and its radius. Aha! three simultaneous equations in three unknowns; easy.
Don t you believe it

The expansions of the equations and final solution were not one of the most enjoyable tasks T ve undertaken and a daft mistake the first time round meant I had to do it twice. I'll spare you the gory details but the application of the equations can be seen in lines 1020 to 1060 of the program Provided the points are sensibly spaced (and next month's cursor routine will make sure of that), the routine is extremely accurate.

Note that the origin is moved to the centre of the circle before plotting takes place. This is recommended by Amsoft because the drawing routines round pixel coordinates towards the origin, so if this is made the centre of the circle then any possible asymmetry is avoided. The arc is drawn from the first point towards the second point via the third, and since the first point could be either clockwise or anticlockwise from the second, line 1110 makes sure the arc is drawn in the correct direction

The rather complicated expression in line 1000 is required because the ARCTAN function on the Amstrad only returns an angle in the first or fourth quadrants (between +90 and —90 degrees). Adjustment is needed to produce angles in the other two quadrants.

FILLING YOU IN

The fill routine, on the other hand, is not difficult from the mathematical point of view but needs some fairly tight logic to make sure that every point in an arbitrarily complex figure gets filled The approach I took was that any closed shape on the screen consists of a series of horizontal line segments, each one pixel high, with vertically adjacent lines overlapping by at least one pixeL So the problem now is to write one routine to fill any horizontal line segment, and another to identify each segment that has to be filled The first one is easy, and is shown in line2030. The program tests each point along the line segment, moving right until it reaches the edge of the screen or a non-background colour. Then we simply have to move left along the same line, filling pixels with the new colour, until we reach the opposite edge of the screen or another border.

As we move left, filling as we go, we also test the colour of the pixels above and below the line. When we find a pixel of background colour it must be part of a new line that has to be filled later, so we save the point on a 'stack' (actually an array dimensioned large enough to make sure we re unlikely to fill it) for later attention The flags tp and bt (top and bottom) have to be set and reset as shown in lines 2060 to 2090 for two reasons. One, when we add a point to the stack we don't need any other points from that particular segment, so tp and bt are set Two, there may be more than line segment adjacent to a given fill line so when a border colour is found, tp and bt are reset so that possible further lines are not missed As a test I asked two colleagues Jo set tricky fill problems. One suggested a double spiral, the other suggested filling around the words "Pangalactic Gargleblastei''! The routine, although slow, succeeded admirably. Not a point was missed, and the subroutine is guaranteed to fill any shape, however complex and even with internal holes (provided the stack anay doesn't overflow; you could always test the stack pointer value to avoid crashes, or make the array bigger if necessary).

Computing Today

★ PUBLISHER: Computing Today
★ YEAR: 1984
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: K. Smith
 

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Art  and  the  Amstrad    (Computing  Today)    ENGLISH    LISTINGDATE: 2022-07-07
DL: 105
TYPE: PDF
SiZE: 397Ko
NOTE: 1 page/PDFlib v1.6

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Scroll-Bremse
» Applications » Happy-Scroll (Happy Computer)
» Coding Src's » Graphic - Scroll Demo (The Amstrad User)
» Applications » Um Scroll Suave como Seda (Amstrad Magazine)
» Coding Src's » Scrolling Scenery (Computing With the Amstrad)
» Coding Src's » Scroll Text (Duffy / NDC )
Je participe au site:
» Pour ce titre nous ne disposons de fichier executable sur CPC (Saisie du listing) , alors si vous avez ça dans vos cartons ou vous désirez usé vos petit doigts boudinés sur votre clavier faites le nous savoir.
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 220 millisecondes et consultée 385 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.