Spinning rod animation/Text

From Rosetta Code
Spinning rod animation/Text is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

An animation with the following frames in the following order must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared before the next frame appears:

  • |
  • /
  • -
  • \

A version that loops and/or a version that doesn't loop can be made.

C Shell

<lang csh>while 1

 foreach rod ('|' '/' '-' '\')
   printf '  %s\r' $rod; sleep 0.25
 end

end</lang> (Added an indent in the printf to better see the spinning rod).

Go

Works with: Ubuntu 16.04

<lang go>package main

import (

   "fmt"
   "time"

)

func main() {

   a := `|/-\`
   fmt.Printf("\033[?25l")  // hide the cursor
   start := time.Now()
   for {
       for i := 0; i < 4; i++ {
           fmt.Print("\033[2J")       // clear terminal
           fmt.Printf("\033[0;0H")    // place cursor at top left corner
           for j := 0; j < 80; j++ {  // 80 character terminal width, say
               fmt.Printf("%c", a[i])
           }
           time.Sleep(250 * time.Millisecond)
       }
       if time.Since(start).Seconds() >= 20.0 { // stop after 20 seconds, say
           break
       }
   }
   fmt.Print("\033[?25h") // restore the cursor

}</lang>

Microsoft Small Basic

<lang microsoftsmallbasic>a[1]="|" a[2]="/" a[3]="-" a[4]="\" b=0 While b=0

 For c=1 To 4
   TextWindow.Clear()
   TextWindow.WriteLine(a[c])
   Program.Delay(250)
 EndFor

EndWhile</lang>


zkl

<lang zkl></lang> <lang zkl></lang>

Output: