How to resolve the algorithm Peano curve step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Peano curve step by step in the Action! programming language

Table of Contents

Problem Statement

Produce a graphical or ASCII-art representation of a Peano curve of at least order 3.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Peano curve step by step in the Action! programming language

Source code in the action! programming language

DEFINE MAXSIZE="12"

INT ARRAY
  angleStack(MAXSIZE)
BYTE ARRAY
  depthStack(MAXSIZE),stageStack(MAXSIZE)
BYTE stacksize=[0]

BYTE FUNC IsEmpty()
  IF stacksize=0 THEN RETURN (1) FI
RETURN (0)

BYTE FUNC IsFull()
  IF stacksize=MAXSIZE THEN RETURN (1) FI
RETURN (0)

PROC Push(INT angle BYTE depth,stage)
  IF IsFull() THEN Break() FI
  angleStack(stacksize)=angle
  depthStack(stacksize)=depth
  stageStack(stackSize)=stage
  stacksize==+1
RETURN

PROC Pop(INT POINTER angle BYTE POINTER depth,stage)
  IF IsEmpty() THEN Break() FI
  stacksize==-1
  angle^=angleStack(stacksize)
  depth^=depthStack(stacksize)
  stage^=stageStack(stacksize)
RETURN

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

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

PROC DrawPeano(INT x BYTE y,len BYTE depth)
  BYTE stage
  INT angle=[90],a
  
  Plot(x,y)
  Push(90,depth,0)

  WHILE IsEmpty()=0
  DO
    Pop(@a,@depth,@stage)
    IF stage<3 THEN
      Push(a,depth,stage+1)
    FI
    IF stage=0 THEN
      angle==+a
      IF depth>1 THEN
        Push(-a,depth-1,0)
      FI
    ELSEIF stage=1 THEN
      x==+len*Cos(angle)
      y==-len*Sin(angle)
      DrawTo(x,y)
      IF depth>1 THEN
        Push(a,depth-1,0)
      FI
    ELSEIF stage=2 THEN
      x==+len*Cos(angle)
      y==-len*Sin(angle)
      DrawTo(x,y)
      IF depth>1 THEN
        Push(-a,depth-1,0)
      FI
    ELSEIF stage=3 THEN
      angle==-a
    FI
  OD
RETURN

PROC Main()
  BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6

  Graphics(8+16)
  Color=1
  COLOR1=$0C
  COLOR2=$02

  DrawPeano(69,186,7,6)

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

  

You may also check:How to resolve the algorithm Loops/Wrong ranges step by step in the Java programming language
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the J programming language
You may also check:How to resolve the algorithm Use another language to call a function step by step in the Rust programming language
You may also check:How to resolve the algorithm Take notes on the command line step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the EchoLisp programming language