color_wave 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8bea5c65d46bd4ff80b996381338abf97fae6f3
4
- data.tar.gz: d58e46eb0b84ab91bac57e499c4a0f6dea860a40
3
+ metadata.gz: 5aacaab444c91b6fe32b1f2254db321b7238db5b
4
+ data.tar.gz: fe295feaaf56f627ab5ad3eb546191a552e20cbe
5
5
  SHA512:
6
- metadata.gz: 22577827d698abec6d8756bfe269709084bfd69f78178cc7699ae92e5fc4eb4b218ffa73ea4b7a5ddd286d10c68c70eaefebba13e203a2a2b770b14735a5daf4
7
- data.tar.gz: 41858f0d4330b53921e30e33bd15f08174b1078729d9c094aefe7faf41cba6a745c805fb1b758d14f9e2cca8b7fd4f10f6044dea583ce364c0c5d7cb59624e9b
6
+ metadata.gz: 9904322801784ecd78448a9029ee7fb18a98c6af69db7664be87e54a68f6e420f2b3b2a0457261951d6a9b5f73f40e09be0490bfb0b48fda638f3ae194b77241
7
+ data.tar.gz: 7a18164cbef3291c0494aeed4bcea9b387abd085ea29b9d2eb56a14e9f3acc20fa2e2305dd6f51373475b2bc0650f9903882fed237054c38b1bea2960c66feba
data/README.md CHANGED
@@ -21,26 +21,29 @@ Or install it yourself as:
21
21
 
22
22
  You can run it from the command line with or without some options:
23
23
 
24
- $ color_wave --lines 10 --cycles 2
24
+ $ color_wave --lines 20 --cycles 3 --speed 10.0
25
+
26
+ The above values are the defaults.
27
+ ##### Options
28
+ * `--lines` - the height of the wave in terminal lines
29
+ * `--cycles` - how many cycles of the wave will be drawn
30
+ * `--speed` - used as the divisor of the delay time between drawing loops; use higher values for faster redrawing
31
+ * `--help` - show usage information
25
32
 
26
33
  You can use it in Ruby too:
27
34
  ```ruby
28
35
  require 'color_wave'
29
36
 
30
- ColorWave.new(lines: 10, cycles: 2, colors: %w( ff0000 00ff00 0000ff ), chars: %w( _ / ^ \ )).run
37
+ ColorWave.new(lines: 10, cycles: 2, speed: 1, colors: %w( ff0000 00ff00 0000ff ), chars: %w( _ / ^ \ )).run
31
38
  ```
32
39
 
33
- `Ctrl-C` will stop it once it's running.
34
-
35
- ## Development
40
+ The `speed` option is used as the divisor to a `BASE_SLEEP_TIME` constant so higher speeds will redraw the wave more quickly. The `colors` and `chars` options specify the colors and characters to be cycled through when drawing the wave.
36
41
 
37
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
-
39
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ `Ctrl-C` will stop it once it's running.
40
43
 
41
44
  ## Contributing
42
45
 
43
- Bug reports and pull requests are welcome on GitHub at https://github.com/jbratton/color_wave. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jbratton/color_wave. This project is intended to be a safe, welcoming space for collaboration and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
44
47
 
45
48
  ## License
46
49
 
@@ -3,14 +3,14 @@
3
3
  require 'color_wave'
4
4
  require 'trollop'
5
5
 
6
- DEFAULT_LINES = 20
7
- DEFAULT_CYCLES = 3
8
-
9
6
  opts = Trollop::options do
10
- opt :lines, "Wave height in lines", default: DEFAULT_LINES
11
- opt :cycles, "Wave cycles to display", default: DEFAULT_CYCLES
7
+ opt :lines, "Wave height in lines", default: ColorWave::DEFAULT_LINES
8
+ opt :cycles, "Wave cycles to display", default: ColorWave::DEFAULT_CYCLES
9
+ opt :speed, "Speed of redrawing", default: ColorWave::DEFAULT_SPEED
12
10
  end
11
+
13
12
  Trollop::die :lines, "must be greater than zero" unless opts[:lines] > 0
14
13
  Trollop::die :cycles, "must be greater than zero" unless opts[:cycles] > 0
14
+ Trollop::die :speed, "must be greater than zero" unless opts[:speed] > 0
15
15
 
16
- ColorWave.new(lines: opts[:lines], cycles: opts[:cycles]).run
16
+ ColorWave.new(lines: opts[:lines], cycles: opts[:cycles], speed: opts[:speed]).run
@@ -8,6 +8,7 @@ class ColorWave
8
8
  DEFAULT_LINES = 20
9
9
  DEFAULT_CHARS = %w( O ).freeze
10
10
  DEFAULT_CYCLES = 3
11
+ DEFAULT_SPEED = 10.0
11
12
 
12
13
  # rainbow RGB values stolen from Term-Colormap on CPAN
13
14
  # https://metacpan.org/source/XXFELIXXX/Term-Colormap-0.06/lib/Term/Colormap.pm
@@ -19,18 +20,19 @@ class ColorWave
19
20
  ).freeze
20
21
 
21
22
  TWO_PI = Math::PI * 2
22
- LOOP_SLEEP = 0.00001
23
+ BASE_SLEEP_TIME = 0.001
23
24
 
24
- attr_reader :lines, :cycles, :chars, :colors
25
+ attr_reader :lines, :cycles, :chars, :colors, :speed
25
26
 
26
27
  def initialize(lines: DEFAULT_LINES, cycles: DEFAULT_CYCLES,
27
- chars: DEFAULT_CHARS, colors: DEFAULT_COLORS)
28
+ chars: DEFAULT_CHARS, colors: DEFAULT_COLORS,
29
+ speed: DEFAULT_SPEED)
28
30
  @lines = lines
29
31
  @cycles = cycles
30
32
  @chars = chars.cycle
31
33
  @colors = colors.cycle
34
+ @speed = speed
32
35
 
33
- @sleep_time = LOOP_SLEEP
34
36
  @current_line = 0
35
37
  @shutdown = false
36
38
 
@@ -51,7 +53,7 @@ class ColorWave
51
53
 
52
54
  private
53
55
 
54
- attr_accessor :current_line, :cycles, :shutdown, :sleep_time, :wave_rows
56
+ attr_accessor :current_line, :cycles, :shutdown, :wave_rows
55
57
 
56
58
  def width
57
59
  TermInfo.screen_width
@@ -83,12 +85,17 @@ class ColorWave
83
85
 
84
86
  def write_one_pass(pass)
85
87
  width.times do |step|
88
+ break if shutdown
86
89
  move_to_line next_line
87
90
  print Rainbow(next_char).color(next_color(pass, step))
88
91
  sleep sleep_time
89
92
  end
90
93
  end
91
94
 
95
+ def sleep_time
96
+ BASE_SLEEP_TIME / speed
97
+ end
98
+
92
99
  def ready_next_pass
93
100
  print "\r"
94
101
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class ColorWave
3
- VERSION = '0.0.5'
3
+ VERSION = '0.1.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_wave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jbratton
@@ -113,8 +113,6 @@ email:
113
113
  - jeremy@alumni.rice.edu
114
114
  executables:
115
115
  - color_wave
116
- - console
117
- - setup
118
116
  extensions: []
119
117
  extra_rdoc_files: []
120
118
  files:
@@ -126,8 +124,6 @@ files:
126
124
  - README.md
127
125
  - Rakefile
128
126
  - bin/color_wave
129
- - bin/console
130
- - bin/setup
131
127
  - color_wave.gemspec
132
128
  - lib/color_wave.rb
133
129
  - lib/color_wave/color_wave.rb
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "color_wave"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- require "pry"
10
- Pry.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here