fractal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/fractal +8 -0
- data/lib/fractal.rb +53 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45b8f6fa7a6f441266b58e9ef31a977d506184ca
|
4
|
+
data.tar.gz: 16d849e8562d36b027ff10e0cf14b4939b5a07c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 812a196b7ae1eaef40e896821e21b67f4a514d9535a48d5f7050866bd0c09be2c2a75e7066593c9b629050b0b92ca5248c2cb79951c777efabeeb0910d4b5d30
|
7
|
+
data.tar.gz: 21b4e68b948b0a2471048a3011d501353d21a5a7a20a6d3950c46a941b1a0a3b8abc3474fbbe4770cb40c17c4df09d852ecc6bc79233ce7d87179063566055e1
|
data/bin/fractal
ADDED
data/lib/fractal.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'chunky_png'
|
2
|
+
|
3
|
+
def drag pos, pos_min, pos_max, out_min, out_max
|
4
|
+
return (
|
5
|
+
(pos - pos_min) * (out_max - out_min) /
|
6
|
+
(pos_max - pos_min) + out_min
|
7
|
+
)
|
8
|
+
end # drag(x, x_min_val, x_max_val, mapped_to_min_val, mapped_to_max_val), the same as the popular map(...) function.
|
9
|
+
|
10
|
+
module Fractals
|
11
|
+
I = Complex 'i'
|
12
|
+
|
13
|
+
class Mandelbrot
|
14
|
+
attr_accessor :colorMode
|
15
|
+
|
16
|
+
def initialize image
|
17
|
+
@width, @height = image.width, image.height
|
18
|
+
@image = image
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw definition=100, scale=2
|
22
|
+
scale = scale.to_f
|
23
|
+
definition = definition.to_f
|
24
|
+
(0..@width - 1).each do |x|
|
25
|
+
(0..@height - 1).each do |y|
|
26
|
+
a = ca = drag(x, 0, @width, -scale, scale)
|
27
|
+
b = cb = drag(y, 0, @height, -scale, scale)
|
28
|
+
|
29
|
+
snap = 0
|
30
|
+
while snap < definition
|
31
|
+
left = a * a - b * b
|
32
|
+
right = 2 * a * b
|
33
|
+
a = left + ca
|
34
|
+
b = right + cb
|
35
|
+
|
36
|
+
if a * a + b * b > 16
|
37
|
+
break
|
38
|
+
end
|
39
|
+
snap += 1
|
40
|
+
end
|
41
|
+
shade = drag(snap, 0, definition, 0, 1)
|
42
|
+
shade = drag(Math.sqrt(shade), 0, 1, 0, 255)
|
43
|
+
|
44
|
+
colours = [shade.round.to_i] * 3
|
45
|
+
hex = String.new
|
46
|
+
colours.each { |component| hex << component.to_s(16) }
|
47
|
+
@image[x, y] = ChunkyPNG::Color.from_hex hex
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return @image
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fractal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Demonstrandum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Creates PNG images of fractals.
|
14
|
+
email: knutsen@jetspace.co
|
15
|
+
executables:
|
16
|
+
- fractal
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/fractal
|
21
|
+
- lib/fractal.rb
|
22
|
+
homepage: https://github.com/Demonstrandum/Fractal
|
23
|
+
licenses:
|
24
|
+
- GPL-3.0
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.9.2
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.6.12
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Draws fractal PNG images.
|
46
|
+
test_files: []
|