dla 0.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
+ SHA256:
3
+ metadata.gz: 8e1e35e63cdc50dd23e32a232530c7631f989b0735f9671bd1c122bfbbce0a90
4
+ data.tar.gz: 57cc1168e784822859d97db4f431a5dfb20c9d1ff488c076105a11ef8d487879
5
+ SHA512:
6
+ metadata.gz: a5006c46748ee4bd969c73807174258aabf36bf60ff6bb0fcc51927dcc50be0bafd6350bdb951118ab51fcd043b3be8194e901ce7be0e4669a6c104fb8e772fb
7
+ data.tar.gz: 6b05a8681ae5886c141e23484cab2967de9058bdd79d52f6f78523b0aeed241905623967e55e8ca72ba3d572ce855b3a7577bdd027bc60cfb24937eef394ae7b
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ Layout/LeadingCommentSpace:
2
+ Enabled: false
3
+ Naming/MethodName:
4
+ Enabled: false
5
+ Naming/VariableName:
6
+ Enabled: false
7
+ Style/SymbolArray:
8
+ Enabled: false
9
+ Metrics/MethodLength:
10
+ Max: 20
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.5
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-11-09
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at arnaud@meuret.net. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Arnaud Meuret
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,79 @@
1
+ # DLA
2
+
3
+ A Ruby library implementing Diffusion-Limited Aggregation.
4
+
5
+ ## Features
6
+ - Produces simple text file fully describing final render
7
+ - Keeps full tree, not just cell positions
8
+ - Keeps building history
9
+
10
+ ## Planned features
11
+ - [X] Demo app
12
+ - [ ] Move "Save .dla" to library
13
+ - [ ] Display saved .dla file
14
+ - [ ] Upscale
15
+ - [ ] Binary .dla format
16
+ - [ ] Load state from .dla file
17
+ - [ ] Height map
18
+ - [ ] Export bitmap
19
+ - [ ] Make history optional
20
+ - [ ] Multithreading
21
+ - [ ] Make Demo app human-friendly
22
+
23
+ ## Installation
24
+
25
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
26
+
27
+ Install the gem and add to the application's Gemfile by executing:
28
+
29
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
30
+
31
+ If bundler is not being used to manage dependencies, install the gem by executing:
32
+
33
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
34
+
35
+ ## Usage
36
+
37
+ Default arguments are fine (1280x720 bounds)
38
+
39
+ Let it run for a while:
40
+ ``` ruby
41
+ require 'dla'
42
+ root = DLA::Node.root
43
+ n = DLA::Node.new root:
44
+ loop do
45
+ n.move
46
+ if n.parent # Node has found another node
47
+ n = DLA::Node.new root:
48
+ end
49
+ break if bored
50
+ end
51
+
52
+ ```
53
+ Inspect state:
54
+ ``` ruby
55
+ root.nodes.each{|n| puts n}
56
+ ```
57
+ ## Demo app
58
+
59
+ A quick and dirty demo app is in `./bin/dla.rb`.
60
+
61
+ Because Rubygems are not supposed to be used to distribute apps, you'll need to run the app from the project directory after running `bundle install` in order to satisfy the requirement of my fork of `TTY:Box`.
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ameuret/dla. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ameuret/dla/blob/main/CODE_OF_CONDUCT.md).
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [Unlicense](https://unlicense.org)
76
+
77
+ ## Code of Conduct
78
+
79
+ Everyone interacting in the DLA project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ameuret/dla/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DLA
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dla.rb ADDED
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dla/version'
4
+
5
+ module DLA
6
+ class Error < StandardError; end
7
+
8
+ class Node
9
+ attr_accessor :xBound, :yBound, :root, :x, :y, :parent, :nodes, :ix, :iy, :history
10
+
11
+ def self.root(x: nil, y: nil, xBound: 1280, yBound: 720)
12
+ r = Node.new root: nil
13
+ r.x = r.ix = x || xBound / 2
14
+ r.y = r.iy = y || yBound / 2
15
+ r.nodes << r
16
+ r
17
+ end
18
+
19
+ def initialize(root:, xBound: 1280, yBound: 720)
20
+ @root = root || self
21
+ @xBound = xBound
22
+ @yBound = yBound
23
+ @nodes = []
24
+ @x, @y = randomFreePos
25
+ @ix, @iy = @x, @y
26
+ @children = {}
27
+ @history = String.new
28
+ end
29
+
30
+ def at(x, y)
31
+ allTreeNodes.find { |n| n.x == x && n.y == y }
32
+ end
33
+
34
+ def north
35
+ @children[:north]
36
+ end
37
+
38
+ def south
39
+ @children[:south]
40
+ end
41
+
42
+ def east
43
+ @children[:east]
44
+ end
45
+
46
+ def west
47
+ @children[:west]
48
+ end
49
+
50
+ def allTreeNodes
51
+ @root.nodes
52
+ end
53
+
54
+ def attach(node, position)
55
+ raise ArgumentError, 'position must be :north, :south, :east, :west' unless [:north, :south, :east, :west].include? position
56
+
57
+ @children[position] = node
58
+ node.parent = self
59
+ raise ArgumentError, 'Node is already present' if allTreeNodes.include? node
60
+
61
+ @root.nodes << node
62
+ end
63
+
64
+ def randomFreePos(forcedX: nil, forcedY: nil)
65
+ x = y = 0
66
+ loop do
67
+ x = rand @xBound
68
+ y = rand @yBound
69
+ break unless @root.at x, y
70
+ end
71
+ [x, y]
72
+ end
73
+
74
+ def oppositeDirection(dir)
75
+ {
76
+ north: :south,
77
+ south: :north,
78
+ east: :west,
79
+ west: :east
80
+ }[dir]
81
+ end
82
+
83
+ def move
84
+ raise RuntimeError if @parent
85
+
86
+ dir = [:north, :south, :east, :west].sample
87
+ destV = {
88
+ north: [0, 1],
89
+ south: [0, -1],
90
+ east: [1, 0],
91
+ west: [-1, 0]
92
+ }[dir]
93
+ @history << dir.to_s[0]
94
+ if (contact = @root.at(@x + destV[0], @y + destV[1]))
95
+ contact.attach(self, oppositeDirection(dir))
96
+ else
97
+ @x += destV[0]
98
+ @y += destV[1]
99
+ end
100
+ end
101
+
102
+ def to_s
103
+ format('%d,%d(%d,%d)%s', @x, @y, @ix, @iy, @history)
104
+ end
105
+ end
106
+ end
data/sig/dla.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Dla
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dla
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Arnaud Meuret
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-box
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-cursor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-reader
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-screen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-duration
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: filewatcher-cli
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '13.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '13.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.13'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.13'
125
+ - !ruby/object:Gem::Dependency
126
+ name: solargraph
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.5'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.5'
139
+ description: A tool to compute and export trees built using a DLA (Diffusion-limited
140
+ Aggregation) algorithm.
141
+ email:
142
+ - arnaud@meuret.net
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".ruby-version"
150
+ - ".standard.yml"
151
+ - CHANGELOG.md
152
+ - CODE_OF_CONDUCT.md
153
+ - LICENSE
154
+ - LICENSE.txt
155
+ - README
156
+ - Rakefile
157
+ - lib/dla.rb
158
+ - lib/dla/version.rb
159
+ - sig/dla.rbs
160
+ homepage: https://github.com/ameuret/dla
161
+ licenses:
162
+ - Unlicense
163
+ metadata:
164
+ allowed_push_host: https://rubygems.org
165
+ homepage_uri: https://github.com/ameuret/dla
166
+ source_code_uri: https://github.com/ameuret/dla
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: 3.3.0
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubygems_version: 3.5.23
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: A tool to create diffusion-limited aggregates.
186
+ test_files: []