gray_scott_gtk3 0.5.3 → 0.5.7

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: ef4f58211b0ab0cd8b0bbc3fdab15dadc240f4f2fb9cb4b22d6d49d85e696d7a
4
- data.tar.gz: d0d8fc77fae048d5fd9250805cf202c4e35a9d5799c26a3ae5ad65f8e87c90c3
3
+ metadata.gz: 4b05f0ded43ea9aacb610353610ceee7467ea79e9780910b99aca883268a2e5a
4
+ data.tar.gz: 478e33120c796fa6c4d05f353d7e5193b83d94cabd94936966df41d128fcf84e
5
5
  SHA512:
6
- metadata.gz: 57eb46e7262c6fa35cd4937bb849731c685bdb312f0c5066ee71c51a87bced2709fbae0428aa2040ae1c492f8f663596989dcbff82612df93fb430bde934356d
7
- data.tar.gz: 56fe55ecdf81df295cae9c1e02f48839c403abb2586d82cfefcb918a5308eada89625b788dc0dec772f0b6bce1924015aff720f5c423997dc2881657660cab61
6
+ metadata.gz: 48b77d17fce3734b60a27521f478bad40a8fb7caada166ddcf7f49a6f95529366220eb1d8880a869c6464c8c595129a86fda68a84b2f2f826c68ac96179053b4
7
+ data.tar.gz: 586fb519f89010e7c72decfcb9610c5348d17597c258e1997d5bc131f2b57d40df7e682daf55dd9403cd0ea04ab3db23fb65cdfd18c671cfb3b588a02f45fd51
@@ -0,0 +1,2 @@
1
+ github: kojix2
2
+ ko_fi: kojix2
@@ -0,0 +1,21 @@
1
+ name: test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ build:
5
+ name: ${{ matrix.os }} Ruby ${{ matrix.ruby }}
6
+ runs-on: ${{ matrix.os }}-latest
7
+ strategy:
8
+ matrix:
9
+ os: [ 'ubuntu' ]
10
+ ruby: [ '2.6', '2.7', '3.0' ]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ - run: |
17
+ sudo apt install -y xvfb libgtk-3-0
18
+ - run: |
19
+ bundle install
20
+ - run: |
21
+ xvfb-run bundle exec rake spec
data/.gitignore CHANGED
@@ -1,55 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
3
  *.glade~
4
- /.config
5
4
  /coverage/
6
- /InstalledFiles
7
- /pkg/
8
- /spec/reports/
9
- /spec/examples.txt
10
- /test/tmp/
11
- /test/version_tmp/
12
5
  /tmp/
13
-
14
- # Used by dotenv library to load environment variables.
15
- # .env
16
-
17
- ## Specific to RubyMotion:
18
- .dat*
19
- .repl_history
20
- build/
21
- *.bridgesupport
22
- build-iPhoneOS/
23
- build-iPhoneSimulator/
24
-
25
- ## Specific to RubyMotion (use of CocoaPods):
26
- #
27
- # We recommend against adding the Pods directory to your .gitignore. However
28
- # you should judge for yourself, the pros and cons are mentioned at:
29
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
- #
31
- # vendor/Pods/
32
-
33
- ## Documentation cache and generated files:
34
- /.yardoc/
35
- /_yardoc/
36
- /doc/
37
- /rdoc/
38
-
39
- ## Environment normalization:
40
- /.bundle/
41
- /vendor/bundle
42
- /lib/bundler/man/
43
-
44
- # for a library or gem, you might want to ignore these files since the code is
45
- # intended to run in multiple environments; otherwise, check them in:
46
6
  Gemfile.lock
47
- # .ruby-version
48
- # .ruby-gemset
49
-
50
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
- .rvmrc
52
-
53
- # rspec
54
- /spec/reports/
55
7
  .rspec_status
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/README.md CHANGED
@@ -1,52 +1,41 @@
1
1
  # Gray-Scott
2
2
 
3
- ![screenshot](https://raw.githubusercontent.com/kojix2/Gray-Scott/screenshot/screenshot/screenshot.gif)
3
+ [![Gem](https://img.shields.io/gem/v/gray_scott_gtk3)](https://rubygems.org/gems/gray_scott_gtk3)
4
+ [![build status](https://travis-ci.com/kojix2/Gray-Scott.svg?branch=master)](https://travis-ci.com/github/kojix2/Gray-Scott)
5
+ [![DOI](https://zenodo.org/badge/158914232.svg)](https://zenodo.org/badge/latestdoi/158914232)
4
6
 
5
- ## Requirements
7
+ Ruby implementation of the Reaction diffusion system (Gray-Scott model).
6
8
 
7
- * Ruby
8
- * Numo/NArray (CPU)
9
- * Cumo/NArray (GPU)
10
- * Ruby/Gtk3
9
+ ![screenshot](https://raw.githubusercontent.com/kojix2/Gray-Scott/screenshot/screenshot/screenshot.gif)
11
10
 
12
11
  ## Installation
13
12
 
14
- $ gem install gray_scott_gtk3
13
+ ```bash
14
+ gem install gray_scott_gtk3
15
+ ```
15
16
 
16
17
  ## Usage
17
18
 
18
- $ grayscott
19
-
20
- $ grayscott -w 256 -h 256 # size of model. display is fixed to 512 x 512 pixels.
21
-
22
- ## Usage with terminal(example)
23
-
24
- $ bundle install
25
-
26
- $ bundle exec bin/console
27
-
28
- ```ruby
29
- c = GrayScott::Controller.new 'resources/', width:1024, height:1024
19
+ ```bash
20
+ grayscott
21
+ ```
30
22
 
31
- # custom feed / kill ratio
32
- na = Numo::SFloat.new(1024,1).seq + 10 # avoid zero
33
- na = na * Numo::SFloat.ones(1, 1024)
34
- na = na / na.max
35
- f = na * 0.05
36
- k = na.transpose * 0.06 + 0.01
37
- c.model.f = f
38
- c.model.k = k
39
- c.model.v.rand(0.0, 0.15)
40
- c.color = 'reverse_green' # colorful is slow.
41
- Gtk.main
23
+ ```bash
24
+ grayscott --help
25
+ # Usage: grayscott [options]
26
+ # -h, --height val height of the model
27
+ # -w, --width val width of the model
28
+ # -g, --gpu use GPU(Cumo)
42
29
  ```
43
30
 
31
+ NOTE : You can set the width and height of the model, but the width and height of the window is fixed at 512 x 512 pixels.
32
+
44
33
  ![screenshot](https://raw.githubusercontent.com/kojix2/Gray-Scott/screenshot/screenshot/reverse-green.png)
45
34
 
46
35
  ## Known issue
47
36
 
48
37
  Glib::Timeout.add(number_of_seconds)
49
- If processing can not be completed within the time, it will not be displayed.
38
+ If processing can not be completed within the time, it will not be displayed.
50
39
  In this case, you should increase the number of seconds.
51
40
 
52
41
  ## Contributing
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/exe/grayscott CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'optparse'
4
5
 
5
- opt = {}
6
+ opt = { width: 256, height: 256 }
6
7
  OptionParser.new do |op|
7
- op.on('-h val', '--height', 'height of the model') { |v| opt[:height] = v.to_i }
8
- op.on('-w val', '--width', 'width of the model') { |v| opt[:width] = v.to_i }
8
+ op.on('-h val', '--height', 'height of the model', Integer) { |v| opt[:height] = v }
9
+ op.on('-w val', '--width', 'width of the model', Integer) { |v| opt[:width] = v }
9
10
  op.on('-g', '--gpu', 'use GPU(Cumo)') { |v| opt[:gpu] = v }
10
11
  op.parse!(ARGV)
11
12
  end
@@ -19,7 +20,7 @@ module GrayScott
19
20
  class << self
20
21
  def run(opt)
21
22
  xml_path = File.expand_path('../resources/', __dir__)
22
- Controller.new(xml_path, opt)
23
+ Controller.new(xml_path, height: opt[:height], width: opt[:width])
23
24
  Gtk.main
24
25
  end
25
26
  end
@@ -1,6 +1,6 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'gray_scott/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/gray_scott/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'gray_scott_gtk3'
@@ -12,19 +12,17 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Reaction diffusion system (Gray-Scott model).'
13
13
  spec.homepage = 'https://github.com/kojix2/Gray-Scott'
14
14
 
15
- # Specify which files should be added to the gem when it is released.
16
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
15
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
16
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
17
  end
20
18
  spec.bindir = 'exe'
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.executables = ['grayscott']
22
20
  spec.require_paths = ['lib']
23
21
 
24
22
  spec.add_dependency 'gtk3'
25
23
  spec.add_dependency 'numo-narray'
26
24
 
27
- spec.add_development_dependency 'bundler', '~> 1.17'
28
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
29
27
  spec.add_development_dependency 'rspec'
30
28
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrayScott
2
4
  module Color
3
- include XumoShortHand
4
-
5
5
  def colorize(ar, color_type)
6
6
  case color_type
7
7
  when 'colorful'
@@ -25,23 +25,31 @@ module GrayScott
25
25
  end
26
26
  end
27
27
 
28
+ # speed
29
+ def uInt8_dstack(ar)
30
+ x = UInt8.zeros(*ar[0].shape, 3)
31
+ x[true, true, 0] = ar[0]
32
+ x[true, true, 1] = ar[1]
33
+ x[true, true, 2] = ar[2]
34
+ x
35
+ end
36
+
28
37
  def hsv2rgb(h)
29
- height, width = h.shape
30
38
  i = UInt8.cast(h * 6)
31
39
  f = (h * 6.0) - i
32
- p = UInt8.zeros height, width, 1
33
- v = UInt8.new(height, width, 1).fill 255
40
+ p = UInt8.zeros(*h.shape)
41
+ v = UInt8.new(*h.shape).fill 255
34
42
  q = (1.0 - f) * 256
35
43
  t = f * 256
36
- rgb = UInt8.zeros height, width, 3
37
- t = UInt8.cast(t).expand_dims(2)
38
- i = UInt8.dstack([i, i, i])
39
- rgb[i.eq 0] = UInt8.dstack([v, t, p])[i.eq 0]
40
- rgb[i.eq 1] = UInt8.dstack([q, v, p])[i.eq 1]
41
- rgb[i.eq 2] = UInt8.dstack([p, v, t])[i.eq 2]
42
- rgb[i.eq 3] = UInt8.dstack([p, q, v])[i.eq 3]
43
- rgb[i.eq 4] = UInt8.dstack([t, p, v])[i.eq 4]
44
- rgb[i.eq 5] = UInt8.dstack([v, p, q])[i.eq 5]
44
+ rgb = UInt8.zeros(*h.shape, 3)
45
+ t = UInt8.cast(t)
46
+ i = uInt8_dstack([i, i, i])
47
+ rgb[i.eq 0] = uInt8_dstack([v, t, p])[i.eq 0]
48
+ rgb[i.eq 1] = uInt8_dstack([q, v, p])[i.eq 1]
49
+ rgb[i.eq 2] = uInt8_dstack([p, v, t])[i.eq 2]
50
+ rgb[i.eq 3] = uInt8_dstack([p, q, v])[i.eq 3]
51
+ rgb[i.eq 4] = uInt8_dstack([t, p, v])[i.eq 4]
52
+ rgb[i.eq 5] = uInt8_dstack([v, p, q])[i.eq 5]
45
53
  rgb
46
54
  end
47
55
 
@@ -71,7 +79,7 @@ module GrayScott
71
79
 
72
80
  def grayscale(ar)
73
81
  d = ar * 255
74
- UInt8.dstack([d,d,d])
82
+ uInt8_dstack([d, d, d])
75
83
  end
76
84
 
77
85
  private
@@ -1,14 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrayScott
2
4
  class Controller
3
5
  class AboutDialog
4
6
  def initialize(resource_dir)
5
- @a = Gtk::AboutDialog.new
6
- @a.program_name = 'Gray-Scott'
7
- @a.logo = GdkPixbuf::Pixbuf.new(file: File.join(resource_dir, 'about_icon.png'))
8
- @a.authors = ['kojix2']
9
- @a.version = GrayScott::VERSION
10
- @a.run
11
- @a.destroy
7
+ Gtk::AboutDialog.new.tap do |d|
8
+ d.program_name = 'Gray-Scott'
9
+ d.comments = 'Reaction diffusion system'
10
+ d.logo = GdkPixbuf::Pixbuf.new(file: File.join(resource_dir, 'about_icon.png'))
11
+ d.copyright = 'Copyright (C) kojix2'
12
+ d.authors = ['kojix2']
13
+ d.version = GrayScott::VERSION
14
+ d.website = 'https://github.com/kojix2/Gray-Scott'
15
+ d.website_label = 'Github kojix2/Gray-Scott'
16
+ d.run
17
+ d.destroy
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'controller/aboutdialog'
2
4
 
3
5
  module GrayScott
4
6
  class Controller
5
7
  include Color
6
- include XumoShortHand
7
8
  attr_accessor :resource_dir, :height, :width, :model, :color
8
9
 
9
10
  def initialize(dir, height: 256, width: 256)
@@ -13,14 +14,14 @@ module GrayScott
13
14
  @model = Model.new(height: height, width: width)
14
15
  @show_u = false
15
16
  @color = 'colorful'
16
- @frames = 1
17
+ @frames = 5
17
18
  @msec = 40
18
19
 
19
20
  builder = Gtk::Builder.new
20
21
  builder.add_from_file File.join(resource_dir, 'gray_scott.glade')
21
22
 
22
23
  %w[win execute_button gimage legend_image uv_combobox pen_density pen_radius].each do |s|
23
- instance_variable_set('@' + s, builder.get_object(s))
24
+ instance_variable_set("@#{s}", builder.get_object(s))
24
25
  end
25
26
 
26
27
  builder.connect_signals { |handler| method(handler) }
@@ -1,9 +1,8 @@
1
- module GrayScott
1
+ # frozen_string_literal: true
2
2
 
3
+ module GrayScott
3
4
  # Gray-Scott model
4
5
  class Model
5
- include XumoShortHand
6
-
7
6
  Dx = 0.01
8
7
 
9
8
  # Delta t is the change in time for each iteration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrayScott
2
4
  module Utils
3
5
  module Math
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrayScott
2
- VERSION = '0.5.3'.freeze
4
+ VERSION = '0.5.7'
3
5
  end
data/lib/gray_scott.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gtk3'
2
4
 
5
+ # Support for Cumo
3
6
  if Object.const_defined? :Cumo
4
7
  Xumo = Cumo
5
8
  else
@@ -7,13 +10,14 @@ else
7
10
  Xumo = Numo
8
11
  end
9
12
 
10
- module XumoShortHand
11
- class Xumo::SFloat
13
+ # Monkey patch
14
+ module Xumo
15
+ class SFloat
12
16
  alias _ inplace
13
17
  end
14
- SFloat = Xumo::SFloat
15
- UInt8 = Xumo::UInt8
16
18
  end
19
+ SFloat = Xumo::SFloat
20
+ UInt8 = Xumo::UInt8
17
21
 
18
22
  require 'gray_scott/model'
19
23
  require 'gray_scott/color'