CODINGLISTINGS ★ DEG those SINs! ★

Circle of Triangles (Computing with the Amstrad)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 ★ 

THIS month we take a look at drawing a circle of triangles. It's not complicated, but it does show how to use functions such as SIN, COS and DEG. And if you think relative drawing is producing a portrait of your aunt, you'd better read on.

  • 10,20 REMs to identify the program and the culprit who's responsible.
  • 30 Puts the Amstrad in the high resolution mode. Try the program in Modes 0 and 1 and see the difference.
  • 40 Ensures that the trigonometric functions used later take their values measured in degrees, not radians. This makes the following FOR ... NEXT loop easier for humans to understand.
  • 50 Moves the origin - the point whose coordinates the graphics commands take as 0,0 - to the centre of the screen.
  • 60-100 Form a FOR ... NEXT loop with control variable angle. The STEP command of 15 ensures that the loop will cycle 24 times as angle goes from 0 to 360.
  • 70 Uses the SIN function with argument angle to calculate the X coordinate of a point of a circle and store the result in x. The circle is centred on the origin and has radius 100.
  • 80 Makes use of COS to find the corresponding Y coordinate and stores it in y. As angle goes from 0 to 360, these two lines will calculate a set of 24 points on the circle's circumference.
  • 90 Calls the subroutine which draws triangles at the point x,y. This line is obeyed each time round the loop, so 24 triangles are drawn in all.
  • 110 Stops the main program crashing into the subroutine definition.
  • 120-170 Make up the triangle drawing routine. Try changing it to create other shapes.
  • 130 MOVEs the graphics pen to the point on the edge of the circle with coordinates x,y. No line is drawn.
  • 140 The DRAWR command causes the graphics pen to DRAW Relative to the previous coordinate. In this case the previous coordinate is x,y. A line is drawn from this point to a point whose X coordinate is 25 units along the X axis from x,y and whose Y coordinate is 25 units further along the Y axis from x,y. The result is that the line is drawn to the point with absolute coordinates x+25, y+25.
  • 150 Here, again, a line is drawn relative to the previous point. This time the difference in the X coordinate is 25, in the Y coordinate -25.
  • 160 The third line of the triangle is now drawn. If you add up all the relative X and Y coordinates of the three DRAWRs, you'll find that they come to zero. This means that the first point and the final point are the same. If you can't see the difference, try changing all the DRAWRs to DRAW and the Amstrad will show you!
  • 170 Rnishes the subroutine, sending the program back to the line after the one that called it.

CWTA

★ PUBLISHER: Computing With The Amstrad
★ YEAR: 1986
★ CONFIG: ???
★ LiCENCE: LISTING
★ COLLECTION: COMPUTING WITH THE AMSTRAD 1986
★ AUTHOR: Trevor Roberts
 

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Circle  of  Triangles    (Computing  with  the  Amstrad)    ENGLISHDATE: 2020-07-23
DL: 182
TYPE: ZIP
SiZE: 4Ko
NOTE: 40 Cyls
.HFE: Χ

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

Lien(s):
» Coding Src's » Rotating triangle
» Coding Src's » Circles
» Coding Src's » Graphic - Circle (The Amstrad User)
» Coding Src's » Triangles (Dale Clinton)
» Coding Src's » Escher's Triangle (CPC Computing)
» Coding Src's » Graphic - Circle Writer (Amstrad Computer User)
Je participe au site:
» 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 364 millisecondes et consultée 853 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.