vissen-output 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee97aa25edd367c68a4f113fac72270890711d5859eb61bec40a71470753fb8e
4
- data.tar.gz: c1069056b86a4f7d62ab4e5d5602bcf5c8131d684e8dc9631955f2582d516e3a
3
+ metadata.gz: e1f284f6ad345d37cb5c25d694d590c209272e00f385abcf6fa334c960adf3d0
4
+ data.tar.gz: ec8fd6ce58c0f326ec4abf696abf9a385a06e6df038015d37abac3bea7dc0b2a
5
5
  SHA512:
6
- metadata.gz: 7475b3b4f78d4fd8f0a656d9dc3e45ade1af5a06e1596df9faa5de8eaa508c3489001b714aaf8f509f9b09d9416ecd99c95ac8682aa17f4cc5ced85003299ad1
7
- data.tar.gz: 9c552a4b52af3646f6459116e3dda5a297c147886f90c261bb85448b1c978eda53155f68028d186af7b7fa0a77c428e4c9e598ae2ae2ebfb67069e46f2ba54ab
6
+ metadata.gz: 47c9ba55e30155f5167bfe12b6eac0120924bf8e30e5097ce30d548a7ef613c3c9c4d4844525b7a23971a0b2c67c207a536dedf8c35bf3b43ad085ba3a171658
7
+ data.tar.gz: 61eddc34c45113076783b59676262d1cbf28be8b6ceaaed7446d8802cf95cd8bc08ed2a604e1602a7d37f445574367d52fb8d8d4f4ff07c6b4559981cf93aa30
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+ ### Added
9
+ - Introduced the #center method in contexts to easily find the x and y coordinates of the center point.
10
+ - The utility method Context#each_polar_offset.
11
+ - Palette#discretize creates a new discrete copy of a palette.
12
+
13
+ ### Changed
14
+ - Context#distance_squared now yields each distance to a block instead of writing to an array.
15
+ - Changed the name of Context#distance_squared to Context#each_distance_squared. The old method is still available as an alias.
16
+ - Vixels no longer truncate values (for performance reasons).
17
+
8
18
  ## [0.6.1] - 2018-04-20
9
19
  ### Changed
10
20
  - Improved, more descriptive comments.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vissen-output (0.6.1)
4
+ vissen-output (0.6.2.pre)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -16,6 +16,7 @@ GEM
16
16
  powerpack (0.1.1)
17
17
  rainbow (3.0.0)
18
18
  rake (10.5.0)
19
+ redcarpet (3.4.0)
19
20
  rubocop (0.55.0)
20
21
  parallel (~> 1.10)
21
22
  parser (>= 2.5)
@@ -30,6 +31,7 @@ GEM
30
31
  simplecov-html (~> 0.10.0)
31
32
  simplecov-html (0.10.2)
32
33
  unicode-display_width (1.3.0)
34
+ yard (0.9.12)
33
35
 
34
36
  PLATFORMS
35
37
  ruby
@@ -38,9 +40,11 @@ DEPENDENCIES
38
40
  bundler (~> 1.16)
39
41
  minitest (~> 5.0)
40
42
  rake (~> 10.0)
43
+ redcarpet (~> 3.4)
41
44
  rubocop (~> 0.52)
42
45
  simplecov (~> 0.16)
43
46
  vissen-output!
47
+ yard (~> 0.9)
44
48
 
45
49
  BUNDLED WITH
46
50
  1.16.1
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # Vissen::Output
1
+ # 🥀 Vissen Output
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/vissen-output.svg)](https://badge.fury.io/rb/vissen-output)
3
4
  [![Build Status](https://travis-ci.org/midi-visualizer/vissen-output.svg?branch=master)](https://travis-ci.org/midi-visualizer/vissen-output)
4
5
  [![Inline docs](http://inch-ci.org/github/midi-visualizer/vissen-output.svg?branch=master)](http://inch-ci.org/github/midi-visualizer/vissen-output)
6
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/vissen-output/)
5
7
 
6
8
  The Vissen Output library implements the objects used by the Vissen Engine to talk to the various sinks.
7
9
 
@@ -23,7 +25,33 @@ Or install it yourself as:
23
25
 
24
26
  ## Usage
25
27
 
26
- TODO: Write usage instructions here
28
+ ```ruby
29
+ include Vissen::Output
30
+
31
+ # First we create a grid shaped context with 64 points.
32
+ context = Context::Grid.new 8, 8
33
+
34
+ # We then create a vixel stack with a single layer.
35
+ stack = VixelStack.new context, 1
36
+
37
+ # We go through each vixel in the layer and randomize its
38
+ # palette value (p). We also set the layer palette to
39
+ # palette number 1.
40
+ stack.layers[0].tap do |layer|
41
+ layer.palette = 1
42
+ layer.each do |vixel|
43
+ vixel.i = 1.0
44
+ vixel.p = rand
45
+ end
46
+ end
47
+
48
+ # Finally we allocate a pixel buffer and render to it.
49
+ pixel_buffer = stack.pixel_buffer
50
+ stack.render pixel_buffer
51
+
52
+ ```
53
+
54
+ Please see the [documentation](http://www.rubydoc.info/gems/vissen-output/) for more details.
27
55
 
28
56
  ## Development
29
57
 
data/Rakefile CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rake/testtask'
5
5
  require 'rubocop/rake_task'
6
+ require 'yard'
6
7
 
7
8
  Rake::TestTask.new(:test) do |t|
8
9
  t.libs << 'test'
@@ -10,8 +11,14 @@ Rake::TestTask.new(:test) do |t|
10
11
  t.test_files = FileList['test/**/*_test.rb']
11
12
  end
12
13
 
13
- RuboCop::RakeTask.new(:rubocop) do |t|
14
- t.options = ['-a']
14
+ RuboCop::RakeTask.new(:rubocop)
15
+
16
+ YARD::Rake::YardocTask.new(:yard) do |t|
17
+ t.stats_options = %w[--list-undoc]
18
+ t.files = ['lib/**/*.rb', '-', 'CHANGELOG.md']
15
19
  end
16
20
 
17
- task default: :test
21
+ desc 'Generate Ruby documentation'
22
+ task doc: %w[yard]
23
+
24
+ task default: %w[test rubocop:auto_correct]
@@ -71,6 +71,14 @@ module Vissen
71
71
  Array.new(point_count, &block)
72
72
  end
73
73
 
74
+ # Uses the width and height och the context to calculate the x and y
75
+ # coordinates of the center point.
76
+ #
77
+ # @return [Array<Float>] the center coordinates.
78
+ def center
79
+ [width / 2.0, height / 2.0]
80
+ end
81
+
74
82
  # Iterates over the context points. The index of the the point is passed
75
83
  # to the given block.
76
84
  #
@@ -113,20 +121,43 @@ module Vissen
113
121
  index
114
122
  end
115
123
 
116
- # This utility method traverses the given target array and calculates for
117
- # each corresponding grid point index the squared distance between the
118
- # point and the given coordinate.
124
+ # This utility method calculates the squared distance between each point
125
+ # and the given coordinate. The squared distance is then yielded to the
126
+ # given block.
119
127
  #
120
128
  # @param x [Numeric] the x coordinate to calculate distances from.
121
129
  # @param y [Numeric] the y coordinate to calculate distances from.
122
- # @param target [Array<Float>] the target array to populate with
123
- # distances.
124
- def distance_squared(x, y, target)
125
- target.each_with_index do |_, i|
126
- x_i, y_i = position i
130
+ # @return [Enumerable] if no block is given.
131
+ def each_distance_squared(x, y)
132
+ return to_enum(__callee__, x, y) unless block_given?
133
+
134
+ each_position do |_, x_i, y_i|
135
+ yield (x_i - x)**2 + (y_i - y)**2
136
+ end
137
+ end
138
+
139
+ alias distance_squared each_distance_squared
140
+
141
+ # This method calculates the distance and angle to each point and the
142
+ # given coordinate. The distance and angle are then yielded to the given
143
+ # block.
144
+ #
145
+ # @param x [Numeric] the x coordinate to calculate angle and distance
146
+ # from.
147
+ # @param y [Numeric] the y coordinate to calculate angle and distance
148
+ # from.
149
+ # @return [Enumerable] if no block is given.
150
+ def each_polar_offset(x, y)
151
+ return to_enum(__callee__, x, y) unless block_given?
152
+
153
+ each_position do |_, x_i, y_i|
127
154
  dx = x_i - x
128
155
  dy = y_i - y
129
- target[i] = (dx * dx) + (dy * dy)
156
+
157
+ distance = Math.sqrt(dx**2 + dy**2)
158
+ angle = Math.atan2 dy, dx
159
+
160
+ yield distance, angle
130
161
  end
131
162
  end
132
163
  end
@@ -24,8 +24,7 @@ module Vissen
24
24
  to = if range.exclude_end?
25
25
  raise ArgumentError if range.end.is_a?(Float)
26
26
  range.end - 1
27
- else
28
- range.end
27
+ else range.end
29
28
  end
30
29
 
31
30
  design_function from, to, steps
@@ -52,6 +52,12 @@ module Vissen
52
52
  super
53
53
  end
54
54
 
55
+ # @param steps [Fixnum] the number of discrete colors in the new palette.
56
+ # @return [Palette] a new, discrete palette.
57
+ def discretize(steps)
58
+ self.class.new(*@colors, steps: steps, label: @label)
59
+ end
60
+
55
61
  # Discretize the palette into the given number of values. Palettes defined
56
62
  # with a step count are sampled as if they where continuous.
57
63
  #
@@ -75,11 +81,12 @@ module Vissen
75
81
  private
76
82
 
77
83
  def define_discrete_accessor(steps)
78
- @palette = to_a steps
84
+ @palette = to_a(steps).freeze
85
+ last_color_index = @palette.length - 1
79
86
  define_singleton_method :[] do |index|
80
- index = if index >= 1.0 then @palette.length - 1
87
+ index = if index >= 1.0 then last_color_index
81
88
  elsif index < 0.0 then 0
82
- else (index * (@palette.length - 1)).floor
89
+ else (index * last_color_index).floor
83
90
  end
84
91
 
85
92
  @palette[index]
@@ -3,6 +3,6 @@
3
3
  module Vissen
4
4
  module Output
5
5
  # The Vissen Output library version number.
6
- VERSION = '0.6.1'
6
+ VERSION = '0.7.0'
7
7
  end
8
8
  end
@@ -9,10 +9,10 @@ module Vissen
9
9
  # TODO: How do we want the vixel to saturate? When written or when read?
10
10
  class Vixel
11
11
  # @return [Float] the vixel intensity.
12
- attr_reader :i
12
+ attr_accessor :i
13
13
 
14
14
  # @return [Float] the vixel palette position.
15
- attr_reader :p
15
+ attr_accessor :p
16
16
 
17
17
  # @param i [Numeric] the vixel intensity.
18
18
  # @param p [Numeric] the vixel palette position.
@@ -30,35 +30,10 @@ module Vissen
30
30
  false
31
31
  end
32
32
 
33
- # @param value [Numeric] the new intensity value.
34
- # @return [Float] the truncated intensity value.
35
- def i=(value)
36
- @i = self.class.truncate value
37
- end
38
-
39
- # @param value [Numeric] the new palette position.
40
- # @return [Float] the truncated palette position.
41
- def p=(value)
42
- @p = self.class.truncate value
43
- end
44
-
45
33
  # @return [String] a string representation of the vixel.
46
34
  def inspect
47
35
  format '(%.1f, %.1f)', @i, @p
48
36
  end
49
-
50
- class << self
51
- # Makes sure n is in the range 0..1.
52
- #
53
- # @param n [Numeric] the value to truncate.
54
- # @return [Float] n truncated to fit within the range 0..1.
55
- def truncate(n)
56
- if n <= 0 then 0.0
57
- elsif n >= 1 then 1.0
58
- else n
59
- end
60
- end
61
- end
62
37
  end
63
38
  end
64
39
  end
@@ -26,6 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'bundler', '~> 1.16'
27
27
  spec.add_development_dependency 'minitest', '~> 5.0'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'redcarpet', '~> 3.4'
29
30
  spec.add_development_dependency 'rubocop', '~> 0.52'
30
31
  spec.add_development_dependency 'simplecov', '~> 0.16'
32
+ spec.add_development_dependency 'yard', '~> 0.9'
31
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vissen-output
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Lindberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-20 00:00:00.000000000 Z
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.16'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
83
111
  description: The output module implements all the objects and facilities used to talk
84
112
  to vissen sinks.
85
113
  email: