fractal 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/fractal +27 -14
- data/lib/fractal.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca753d7ca93789497b10c740760968eabe70ed3
|
4
|
+
data.tar.gz: 6111c8006945b1e67a96b4a8e7322eb275417ca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a5e8dfa8df498cdb61aa878f17a53e0f4560bbf6875b17cdc1d00838554e933b8d967ba3a496d7b467bb64210b75f3dd4f2d33c7408e287bc606d4f7dc18981
|
7
|
+
data.tar.gz: 6b8f3ea49144ef2c2173b4f981a5a2867b8d151bfbc394211c299be36e149c61ec95d7c6c9275de2cb6f287744d27d79c8b39512fb597f687d8c5ea022793cec
|
data/bin/fractal
CHANGED
@@ -10,15 +10,24 @@ if args.key?('help')
|
|
10
10
|
(Defaults to 300), e.g. `-w=500`
|
11
11
|
- `-h=`, the pixel height of the output image.
|
12
12
|
(Defaults to 300), e.g. `-h=240`
|
13
|
+
- `--color=`, (Defaults to mono), allows you to draw
|
14
|
+
the image in colour or monochromatically,
|
15
|
+
e.g. `--color=mono` or `--color=multi`
|
16
|
+
which is the same as `--color=rainbow`
|
13
17
|
- `--def=`, (optional), the 'definition' of the image,
|
14
18
|
the amount of calculations performed. e.g. `--def=255`
|
15
19
|
- `--scale=`, (optional), the zoom level of the image,
|
16
20
|
a higher value corresponds to a taller imaginary number line
|
17
21
|
thus a smaller fractal is seen. e.g. `--scale=2.25`
|
22
|
+
- `--complex=` (*only needed for the Julia set*)
|
23
|
+
this sets a complex coordinate for the Julia set,
|
24
|
+
in the form of `a±bi` ('a' and 'b' real numbers and
|
25
|
+
'i' is the square root of -1 which can take on all
|
26
|
+
values in the complex plane), e.g. '-0.8+0.4i'
|
18
27
|
- Last but not least, (required), the type of fractal drawn.
|
19
28
|
This argument is composed of just the fractal's name,
|
20
29
|
put at any position in your list of arguments.
|
21
|
-
e.g. `mandelbrot`
|
30
|
+
e.g. `mandelbrot` or `julia`
|
22
31
|
|
23
32
|
An example command is:
|
24
33
|
`fractal -w=400 -h=320 mandelbrot --scale=2 --def=100`
|
@@ -28,11 +37,11 @@ EOF
|
|
28
37
|
exit 0
|
29
38
|
end
|
30
39
|
|
31
|
-
|
40
|
+
allowedFractals = ['mandelbrot', 'julia']
|
32
41
|
fractalType = String.new
|
33
42
|
|
34
43
|
ARGV.each do |arg|
|
35
|
-
|
44
|
+
allowedFractals.each do |option|
|
36
45
|
fractalType = arg.downcase if arg.downcase == option
|
37
46
|
end
|
38
47
|
end
|
@@ -66,20 +75,24 @@ if fractalType == 'julia' && (ca.nil? || cb.nil?)
|
|
66
75
|
end
|
67
76
|
|
68
77
|
png = ChunkyPNG::Image.new width, height
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
|
79
|
+
case fractalType
|
80
|
+
when 'mandelbrot'
|
81
|
+
fractal = Fractals::Mandelbrot.new png
|
82
|
+
when 'julia'
|
83
|
+
fractal = Fractals::Julia.new png
|
84
|
+
fractal.real = ca
|
85
|
+
fractal.complex = cb
|
86
|
+
else
|
87
|
+
fractal = Fractals::Mandelbrot.new png
|
88
|
+
end
|
89
|
+
|
90
|
+
|
78
91
|
fractal.colorType = args['color'] if args.key? 'color' # --color=mono
|
79
92
|
fractal.colorType = args['mode'] if args.key? 'mode' # --mode=mono
|
80
93
|
|
81
|
-
definition, scale = 255, 2
|
94
|
+
definition, scale = 255, 2.0
|
82
95
|
definition = args['def'].to_i if args.key? 'def' # --def=100
|
83
|
-
scale = args['scale'].
|
96
|
+
scale = args['scale'].to_f if args.key? 'scale' # --scale=1.5
|
84
97
|
|
85
98
|
fractal.draw(definition, scale).save("#{fractalType}-fractal.png")
|
data/lib/fractal.rb
CHANGED
@@ -28,7 +28,7 @@ module Fractals
|
|
28
28
|
return [a, b]
|
29
29
|
end
|
30
30
|
|
31
|
-
def draw definition=255, scale=2
|
31
|
+
def draw definition=255, scale=2.0
|
32
32
|
scaleWidth = scale.to_f
|
33
33
|
scaleHeight = scale.to_f * (@height.to_f / @width.to_f)
|
34
34
|
definition = definition.to_f
|
@@ -66,4 +66,18 @@ module Fractals
|
|
66
66
|
return @image
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
class Julia < Mandelbrot
|
71
|
+
attr_accessor :real
|
72
|
+
attr_accessor :complex
|
73
|
+
|
74
|
+
def calculate a, b, c_arr
|
75
|
+
left = a * a - b * b
|
76
|
+
right = 2 * a * b
|
77
|
+
a = left + @real
|
78
|
+
b = right + @complex
|
79
|
+
return [a, b]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
# module space
|
69
83
|
end
|