# Create Unit Circle with its Sin Cos Animation

**URL:** <https://discourse.julialang.org/t/create-unit-circle-with-its-sin-cos-animation/83467>\
**Category:** General Usage\
**Created:** [June 28, 2022, 3:30pm UTC](https://discourse.julialang.org/t/create-unit-circle-with-its-sin-cos-animation/83467 "2022-06-28T15:30:29Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [June 29, 2022, 10:57pm UTC](https://discourse.julialang.org/t/create-unit-circle-with-its-sin-cos-animation/83467/15 "2022-06-29T22:57:27Z")

</div>

I read this:

> [@Discussion on "Why I no longer recommend Julia" by Yuri Vishnevsky](https://discourse.julialang.org/t/discussion-on-why-i-no-longer-recommend-julia-by-yuri-vishnevsky/81151/3):
>
> My suggestion for these issues of correctness and my suggestion for issues of performance/static compilation are basically the same – there should be a Julia “core” (in both Base and in other libraries) that is not at all generic and is essentially C code written in Julia. This code won’t need to cover an infinite set of types (so rigorous testing is feasible) and this code could be trivially statically compiled if the compiler got better because exactly which methods exist and which are called …

I know the MiniFB needs a browser, I use dual boot OS, one(LFS OS) has no browser thus has a problem with MiniFB, one (CAELinux) has standard browser firefox thus can use Pluto.jl and can show the visual window like yours for the simulation.

I just want to show the result without browser, not depending much on browser. Julia REPL and Plots shall be enough. I will try to convert your code from @play

Btw, I try this code and the gif is not showing up:

```julia
using Luxor, MiniFB
if !(@isdefined var"@play")
    include(dirname(pathof(Luxor)) * "/play.jl")
end

let
    w, h = 600, 400

    ntrig = 360
    sinarray = sind.(1:ntrig)
    cosarray = cosd.(1:ntrig)
    i = 1

    @play w h begin
        background("gray"); sethue("white")

        # translate near bottom right corner
        origin(0.8w, 0.8h)
        setline(1); setopacity(1)
        cr = 0.15h
        circle(0, 0, cr, :stroke)
        circle_marker_pos = getworldposition(Point(cr*cosarray[i], cr*sinarray[i]))

        # translate to lower 20%, on the left
        origin(0, 0.8h)
        setline(1); setopacity(1)
        scale(1.0, cr)
        # draw a sin wave
        for j in 1:ntrig-1
            p1 = Point(j, sinarray[mod(j+i, ntrig)+1])
            p2 = Point((j+1), sinarray[mod(j+i+1, ntrig)+1])
            line(p1, p2, :stroke)
        end
        # record the last point of the sin wave
        sin_marker_pos = getworldposition(Point(ntrig,sinarray[mod(ntrig+i, ntrig)+1]))

        # translate to top left corner, then down 20%
        origin(0, 0.2h)
        scale(1.0, cr)
        setline(1); setopacity(1)
        # draw a sin wave
        for j in 1:ntrig-1
            p1 = Point(j, cosarray[mod(j+i, ntrig)+1])
            p2 = Point((j+1), cosarray[mod(j+i+1, ntrig)+1])
            line(p1, p2, :stroke)
        end
        # record the last point of the sin wave
        cos_marker_pos = getworldposition(Point(ntrig, cosarray[mod(ntrig+i, ntrig)+1]))

        # mark the last point of the sin and cos waves
        origin()
        setline(2); setopacity(1);
        circle(sin_marker_pos, 2, :stroke)
        circle(cos_marker_pos, 2, :stroke)
        circle(circle_marker_pos, 2, :stroke)
        # draw connecting lines between the wave and the circle
        setline(1); setopacity(0.5)
        line(sin_marker_pos, circle_marker_pos, :stroke)
        # line(cos_marker_pos, circle_marker_pos, :stroke)

        i %= ntrig
        i += 1
    end
end

begin
function frame(scene, i)
movie = Movie(600, 400, "Lasthrim")
animate(movie, [Scene(demo, frame, 0:359)], creategif=true, pathname = "sincoscircleluxor.gif")
end

```

---

_[View the full topic](https://discourse.julialang.org/t/create-unit-circle-with-its-sin-cos-animation/83467)._
