goldensections 1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03ee7fb6c5e7b0f1038092abf4f87bae26a1de31
4
+ data.tar.gz: 471000325fbfb0981a0e0ad9f0f176b87bf8b363
5
+ SHA512:
6
+ metadata.gz: ba7ad2dce54eddb9c454860af09cfc1733d43744a2cad6d44f9993ce1b0298a3633884b34c824c480503101305e32612c95cdb514a745d69c0cf87c0a57d86a2
7
+ data.tar.gz: 23b459f3866a5de0f3d601aa04eb371ad133f393711d1076b2e752d54c1e3b5e69ac2b1ce00cb3e0987e54fa8a7dfd07863633fe70c169f3611173cc110cdedd
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ Golden Sections
2
+ https://github.com/austinseraphin/goldensections
3
+
4
+ Welcome to Golden Sections, a RubyMotion gem for creating views based
5
+ on the golden mean. I wrote this gem because using the golden mean
6
+ looks naturally beautiful. Instead of guessing or picking round
7
+ numbers, why not use something more appealing? Give your app the Midas
8
+ touch with Golden Sections!
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'goldensections'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install goldensections
23
+
24
+ This gem depends on Geomotion.
25
+
26
+ ## Usage
27
+
28
+ Firstly, the gem adds a method to the Numeric class called
29
+ golden_section(exponent) the parameter represents the exponent of the
30
+ golden mean to use, defaulting to 1.
31
+
32
+ It then adds golden_section class and instance methods to CGPoint,
33
+ CGSize, and CGRect. The class methods i.e. CGRect.golden_section take
34
+ a hash of options. The options depend on the class, but should include
35
+ enough information to create an object. For CGPoint this means
36
+ specifying either :x or :y. For CGSize this means specifying either
37
+ :width or :height. CGRect can take any combination of these options,
38
+ usually :x, :y, and either :width or :height. The methods then fill in
39
+ the missing attributes. They also take a :exponent option. For
40
+ example:
41
+
42
+ point=CGPoint.golden_section(x: 100) => CGPoint(100.0,
43
+ 61.8033905029297) size=CGSize.golden_section(width: 100) =>
44
+ CGSize(100.0, 61.8033905029297) rect=CGRect.golden_section(x: 0, y: 0,
45
+ width: 100) => CGRect([0.0, 0.0], [100.0, 61.8033905029297])
46
+
47
+ The fifth exponent of the golden ratio comes out to 11.08. Instead of
48
+ making a label that takes up a tenth of the screen, you could try
49
+ this:
50
+
51
+ CGRect.golden_section(x: 0, y: 0, width: 100, exponent: 5) =>
52
+ CGRect([0.0, 0.0], [100.0, 9.01699829101562])
53
+
54
+ The instance methods take an existing object and return a new object
55
+ based on it. They take a direction, either :width or :height, and
56
+ optionally an exponent.
57
+
58
+ point.golden_section(:x) => CGPoint(61.8033905029297,
59
+ 61.8033905029297) size.golden_section(:width) =>
60
+ CGSize(61.8033905029297, 61.8033905029297) rect.golden_section(:width)
61
+ => CGRect([0.0, 0.0], [61.8033905029297, 61.8033905029297])
62
+
63
+ Finally, you can use the golden_split method to split a CGRect into
64
+ two. It has two parameters. First, specify the direction to split the
65
+ rectangle, either :width or :height. Imagine folding a piece of paper
66
+ along its width or length. The second parameter controls which section
67
+ should have the greater area, either :first or :last. It returns an
68
+ array containing the two CGRect objects.
69
+
70
+ rect=CGRect.new([0,0],[100,100]) => CGRect([0.0, 0.0], [100.0, 100.0])
71
+ rect.golden_split(:width) => [CGRect([0.0, 0.0], [61.8033905029297,
72
+ 100.0]), CGRect([61.8033905029297, 0. 0], [38.1965942382812, 100.0])]
73
+ rect.golden_split(:height) => [CGRect([0.0, 0.0], [100.0,
74
+ 61.8033905029297]), CGRect([0.0, 61.803390502929 7], [100.0,
75
+ 38.1965942382812])] rect.golden_split(:height, :last) => [CGRect([0.0,
76
+ 0.0], [100.0, 38.1966094970703]), CGRect([0.0, 38.196609497070 3],
77
+ [100.0, 61.8034210205078])]
78
+
79
+ And that should just about do it. Have fun making beautiful apps.
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+ require 'geomotion'
5
+
6
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
7
+ Motion::Project::App.setup do |app|
8
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
9
+ end
@@ -0,0 +1,27 @@
1
+ class CGPoint
2
+
3
+ # Given an x or y coordinate, returns a point with the other coordinate set to
4
+ # the golden section
5
+ # @param options [hash] either the :x or :y coordinate, and optionally exponent
6
+ # @return [CGPoint] the new point
7
+ def self.golden_section(options)
8
+ Golden_Sections.handler(Golden_Sections::CGPoint_relations, options, &Golden_Sections::CGPoint_proc)
9
+ end
10
+
11
+ # Returns a CGPoint with one or both coordinates as a golden section
12
+ # @param direction [Symbol] Which coordinate to modify - :x, :y, or :both, the default.
13
+ # @param exp [Integer] The exponent of the golden mean, defaults to 1
14
+ # @return [CGPoint] The new CGPoint
15
+ def golden_section(direction=:both, exp=1)
16
+ if direction==:both
17
+ CGPoint.new(self.x.golden_section(exp), self.y.golden_section(exp))
18
+ elsif direction==:x
19
+ CGPoint.new(self.x.golden_section(exp), self.y)
20
+ elsif direction==:y
21
+ CGPoint.new(self.x, self.y.golden_section(exp))
22
+ else
23
+ raise "CGPoint: unknown direction #{direction}"
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,59 @@
1
+ class CGRect
2
+
3
+ # Creates a CGRect with the proportions of the golden section
4
+ # @param options [Hash] The combination of size and height parameters, and optionally exponent.
5
+ # :x, :y, or both
6
+ # :width, :height, or both
7
+ # The method fills in the missing attributes.
8
+ # @return [CGRect] the new object
9
+ def self.golden_section(options)
10
+ Golden_Sections::handler(Golden_Sections::CGRect_relations, options, &Golden_Sections::CGRect_proc)
11
+ end
12
+
13
+ # Creates a new CGRect changing the width, height, or both in the proportion of
14
+ #the golden section
15
+ # direction [Symbol] :width, :height, or :both, the dfeault
16
+ # @param exp [Integer] the exponent of the golden mean, deafults to 1
17
+ # @return [CGRect] the new object
18
+ def golden_section(direction=:both, exp=1)
19
+ rect=self.dup
20
+ fixed=false
21
+ if direction==:width||direction==:both
22
+ rect.width=rect.width.golden_section(exp)
23
+ fixed=true
24
+ end
25
+ if direction==:height||direction==:both
26
+ rect.height=rect.height.golden_section(exp)
27
+ fixed=true
28
+ end
29
+ raise "CGRect#golden_section: unknown direction: #{direction}" unless fixed
30
+ rect
31
+ end
32
+
33
+ # Splits a rectangle into two, with the proportion of the golden section
34
+ # @param direction [Symbol] :width or :height, this controls how to split the rectangle. Imagine folding a piece of paper along its width or length.
35
+ # @param greater [Symbol] controls which rectangle has the greater area, :first or :last. Defaults to :first.
36
+ # @return [Array] an array of the two CGRect objects
37
+ def golden_split(direction, greater=:first)
38
+ raise "Golden_Section#golden_split: unknown direction #{direction}" unless [:width, :height].member?(direction)
39
+ raise "Golden_Section.golden_split: Unknown greater section #{greater}" unless [:first, :last].member?(greater)
40
+ if greater==:first
41
+ exp=1
42
+ else
43
+ exp=2
44
+ end
45
+ rect1=self.golden_section(direction,exp)
46
+ if greater==:first
47
+ exp=1
48
+ else
49
+ exp=-1
50
+ end
51
+ if direction==:width
52
+ rect2=rect1.beside.width(rect1.width.golden_section(exp))
53
+ else
54
+ rect2=rect1.below.height(rect1.height.golden_section(exp))
55
+ end
56
+ [rect1,rect2]
57
+ end
58
+
59
+ end
@@ -0,0 +1,28 @@
1
+ class CGSize
2
+
3
+ # Given a width or height, returns a new CGSize object with the other
4
+ # set to the golden section
5
+ # @param options [Hash] the width or height, and optionally exponent
6
+ # @return [CGSize] the new CGSize object
7
+ def self.golden_section(options)
8
+ Golden_Sections::handler(Golden_Sections::CGSize_relations, options, &Golden_Sections::CGSize_proc)
9
+ end
10
+
11
+ # Returns a new CGSize object with the width, height, or both modified
12
+ #to conform to the golden section
13
+ # @param direction [Symbol] :width, :height, or :both, the default
14
+ # @param exp [Integer] the exponent of the golden mean, defaults to 1
15
+ # @return [CGSize] the new object
16
+ def golden_section(direction=:both, exp=1)
17
+ if direction==:both
18
+ CGSize.new(self.width.golden_section(exp), self.height.golden_section(exp))
19
+ elsif direction==:width
20
+ CGSize.new(self.width.golden_section(exp), self.height)
21
+ elsif direction==:height
22
+ CGSize.new(self.width, self.height.golden_section(exp))
23
+ else
24
+ raise "CGSize#golden_section: unknown direction #{direction}"
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,18 @@
1
+ class Golden_Sections
2
+
3
+ # The version of golden-sections
4
+ Version='0.0.2'
5
+
6
+ # The all-important golden mean
7
+ Golden_Mean=1.6180339
8
+
9
+ # Relations of CGPoint attributes
10
+ CGPoint_relations = {:x => :y}
11
+
12
+ # Relations of CGSize attributes
13
+ CGSize_relations = {:width => :height}
14
+
15
+ # Relations of CGRect attributes
16
+ CGRect_relations = {:x => :y, :width => :height}
17
+
18
+ end
@@ -0,0 +1,4 @@
1
+ class Golden_Sections
2
+
3
+ end
4
+
@@ -0,0 +1,30 @@
1
+ # Golden_Sections handler for common methods
2
+
3
+ class Golden_Sections
4
+
5
+ # A common handler for golden_section methods
6
+ # @param relations [Hash] the set of relations to use
7
+ # @param options [Hash] the options passed by the user
8
+ # @param init [Proc] the initialization method to call
9
+ def self.handler(relations, options, &init)
10
+ options[:exponent]||=1
11
+ relations.each do |relation1, relation2|
12
+ if options[relation1]&&!options[relation2]
13
+ options[relation2]=options[relation1].golden_section(options[:exponent])
14
+ elsif options[relation2]&&!options[relation1]
15
+ options[relation1]=options[relation2].golden_section(options[:exponent])
16
+ end
17
+ end
18
+ init.call(options)
19
+ end
20
+
21
+ # CGPoint initializer
22
+ CGPoint_proc=lambda {|options| CGPoint.new(options[:x], options[:y])}
23
+
24
+ # CGSize initializer
25
+ CGSize_proc=lambda {|options| CGSize.new(options[:width], options[:height])}
26
+
27
+ # CGRect initializer
28
+ CGRect_proc = lambda {|options| CGRect.new([options[:x], options[:y]], [options[:width], options[:height]])}
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ # Golden Sections mathematical methods
2
+
3
+ class Numeric
4
+
5
+ # Returns the golden section of a number
6
+ # @param exponent [Numeric] the exponent of the golden mean, defaults to 1
7
+ def golden_section(exponent=1)
8
+ self/(Golden_Sections::Golden_Mean**exponent)
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goldensections
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Austin Seraphin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: geomotion
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Easily make views based on the golden section
42
+ email:
43
+ - austin@austinseraphin.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/goldensections.rb
50
+ - lib/project/cg_point.rb
51
+ - lib/project/cg_rect.rb
52
+ - lib/project/cg_size.rb
53
+ - lib/project/constants.rb
54
+ - lib/project/goldensections.rb
55
+ - lib/project/handler.rb
56
+ - lib/project/math.rb
57
+ homepage: https://github.com/austinseraphin/goldensections
58
+ licenses:
59
+ - GPL
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Welcome to Golden Sections, a RubyMotion gem for creating views based on
81
+ the golden mean. I wrote this gem because using the golden mean looks naturally
82
+ beautiful. Instead of guessing or picking round numbers, why not use something more
83
+ appealing? Give your app the Midas
84
+ test_files: []