about summary refs log tree commit diff stats
path: root/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/pokeviewer/pokemon_helper.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/app/helpers/pokeviewer/pokemon_helper.rb b/app/helpers/pokeviewer/pokemon_helper.rb index 4f3dc3f..de2d815 100644 --- a/app/helpers/pokeviewer/pokemon_helper.rb +++ b/app/helpers/pokeviewer/pokemon_helper.rb
@@ -1,4 +1,80 @@
1require 'victor'
2
1module Pokeviewer 3module Pokeviewer
2 module PokemonHelper 4 module PokemonHelper
5
6 def condition_diagram(revision)
7 svg = Victor::SVG.new width: 420, height: 430
8
9 center_x = 200
10 center_y = 200
11 radius = 160
12
13 angle = -Math::PI / 2.0
14 incr = (2 * Math::PI) / 5
15
16 data = [
17 [:cool, revision.coolness],
18 [:beauty, revision.beauty],
19 [:cute, revision.cuteness],
20 [:smart, revision.smartness],
21 [:tough, revision.toughness]
22 ]
23
24 outline = data.map do |c|
25 x_offset = radius * Math.cos(angle)
26 y_offset = radius * Math.sin(angle)
27
28 svg.circle(
29 cx: (center_x + x_offset),
30 cy: (center_y + y_offset),
31 r: 53,
32 class: "pkcv-#{c[0]}-circle")
33
34 if c[0] == :cool
35 text_y = center_y + (radius + 20) * Math.sin(angle)
36 else
37 text_y = center_y + (radius + 60) * Math.sin(angle)
38 end
39
40 svg.text(c[0].upcase,
41 x: (center_x + (radius + 60) * Math.cos(angle)),
42 y: text_y,
43 class: "pkcv-label-outline")
44
45 svg.text(c[0].upcase,
46 x: (center_x + (radius + 60) * Math.cos(angle)),
47 y: text_y,
48 class: "pkcv-label")
49
50 angle += incr
51
52 [center_x + x_offset, center_y + y_offset]
53 end
54
55 svg.polygon points: outline.map { |point| point * "," } * " ", class: "pkcv-outline"
56
57 points = data.map do |c|
58 datapoint = c[1]
59 datapoint = 0.01 if datapoint < 1
60 datapoint /= 10.0
61 datapoint **= (1.0/3.0)
62
63 x_offset = (radius - 3) * Math.cos(angle) * datapoint
64 y_offset = (radius - 3) * Math.sin(angle) * datapoint
65
66 angle += incr
67
68 [center_x + x_offset, center_y + y_offset]
69 end
70
71 svg.polygon points: points.map { |point| point * "," } * " ", class: "pkcv-data"
72
73 tag.svg(svg.to_s.html_safe,
74 viewBox: "0 -30 410 430",
75 width: 410,
76 class: "pokemon-condition")
77 end
78
3 end 79 end
4end 80end