isaac-rb 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: 5ec389ff7c8654a85bf5667e2dad02d31ee7f138b88f7d39d49f0d8b4d8dba12
4
+ data.tar.gz: b7ca0edd74fbaa24cea36fc252455842334189c5482707e86bffec4fb8861337
5
+ SHA512:
6
+ metadata.gz: ff7ba62d418c12e125f4030ef441807c4da7bf0bd33522dd95f32338638dccc1a79285f633680e3f45a4dffe178f3905e9f97bb2b2f06fb03729ca3065da62f3
7
+ data.tar.gz: e7a2d294eadd2c3ebc843312bcffd93c2fb8009442cd5a9957b1c7dee11bd289ee7a1075f3323aab0c17bf3bb5e1b6ce1334f92b0faf5f54bb411b761cf60613
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 3.0
8
+
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: false
17
+
18
+ Style/MethodParameterName:
19
+ Enabled: false
20
+
21
+ Metrics:
22
+ Enabled: false
23
+
24
+ Style/Documentation:
25
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-05-21
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 nia.personal.0@gmail.com. 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.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 kawaii-Code
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.md ADDED
@@ -0,0 +1,29 @@
1
+ # Isaac
2
+
3
+ TODO: Describe the gem here.
4
+
5
+ ## Installation
6
+
7
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with the gem name right after releasing it to RubyGems.org.
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ 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).
26
+
27
+ ## Code of Conduct
28
+
29
+ Everyone interacting in the Isaac project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kawaii-Code/isaac-rb/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
data/display_tester.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative "lib/isaac/canvas"
2
+ canvas = Canvas.new(5, 5)
3
+ 250.times do |y|
4
+ x = y % 25
5
+ canvas.clear
6
+ canvas.draw_pixel(x / 5, x % 5, "#")
7
+ canvas.display
8
+ sleep 0.1
9
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pixels"
4
+ require_relative "colors"
5
+
6
+ module Isaac
7
+ # Screen representation.
8
+ # Consists of a width x height matrix of pixels
9
+ class Canvas
10
+ attr_reader :pixels, :width, :height
11
+
12
+ def initialize(width, height)
13
+ @pixels = Pixels.new(width, height)
14
+ @width = width
15
+ @height = height
16
+ end
17
+
18
+ def clear
19
+ @pixels.clear
20
+ end
21
+
22
+ def fill(item)
23
+ @pixels.fill(item)
24
+ end
25
+
26
+ def draw_pixel(width, height, new_value)
27
+ @pixels[width, height] = new_value
28
+ end
29
+
30
+ def display
31
+ (system "cls") || (system "clear") # clears terminal
32
+ print "\e[H\e[?25l" # hides cursor (its annoying)
33
+ # puts "\x1b[48;2;#{@background_color[0]};#{@background_color[1]};#{@background_color[2]}m" #sets background color
34
+ @pixels.height.times do |i|
35
+ # "\x1b[38;2;#{@color[i, j][0]};#{@color[i, j][1]};#{@color[i, j][2]}m",
36
+ @pixels.width.times do |j|
37
+ print @pixels[i, j]
38
+ end
39
+ print "\n"
40
+ end
41
+ print "\e[H\e[?25h" # makes cursor visible
42
+ end
43
+
44
+ def draw_rect(x, y, width, height, symbol = "#", _color = Colors::WHITE)
45
+ return if x.negative? || y.negative? || x >= @width || y >= @height
46
+
47
+ (x..x + width - 1).each do |i|
48
+ break if i >= @width
49
+
50
+ @pixels[y, i] = symbol
51
+ # @colors[i][y] = color
52
+
53
+ next if y + height - 1 >= @height
54
+
55
+ @pixels[y + height - 1, i] = symbol
56
+ # @colors[i][y+height-1] = color
57
+ end
58
+
59
+ (y..y + height - 1).each do |j|
60
+ break if j >= @height
61
+
62
+ @pixels[j, x] = symbol
63
+ # @colors[x][j] = color
64
+
65
+ next if x + width - 1 >= @width
66
+
67
+ @pixels[j, x + width - 1] = symbol
68
+ # @colors[x+weight-1][j] = color
69
+ end
70
+ end
71
+
72
+ def fill_rect(x, y, width, height, symbol = "#", _color = Colors::WHITE)
73
+ return if x.negative? || y.negative? || x >= @width || y >= @height
74
+
75
+ (x..x + width - 1).each do |i|
76
+ (y..y + height - 1).each do |j|
77
+ next if i >= @width || j >= @height
78
+
79
+ @pixels[j, i] = symbol
80
+ # @colors[i][j] = color
81
+ end
82
+ end
83
+ end
84
+
85
+ def draw_text(x, y, string, _color = Colors::WHITE, transparent_spaces: false)
86
+ return if x.negative? || y.negative? || x >= @width || y >= @height
87
+
88
+ first = x
89
+
90
+ string.each_char do |char|
91
+ break if y >= @height
92
+
93
+ unless transparent_spaces && char == " "
94
+ @pixels[y, x] = char
95
+ # @colors[x][y] = color
96
+ end
97
+ x += 1
98
+
99
+ if x >= @width
100
+ x = first
101
+ y += 1
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,51 @@
1
+ module Isaac
2
+ class Color
3
+ def initialize(r, g, b)
4
+ @r = r
5
+ @g = g
6
+ @b = b
7
+ end
8
+ end
9
+
10
+ class Colors
11
+ BLACK = Color.new(0, 0, 0)
12
+ WHITE = Color.new(255, 255, 255)
13
+ RED = Color.new(255, 0, 0)
14
+ GREEN = Color.new(0, 255, 0)
15
+ BLUE = Color.new(0, 0, 255)
16
+ def initialize(width, height)
17
+ @matrix = Array.new(width) { Array.new(height) }
18
+ clear
19
+ end
20
+
21
+ def []=(width, height, new_value)
22
+ raise Isaac::Error, "Can only use strings for Color!" unless new_value.is_a?(Color)
23
+
24
+ @matrix[width][height] = new_value
25
+ end
26
+
27
+ def [](width, height)
28
+ @matrix[width][height]
29
+ end
30
+
31
+ def clear
32
+ @matrix.each { |arr| arr.fill(Colors::WHITE) }
33
+ end
34
+
35
+ def height
36
+ @matrix.length
37
+ end
38
+
39
+ def width
40
+ @matrix[0].length
41
+ end
42
+
43
+ def fill(item)
44
+ raise Isaac::Error, "Can only use strings for Color!" unless new_value.is_a?(Color)
45
+
46
+ @matrix.each { |arr| arr.fill(item) }
47
+ end
48
+ end
49
+
50
+ private_constant :Colors
51
+ end
@@ -0,0 +1,39 @@
1
+ module Isaac
2
+ class Pixels
3
+ def initialize(width, height)
4
+ @matrix = Array.new(width) { Array.new(height) }
5
+ clear
6
+ end
7
+
8
+ def []=(width, height, new_value)
9
+ raise Isaac::Error, "Can only use strings for pixels!" unless new_value.is_a?(String)
10
+ raise Isaac::Error, "Pixel must be a single character!" if new_value.length != 1
11
+
12
+ @matrix[width][height] = new_value.to_s
13
+ end
14
+
15
+ def [](width, height)
16
+ @matrix[width][height]
17
+ end
18
+
19
+ def clear
20
+ @matrix.each { |arr| arr.fill(" ") }
21
+ end
22
+
23
+ def height
24
+ @matrix.length
25
+ end
26
+
27
+ def width
28
+ @matrix[0].length
29
+ end
30
+
31
+ def fill(item)
32
+ raise Isaac::Error, "only single one can cope with it" if item.length != 1
33
+
34
+ @matrix.each { |arr| arr.fill(item.to_s) }
35
+ end
36
+ end
37
+
38
+ private_constant :Pixels
39
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Isaac
4
+ VERSION = "0.1.0"
5
+ end
data/lib/isaac.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "isaac/version"
4
+ require_relative "isaac/canvas"
5
+
6
+ module Isaac
7
+ class Error < StandardError; end
8
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isaac-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kawaii-Code
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - nia.personal.0@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - display_tester.rb
27
+ - lib/isaac.rb
28
+ - lib/isaac/canvas.rb
29
+ - lib/isaac/colors.rb
30
+ - lib/isaac/pixels.rb
31
+ - lib/isaac/version.rb
32
+ homepage: https://github.com/kawaii-Code/isaac-rb
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/kawaii-Code/isaac-rb
37
+ source_code_uri: https://github.com/kawaii-Code/isaac-rb
38
+ changelog_uri: https://github.com/kawaii-Code/isaac-rb/blob/main/CHANGELOG.md
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.25
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A simple library for doing console graphics in ruby.
58
+ test_files: []