fractal 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/fractal +26 -5
- data/lib/fractal.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6e9e8b59a32d9c1c60cc4491b890caf44e70f70
|
4
|
+
data.tar.gz: 7279d76d297eb703f576063289ea06dc7e8ff92d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a0aa10ad51c5cf18933c07d0d710dbae8cd21a20bd0b08d74829bef48644797ba315997b83bbf99910a147c2143e3e8f16dd2abe807d7df150f1fdad2511b77
|
7
|
+
data.tar.gz: 9238c025bd4cdeac06d21b1498ddc7677f399f6fc7b7949de04bef0903f93ee6865aa9fd54059d08de53c5e94b854bda506e1ee0c2531b1ff896030662dea47d
|
data/bin/fractal
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'fractal'
|
3
3
|
args = Hash[ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/)]
|
4
|
-
|
4
|
+
|
5
|
+
if args.key? 'help'
|
5
6
|
help = <<EOF
|
6
7
|
|
7
8
|
`fractal` command-line arguments:
|
@@ -14,8 +15,12 @@ if args.key?('help')
|
|
14
15
|
the image in colour or monochromatically,
|
15
16
|
e.g. `--color=mono` or `--color=multi`
|
16
17
|
which is the same as `--color=rainbow`
|
18
|
+
- `-o=`, (*optional*) is the location in which to save
|
19
|
+
your image, the `-o=` part is not required if you
|
20
|
+
just write the file location with a `.png` at the end.
|
17
21
|
- `--def=`, (optional), the 'definition' of the image,
|
18
|
-
the amount of calculations performed
|
22
|
+
the amount of calculations performed or iterations of
|
23
|
+
the formula. e.g. `--def=100` for 100 iterations.
|
19
24
|
- `--scale=`, (optional), the zoom level of the image,
|
20
25
|
a higher value corresponds to a taller imaginary number line
|
21
26
|
thus a smaller fractal is seen. e.g. `--scale=2.25`
|
@@ -29,8 +34,9 @@ if args.key?('help')
|
|
29
34
|
put at any position in your list of arguments.
|
30
35
|
e.g. `mandelbrot` or `julia`
|
31
36
|
|
32
|
-
|
33
|
-
`fractal -w=
|
37
|
+
Example commands:
|
38
|
+
`fractal ~/my_fractal.png -w=500 -h=310 --scale=2.92 --def=100 mandelbrot --color=mono`
|
39
|
+
`fractal julia -w=600 -h=600 --color=multi --complex=-0.8+0.156i --def=100 --scale=1.5 -o=../my_fractal`
|
34
40
|
|
35
41
|
EOF
|
36
42
|
puts help
|
@@ -40,14 +46,24 @@ end
|
|
40
46
|
allowedFractals = ['mandelbrot', 'julia']
|
41
47
|
fractalType = String.new
|
42
48
|
|
49
|
+
o = String.new
|
43
50
|
ARGV.each do |arg|
|
44
51
|
allowedFractals.each do |option|
|
45
52
|
fractalType = arg.downcase if arg.downcase == option
|
46
53
|
end
|
54
|
+
|
55
|
+
o = arg if arg[arg.length - 4, 4].downcase == '.png'
|
56
|
+
end
|
57
|
+
|
58
|
+
o = args['o'] if args.key? 'o'
|
59
|
+
if o.include? '~'
|
60
|
+
o.delete! '~'
|
61
|
+
o = "#{File.expand_path('~')}/#{o}"
|
47
62
|
end
|
48
63
|
|
64
|
+
|
49
65
|
if fractalType.empty?
|
50
|
-
puts "Error: Please provide a fractal type."
|
66
|
+
puts "Error: Please provide a fractal type.\nType `fractal --help` for help."
|
51
67
|
exit 1
|
52
68
|
end
|
53
69
|
|
@@ -95,4 +111,9 @@ definition, scale = 255, 2.0
|
|
95
111
|
definition = args['def'].to_i if args.key? 'def' # --def=100
|
96
112
|
scale = args['scale'].to_f if args.key? 'scale' # --scale=1.5
|
97
113
|
|
114
|
+
unless o.empty?
|
115
|
+
fractal.draw(definition, scale).save(o)
|
116
|
+
exit 0
|
117
|
+
end
|
118
|
+
|
98
119
|
fractal.draw(definition, scale).save("#{fractalType}-fractal.png")
|
data/lib/fractal.rb
CHANGED
@@ -29,7 +29,7 @@ module Fractals
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def draw definition=255, scale=2.0
|
32
|
-
scaleWidth = scale
|
32
|
+
scaleWidth = scale
|
33
33
|
scaleHeight = scale.to_f * (@height.to_f / @width.to_f)
|
34
34
|
definition = definition.to_f
|
35
35
|
(0..@width - 1).each do |x|
|
@@ -67,15 +67,15 @@ module Fractals
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
class Julia < Mandelbrot
|
70
|
+
class Julia < Mandelbrot # Since the Julia set only has a slightly modified calculation
|
71
71
|
attr_accessor :real
|
72
72
|
attr_accessor :complex
|
73
73
|
|
74
|
-
def calculate a, b, c_arr
|
74
|
+
def calculate a, b, c_arr # c_arr is irrelevant as c is now constant, however the draw() still supplies it and I don't want to rewrite draw when it already exists.
|
75
75
|
left = a * a - b * b
|
76
76
|
right = 2 * a * b
|
77
|
-
a = left + @real
|
78
|
-
b = right + @complex
|
77
|
+
a = left + @real # z^2 + c
|
78
|
+
b = right + @complex # but here the c is constant, composed of a real and imaginary part in form of a±bi where a and b have been separated and labeled here as real and complex
|
79
79
|
return [a, b]
|
80
80
|
end
|
81
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fractal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Demonstrandum
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.6.
|
62
|
+
rubygems_version: 2.6.11
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: Draws fractal PNG images.
|