nbody_display.jl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. #
  5. # StarPU is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at
  8. # your option) any later version.
  9. #
  10. # StarPU is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. #
  16. function get_planet_pixels(X ::Int64, Y ::Int64)
  17. pix ::Array{Tuple{Int64,Int64}} = []
  18. for i = X-1:X+1
  19. for j = Y-3:Y+3
  20. push!(pix,(i,j))
  21. end
  22. end
  23. for i = Y-2:Y+2
  24. push!(pix,(X-2,i))
  25. push!(pix,(X+2,i))
  26. end
  27. for i = Y-1:Y+1
  28. push!(pix,(X-3,i))
  29. push!(pix,(X+3,i))
  30. end
  31. return pix
  32. end
  33. function is_inside(t ::Tuple{Int64,Int64}, width ::Int64, height ::Int64)
  34. if (t[1] > 0 && t[1] <= width && t[2] > 0 && t[2] <= height)
  35. return true
  36. else
  37. return false
  38. end
  39. end
  40. function graph_planets(pixels ::Array{Array{Int64}}, positions ::Matrix{Float64}, min_value ::Float64, max_value ::Float64, width ::Int64, height ::Int64, file_name ::String)
  41. n = size(positions)[2]
  42. for i = 1:n
  43. X ::Int64= round( ( (positions[1, i] - min_value) / (max_value - min_value) ) * (width - 1) ) + 1
  44. Y ::Int64= round( (1 - ( (positions[2, i] - min_value) / (max_value - min_value) ) ) * (height - 1) ) + 1
  45. pix ::Array{Tuple{Int64,Int64}} = get_planet_pixels(X,Y)
  46. for pixel in pix
  47. if is_inside(pixel, width, height)
  48. pixels[(pixel[2] - 1)*width + pixel[1]] = [125, round(255*i/n)]
  49. end
  50. end
  51. end
  52. open(file_name,"w") do f
  53. write(f, "P3\n$width $height\n255\n")
  54. for he = 1:height
  55. for wi = 1:width
  56. write(f, "$(pixels[(he - 1)*width + wi][1]) 0 $(pixels[(he - 1)*width + wi][2]) ")
  57. end
  58. write(f,"\n")
  59. end
  60. end
  61. end
  62. # function graph_planets(pixels ::Array{Array{Int64}}, positions ::Vector{Vector{Float64}}, min_value ::Float64, max_value ::Float64, width ::Int64, height ::Int64, file_name ::String)
  63. # n = length(positions)
  64. # for i = 1:n
  65. # X ::Int64= round( ( (positions[i][1] - min_value) / (max_value - min_value) ) * (width - 1) ) + 1
  66. # Y ::Int64= round( (1 - ( (positions[i][2] - min_value) / (max_value - min_value) ) ) * (height - 1) ) + 1
  67. # pix ::Array{Tuple{Int64,Int64}} = get_planet_pixels(X,Y)
  68. # for pixel in pix
  69. # if is_inside(pixel, width, height)
  70. # pixels[(pixel[2] - 1)*width + pixel[1]] = [125, round(255*i/n)]
  71. # end
  72. # end
  73. # end
  74. # open(file_name,"w") do f
  75. # write(f, "P3\n$width $height\n255\n")
  76. # for he = 1:height
  77. # for wi = 1:width
  78. # write(f, "$(pixels[(he - 1)*width + wi][1]) 0 $(pixels[(he - 1)*width + wi][2]) ")
  79. # end
  80. # write(f,"\n")
  81. # end
  82. # end
  83. # end