fractal 0.1.5 → 0.1.6
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 +16 -3
- data/lib/fractal.rb +16 -9
- 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: c48c0abbbd61e352458fe008cc8644bc663e6cab
|
4
|
+
data.tar.gz: 4d6a44628b4fca35212178956b1e0ff309e6e71d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00b3e6e4a738d218de472066fc6d2329018de4b6ee21eebadfc29d3877ce8d2cc7a76b6f96f4552546a9d617d0827e7027baf3c42f748151d4c5be4b61b4e313
|
7
|
+
data.tar.gz: 065da56ed5d1c6a368eb51e2357241138093d431f8d3f9cf0bd4ae7ca0e224e52d73d4eb17bc59b632d8011edf6e6ede4f9b1a119506700ae079d1d9a63faf70
|
data/bin/fractal
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'fractal'
|
3
3
|
args = Hash[ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/)]
|
4
|
-
if args.key?('
|
4
|
+
if args.key?('help')
|
5
5
|
help = <<EOF
|
6
6
|
|
7
7
|
`fractal` command-line arguments:
|
@@ -38,7 +38,7 @@ ARGV.each do |arg|
|
|
38
38
|
end
|
39
39
|
|
40
40
|
if fractalType.empty?
|
41
|
-
puts "Please provide a fractal type."
|
41
|
+
puts "Error: Please provide a fractal type."
|
42
42
|
exit 1
|
43
43
|
end
|
44
44
|
|
@@ -51,6 +51,20 @@ if width <= 0 || height <= 0
|
|
51
51
|
width = height = 300
|
52
52
|
end
|
53
53
|
|
54
|
+
ca = cb = nil
|
55
|
+
if args.key? 'complex'
|
56
|
+
complex = args['complex']
|
57
|
+
ca, cb = complex.split(/(?=[+\-])/)
|
58
|
+
ca = ca.to_f
|
59
|
+
cb.delete! "i"
|
60
|
+
cb = cb.to_f
|
61
|
+
end
|
62
|
+
|
63
|
+
if fractalType == 'julia' && (ca.nil? || cb.nil?)
|
64
|
+
puts "Error: fractal type: '#{fractalType}' requires complex coordinate,\n in form of '±c₁±c₂i', for example: -0.416+0.8i"
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
54
68
|
png = ChunkyPNG::Image.new width, height
|
55
69
|
fractal = (
|
56
70
|
case fractalType
|
@@ -60,7 +74,6 @@ fractal = (
|
|
60
74
|
Fractals::Mandelbrot.new png
|
61
75
|
end
|
62
76
|
)
|
63
|
-
fractal.colorType = 'mono'
|
64
77
|
# TODO: Use colorMode option for multichromatic images.
|
65
78
|
fractal.colorType = args['color'] if args.key? 'color' # --color=mono
|
66
79
|
fractal.colorType = args['mode'] if args.key? 'mode' # --mode=mono
|
data/lib/fractal.rb
CHANGED
@@ -45,15 +45,22 @@ module Fractals
|
|
45
45
|
end
|
46
46
|
snap += 1
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
|
49
|
+
case @colorType
|
50
|
+
when 'multichromatic', 'multi', 'rainbow'
|
51
|
+
brightness = 1
|
52
|
+
brightness = 0 if snap == definition
|
53
|
+
hue = drag(snap, 0, definition, 0, 1)
|
54
|
+
hue = drag(Math.sqrt(hue), 0, 1, 0, 360)
|
55
|
+
|
56
|
+
@image[x, y] = ChunkyPNG::Color.from_hsv hue, 1, brightness
|
57
|
+
else
|
58
|
+
shade = drag(snap, 0, definition, 0, 1)
|
59
|
+
shade = drag(Math.sqrt(shade), 0, 1, 0, 255)
|
60
|
+
r, g, b = [shade.round.to_i] * 3
|
61
|
+
|
62
|
+
@image[x, y] = ChunkyPNG::Color.rgb r, g, b
|
63
|
+
end
|
57
64
|
end
|
58
65
|
end
|
59
66
|
return @image
|