import GR

j = [0.19454, 0.1194, 0.19454, 0.41129, 0.10807, 0.3875, 0.10807, 0.07711, 0.10807, 0.06075, 0.10681, 0.04973, 0.1043, 0.04407, 0.10178, 0.0384, 0.09813, 0.03557, 0.09335, 0.03557, 0.09108, 0.03557, 0.08856, 0.03645, 0.08579, 0.03822, 0.08303, 0.03998, 0.07963, 0.0435, 0.0756, 0.04879, 0.07207, 0.05357, 0.06761, 0.05842, 0.06219, 0.06333, 0.05678, 0.06824, 0.04954, 0.07069, 0.04048, 0.07069, 0.0284, 0.07069, 0.01877, 0.06767, 0.0116, 0.06163, 0.00442, 0.05559, 0.00083, 0.04816, 0.00083, 0.03935, 0.00083, 0.02878, 0.00725, 0.01971, 0.02009, 0.01216, 0.03293, 0.00461, 0.05143, 0.00083, 0.0756, 0.00083, 0.09347, 0.00083, 0.10971, 0.00228, 0.12431, 0.00518, 0.13891, 0.00807, 0.15143, 0.0138, 0.16188, 0.02236, 0.17233, 0.03092, 0.18038, 0.04294, 0.18605, 0.05842, 0.19171, 0.0739, 0.19454, 0.09423, 0.19454, 0.1194]

u = [0.31464, 0.40298, 0.22855, 0.40298, 0.22855, 0.20323, 0.22855, 0.1909, 0.23113, 0.17932, 0.23629, 0.16849, 0.24145, 0.15767, 0.24856, 0.14823, 0.25763, 0.14017, 0.26669, 0.13212, 0.27726, 0.12576, 0.28935, 0.1211, 0.30143, 0.11644, 0.31452, 0.11412, 0.32862, 0.11412, 0.3407, 0.11412, 0.35316, 0.11701, 0.366, 0.1228, 0.37884, 0.12859, 0.39092, 0.13627, 0.40225, 0.14583, 0.40225, 0.1194, 0.48834, 0.1194, 0.48834, 0.40298, 0.40225, 0.40298, 0.40225, 0.19832, 0.3957, 0.18825, 0.38803, 0.17988, 0.37922, 0.17321, 0.3704, 0.16654, 0.36273, 0.1632, 0.35618, 0.1632, 0.35039, 0.1632, 0.34498, 0.16427, 0.33994, 0.16641, 0.33491, 0.16855, 0.3305, 0.17139, 0.32673, 0.17491, 0.32295, 0.17843, 0.31999, 0.18265, 0.31785, 0.18756, 0.31571, 0.19247, 0.31464, 0.19769, 0.31464, 0.20323]

l = [0.60797, 0.1194, 0.60797, 0.54081, 0.52225, 0.51702, 0.52225, 0.1194]

i = [0.64226, 0.3875, 0.64226, 0.1194, 0.72835, 0.1194, 0.72835, 0.41129]

a = [0.91001, 0.26591, 0.91001, 0.18397, 0.9012, 0.17743, 0.89321, 0.17201, 0.88604, 0.16773, 0.87886, 0.16345, 0.87175, 0.16132, 0.8647, 0.16132, 0.86118, 0.16132, 0.8579, 0.16238, 0.85488, 0.16452, 0.85186, 0.16666, 0.84909, 0.1695, 0.84658, 0.17302, 0.84406, 0.17655, 0.84211, 0.18076, 0.84072, 0.18567, 0.83934, 0.19058, 0.83865, 0.19568, 0.83865, 0.20096, 0.83865, 0.20776, 0.84079, 0.21431, 0.84507, 0.2206, 0.84934, 0.22689, 0.85495, 0.23281, 0.86187, 0.23835, 0.86879, 0.24388, 0.87647, 0.24898, 0.8849, 0.25364, 0.89334, 0.2583, 0.90171, 0.26239, 0.91001, 0.26591, 0.99648, 0.1194, 0.99648, 0.33199, 0.99648, 0.34382, 0.99422, 0.35452, 0.98969, 0.36409, 0.98516, 0.37365, 0.97811, 0.38184, 0.96854, 0.38863, 0.95898, 0.39543, 0.94683, 0.40065, 0.9321, 0.4043, 0.91738, 0.40795, 0.89982, 0.40978, 0.87943, 0.40978, 0.86281, 0.40978, 0.84708, 0.40802, 0.83223, 0.40449, 0.81737, 0.40097, 0.80428, 0.39618, 0.79296, 0.39014, 0.78163, 0.3841, 0.77263, 0.37686, 0.76596, 0.36843, 0.75929, 0.36, 0.75595, 0.35087, 0.75595, 0.34105, 0.75595, 0.33048, 0.75973, 0.32173, 0.76728, 0.31481, 0.77483, 0.30789, 0.78465, 0.30443, 0.79673, 0.30443, 0.80454, 0.30443, 0.81102, 0.30556, 0.81618, 0.30783, 0.82134, 0.31009, 0.8253, 0.31311, 0.82807, 0.31689, 0.83084, 0.32066, 0.83279, 0.32507, 0.83393, 0.3301, 0.83506, 0.33514, 0.83563, 0.3403, 0.83563, 0.34559, 0.83563, 0.3549, 0.83827, 0.36283, 0.84356, 0.36937, 0.84884, 0.37592, 0.85828, 0.37919, 0.87188, 0.37919, 0.88346, 0.37919, 0.89271, 0.37542, 0.89963, 0.36786, 0.90655, 0.36031, 0.91001, 0.34747, 0.91001, 0.32935, 0.91001, 0.30141, 0.90057, 0.29914, 0.88899, 0.29562, 0.87729, 0.2919, 0.86546, 0.288, 0.85362, 0.2841, 0.84223, 0.27982, 0.83128, 0.27516, 0.82033, 0.27051, 0.81007, 0.26541, 0.80051, 0.25987, 0.79094, 0.25433, 0.78257, 0.24804, 0.7754, 0.24099, 0.76822, 0.23394, 0.76256, 0.22601, 0.75841, 0.2172, 0.75425, 0.20839, 0.75217, 0.19857, 0.75217, 0.18775, 0.75217, 0.17717, 0.75413, 0.16742, 0.75803, 0.15848, 0.76193, 0.14955, 0.76753, 0.14181, 0.77483, 0.13526, 0.78213, 0.12872, 0.791, 0.12355, 0.80145, 0.11978, 0.8119, 0.116, 0.82367, 0.11411, 0.83676, 0.11411, 0.84632, 0.11411, 0.85463, 0.11481, 0.86168, 0.11619, 0.86873, 0.11758, 0.87508, 0.11953, 0.88075, 0.12204, 0.88641, 0.12456, 0.89151, 0.12752, 0.89604, 0.13092, 0.90057, 0.13432, 0.90523, 0.13803, 0.91001, 0.14206, 0.91001, 0.1194]

function draw_path(p, codes, fill, border)
  GR.setfillcolorind(fill)
  GR.setbordercolorind(border)
  op = border == 0 ? 'f' : 'F'
  GR.path(p[1:2:end], p[2:2:end], codes)
end

function circle(xmin, ymin, xmax, ymax, fill, border)
  GR.setfillintstyle(4)
  GR.setfillcolorind(fill)
  GR.setbordercolorind(border)
  GR.fillarc(xmin, xmax, ymin, ymax, 0, 360)
end

GR.setcolorrep(1, 0.14, 0.14, 0.14)
GR.setcolorrep(2, 0.251, 0.388, 0.847) # darker blue
GR.setcolorrep(3, 0.796, 0.235, 0.2)   # darker red
GR.setcolorrep(4, 0.584, 0.345, 0.698) # darker purple
GR.setcolorrep(5, 0.22, 0.596, 0.149)  # darker green
GR.setcolorrep(6, 0.4, 0.51, 0.878)    # lighter blue
GR.setcolorrep(7, 0.835, 0.388, 0.361) # lighter red
GR.setcolorrep(8, 0.667, 0.475, 0.757) # lighter purple
GR.setcolorrep(9, 0.376, 0.678, 0.318) # lighter green

GR.setviewport(0, 1, 0, 1)
GR.setwindow(0, 1, 0, 1)
GR.updatews()

for s in 0.1:0.01:0.5
  GR.clearws()
  GR.setviewport(0.5 - s, 0.5 + s, 0.5 - s, 0.5 + s)
  GR.setborderwidth(s * 8)

  draw_path(j, "MLLLCCCCCCCCCCCCCCf", 1, 0)
  draw_path(u, "MLLCCCCCCLLLLLCCCCCCf", 1, 0)
  draw_path(l, "MLLLf", 1, 0)
  draw_path(i, "MLLLf", 1, 0)
  draw_path(a, "MLCCCCCCCCCCZMLCCCCCCCCCCCCCCCCCCLLCCCCCCCCCCCCCCLf", 1, 0)

  circle(0.09698, 0.43274, 0.20364, 0.5394, 2, 6)
  circle(0.63794, 0.43274, 0.7446, 0.5394, 3, 7)
  circle(0.70794, 0.55274, 0.8146, 0.6594, 4, 8)
  circle(0.77794, 0.43274, 0.8846, 0.5394, 5, 9)

  GR.updatews()

  sleep(0.01)
end
