_TITLE "Line Color Rotation"
' by Charlie Veniot

' 🟠🟠🟠 Initialization

'center position determines screen width and height
  cp = 160
'outer point increments
  opi = 5
'number of lines per screen edge (including only 1 corner )
  nlpse = (cp * 2 / opi)
'total number of lines
  tl = nlpse * 4
  
'array of colours
  DIM this_color(1 TO (tl + 1))
  FOR i = 1 TO tl
    this_color(i) = INT(RND*64) + 1
  next i


' 🟠🟠🟠 Main program

  SCREEN _NEWIMAGE(cp*2+1,cp*2+1, 17)
  
  🏁🏁🏁another_cycle🏁🏁🏁:
    j = 1
    FOR i = 0 TO cp * 2 * 4 - 1 STEP opi
        IF BETWEEN(i, 0, cp*2 - 1) THEN x2 = i : y2 = 0
        IF BETWEEN(i, cp*2, cp*4 - 1) THEN x2 = XMAX : y2 = i - cp*2
        IF BETWEEN(i, cp*4, cp*6 - 1) THEN x2 = XMAX - (i - cp*4) : y2 = YMAX
        IF BETWEEN(i, cp*6, cp*8 - 1 ) THEN x2 = 0 : y2 = YMAX - (i - cp*6)
        LINE (cp,cp) TO (x2,y2), this_color(j)
        j = j + 1 
    NEXT i
    SLEEP 0.075
    ' shift the colors; next draw loop will draw lines in same positions, but colors will be shifted, creating the sensation of animation
    FOR s = tl TO 1 STEP -1
      this_color(s+1) = this_color(s)
    NEXT s
    this_color(1) = this_color(tl+1)
  GOTO 🏁🏁🏁another_cycle🏁🏁🏁