Primeri

# Nazarathy and Klok, Listing 1.12
using Plots; pyplot()

function graphCreator(n::Int)
   vertices = 1:n
   complexPts = [exp(2*pi*im*k/n) for k in vertices]
   coords = [(real(p),imag(p)) for p in complexPts]
   xPts = first.(coords)
   yPts = last.(coords)
   edges = []
   for v in vertices, u in (v+1):n
      push!(edges,(v,u))
   end

   anim = Animation()
   scatter(xPts, yPts, c=:blue, msw=0, ratio=1,
      xlims=(-1.5,1.5), ylims=(-1.5,1.5), legend=:none)

   for i in 1:length(edges)
      u, v = edges[i][1], edges[i][2]
      xpoints = [xPts[u], xPts[v]]
      ypoints = [yPts[u], yPts[v]]
      plot!(xpoints, ypoints, line=(:red))
      frame(anim)
   end

   gif(anim, "D:\\julia\\test\\graph.gif", fps = 60)
end

graphCreator(16)
include("D:/julia/test/GphAnim.jl")



notes/jl/ex1.txt · Last modified: 2021/03/17 05:30 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki