Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.57 KB | None | 0 0
  1. # bigbang.jl  a utility for the Space Commander game
  2.  
  3. using JSON
  4.  
  5. cfgfile = "data/bigbang.json"
  6. LY = 9460730472580800  # light year in meters (exact)
  7.  
  8. macro OK() @printf("\e[128C\e[4D\e[0m[\e[1;32mOK\e[0m]\n") end  # [OK]
  9.  
  10. @printf("\n\e[1;31mbigbang.jl \e[30mfor \e[34mSpace Commander\e[0m\n\n")
  11. print("Searching for configs...")
  12.                                                 # Galaxy Name
  13. # Read in the data file and get the configs     # Origin System
  14.                                                 # Home World
  15. bbcfg = Dict()                                  # Creator
  16. try                                             # Systems
  17.     open(cfgfile, "r") do f                     # Planets
  18.         global bbcfg                            # Galaxy Size
  19.         bbcfg=JSON.parse(readstring(f))         # Spiral Arms
  20.         @OK                                     # Variance
  21.     end                                         # Chaos
  22. catch
  23.     @printf("\e[1;31mError: %s not found. Running GUI... ", cfgfile)
  24.     run(`./bigb5`)
  25.     exit()
  26. end
  27. @printf("Read %s :: \e[1;33mVersion %d", cfgfile, bbcfg["Version"]); @OK
  28. print("Loading functions... ")
  29.  
  30. function discus()  # return [x,y,z]  attempts to make an elliptical blob
  31.     s = rand()*bbcfg["Galaxy Size"]
  32.     a = 2π * rand()
  33.     b = (π/2 * exp(-0.07*s) * rand()) * rand([-1,1])
  34.     r = [cos(b)*cos(a), cos(b)*sin(a), sin(b)] * s * LY
  35.     return r
  36. end
  37.  
  38. @OK
  39. @printf "Generating %s points... " bbcfg["Systems"]
  40. points = Array{Float64}(bbcfg["Systems"],3)
  41. for i in 1:bbcfg["Systems"]
  42.     points[i,:] = discus()
  43. end
  44. @OK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement