fractal 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/fractal +27 -14
  3. data/lib/fractal.rb +15 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c48c0abbbd61e352458fe008cc8644bc663e6cab
4
- data.tar.gz: 4d6a44628b4fca35212178956b1e0ff309e6e71d
3
+ metadata.gz: 9ca753d7ca93789497b10c740760968eabe70ed3
4
+ data.tar.gz: 6111c8006945b1e67a96b4a8e7322eb275417ca6
5
5
  SHA512:
6
- metadata.gz: 00b3e6e4a738d218de472066fc6d2329018de4b6ee21eebadfc29d3877ce8d2cc7a76b6f96f4552546a9d617d0827e7027baf3c42f748151d4c5be4b61b4e313
7
- data.tar.gz: 065da56ed5d1c6a368eb51e2357241138093d431f8d3f9cf0bd4ae7ca0e224e52d73d4eb17bc59b632d8011edf6e6ede4f9b1a119506700ae079d1d9a63faf70
6
+ metadata.gz: 4a5e8dfa8df498cdb61aa878f17a53e0f4560bbf6875b17cdc1d00838554e933b8d967ba3a496d7b467bb64210b75f3dd4f2d33c7408e287bc606d4f7dc18981
7
+ data.tar.gz: 6b8f3ea49144ef2c2173b4f981a5a2867b8d151bfbc394211c299be36e149c61ec95d7c6c9275de2cb6f287744d27d79c8b39512fb597f687d8c5ea022793cec
@@ -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
- fractals = ['mandelbrot']
40
+ allowedFractals = ['mandelbrot', 'julia']
32
41
  fractalType = String.new
33
42
 
34
43
  ARGV.each do |arg|
35
- fractals.each do |option|
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
- fractal = (
70
- case fractalType
71
- when 'mandelbrot'
72
- Fractals::Mandelbrot.new png
73
- else
74
- Fractals::Mandelbrot.new png
75
- end
76
- )
77
- # TODO: Use colorMode option for multichromatic images.
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'].to_i if args.key? 'scale' # --scale=1.5
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")
@@ -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
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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Demonstrandum