How to resolve the algorithm Draw a sphere step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Draw a sphere step by step in the Action! programming language

Table of Contents

Problem Statement

Draw a sphere. The sphere can be represented graphically, or in ASCII art, depending on the language capabilities. Either static or rotational projection is acceptable for this task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Draw a sphere step by step in the Action! programming language

Source code in the action! programming language

INT ARRAY SinTab=[
  0 4 9 13 18 22 27 31 36 40 44 49 53 58 62 66 71 75 79 83
  88 92 96 100 104 108 112 116 120 124 128 132 136 139 143
  147 150 154 158 161 165 168 171 175 178 181 184 187 190
  193 196 199 202 204 207 210 212 215 217 219 222 224 226
  228 230 232 234 236 237 239 241 242 243 245 246 247 248
  249 250 251 252 253 254 254 255 255 255 256 256 256 256]

INT FUNC Sin(INT a)
  WHILE a<0 DO a==+360 OD
  WHILE a>360 DO a==-360 OD
  IF a<=90 THEN
    RETURN (SinTab(a))
  ELSEIF a<=180 THEN
    RETURN (SinTab(180-a))
  ELSEIF a<=270 THEN
    RETURN (-SinTab(a-180))
  ELSE
    RETURN (-SinTab(360-a))
  FI
RETURN (0)

INT FUNC Cos(INT a)
RETURN (Sin(a-90))

PROC Ellipse(INT x0,y0,rx,ry)
  INT i
  CARD x
  BYTE y

  x=x0+rx*Sin(0)/256
  y=y0+ry*Cos(0)/256
  Plot(x,y)
  FOR i=5 TO 360 STEP 5
  DO
    x=x0+rx*Sin(i)/256
    y=y0+ry*Cos(i)/256
    DrawTo(x,y)
  OD
RETURN

PROC Main()
  BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
  INT cx=[160],cy=[96],r=[90],r2
  BYTE i
  
  Graphics(8+16)
  COLOR1=$0C
  COLOR2=$02
  Color=1

  Ellipse(cx,cy,r,r)
  FOR i=10 TO 90 STEP 10
  DO
    r2=r*Cos(i)/256
    Ellipse(cx,cy,r,r2)
    Ellipse(cx,cy,r2,r)
  OD

  DO UNTIL CH#$FF OD
  CH=$FF
RETURN

  

You may also check:How to resolve the algorithm Catalan numbers step by step in the Pascal programming language
You may also check:How to resolve the algorithm GSTrans string conversion step by step in the Wren programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the PHP programming language
You may also check:How to resolve the algorithm Sorting algorithms/Patience sort step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm State name puzzle step by step in the J programming language