The purpose of this task is to explore working with   complex numbers.



Task

Given   n,   find the   nth   roots of unity.




WindowWidth  =400
WindowHeight =400
 
'nomainwin
 
open "N'th Roots of One" for graphics_nsb_nf as #w
 
#w "trapclose [quit]"
 
for n =1 To 10
    angle =0
    #w "font arial 16 bold"
    print n; "th roots."
    #w "cls"
    #w "size 1 ; goto 200 200 ; down ; color lightgray ; circle 150 ; size 10 ; set 200 200 ; size 2"
    #w "up ; goto 200 0 ; down ; goto 200 400 ; up ; goto 0 200 ; down ; goto 400 200"
    #w "up ; goto 40 20 ; down ; color black"
    #w "font arial 6"
    #w "\"; n; " roots of 1."
 
    for i = 1 To n
        x = cos( Radian( angle))
        y = sin( Radian( angle))
 
        print using( "##", i); ":  ( " + using( "##.######", x);_
          " +i *" +using( "##.######", y); ")      or     e^( i *"; i -1; " *2 *Pi/ "; n; ")"
 
        #w "color "; 255 *i /n; " 0 "; 256 -255 *i /n
        #w "up ; goto 200 200"
        #w "down ; goto "; 200 +150 *x; " "; 200 -150 *y
        #w "up   ; goto "; 200 +165 *x; " "; 200 -165 *y
        #w "\"; str$( i)
        #w "up"
 
        angle =angle +360 /n
 
    next i
 
    timer 500, [on]
    wait
  [on]
    timer 0
next n
 
wait
 
[quit]
    close #w
 
    end
 
function Radian( theta)
    Radian =theta *3.1415926535 /180
end function