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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/fractal +16 -3
  3. data/lib/fractal.rb +16 -9
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce6ccc1d562e8399fdbd9b5867851075197b1b31
4
- data.tar.gz: 708e78c8f8d02810d0376b2185618a55333e974f
3
+ metadata.gz: c48c0abbbd61e352458fe008cc8644bc663e6cab
4
+ data.tar.gz: 4d6a44628b4fca35212178956b1e0ff309e6e71d
5
5
  SHA512:
6
- metadata.gz: 48cd8349fe3c1602ee3fd3740765e7dcacecb548116b8347b3ff83cbb0fb719f8a819cfe93837760b1fbd92aa4205849a11a6633f5eae6fc03e6a7b3fae1af42
7
- data.tar.gz: 490f199d0ce4326813e4e17c1d82ba638adc56db49a99e2ceff1362fd2428deacef47788ec61e08dbe026a01bac0acc597a36e5847628ba1d0ea2c6ce39a7dc1
6
+ metadata.gz: 00b3e6e4a738d218de472066fc6d2329018de4b6ee21eebadfc29d3877ce8d2cc7a76b6f96f4552546a9d617d0827e7027baf3c42f748151d4c5be4b61b4e313
7
+ data.tar.gz: 065da56ed5d1c6a368eb51e2357241138093d431f8d3f9cf0bd4ae7ca0e224e52d73d4eb17bc59b632d8011edf6e6ede4f9b1a119506700ae079d1d9a63faf70
@@ -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?('h') || args.key?('help')
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
@@ -45,15 +45,22 @@ module Fractals
45
45
  end
46
46
  snap += 1
47
47
  end
48
- # TODO: Use colorType as option non-monochromatic images
49
- # (allow colourful fractals), currently only greyscale
50
- shade = drag(snap, 0, definition, 0, 1)
51
- shade = drag(Math.sqrt(shade), 0, 1, 0, 255)
52
-
53
- colours = [shade.round.to_i] * 3
54
- hex = String.new
55
- colours.each { |component| hex << component.to_s(16) }
56
- @image[x, y] = ChunkyPNG::Color.from_hex hex
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
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Demonstrandum