isaac-rb 0.1.0 → 0.1.1

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: 5ec389ff7c8654a85bf5667e2dad02d31ee7f138b88f7d39d49f0d8b4d8dba12
4
- data.tar.gz: b7ca0edd74fbaa24cea36fc252455842334189c5482707e86bffec4fb8861337
3
+ metadata.gz: 051cd899085a927f8cc8763d4aa302e368df8b0a13a34b23996227f2616eb844
4
+ data.tar.gz: 46a6c4974849761dc969c0951f22fa34c169b0346f41909b10f79f17b7b9e7da
5
5
  SHA512:
6
- metadata.gz: ff7ba62d418c12e125f4030ef441807c4da7bf0bd33522dd95f32338638dccc1a79285f633680e3f45a4dffe178f3905e9f97bb2b2f06fb03729ca3065da62f3
7
- data.tar.gz: e7a2d294eadd2c3ebc843312bcffd93c2fb8009442cd5a9957b1c7dee11bd289ee7a1075f3323aab0c17bf3bb5e1b6ce1334f92b0faf5f54bb411b761cf60613
6
+ metadata.gz: c822c5cf211a3970c4e3e752e6ee0b1fe547d33901d06c08b462317824b55dd8818ad0c19e40a7f97cd1106d695614168c9afaeb98f585c72d6a3b6e24c099b2
7
+ data.tar.gz: e6904b4da87717f64b1f927a07ac5a0536f03809d880a1583d1e687b52cefa1d387a95f008ae8af997d1c0f2e473567917fde7ea175e93c351d7a417408bbdab
data/.rubocop.yml CHANGED
@@ -15,7 +15,7 @@ Style/StringLiteralsInInterpolation:
15
15
  Style/FrozenStringLiteralComment:
16
16
  Enabled: false
17
17
 
18
- Style/MethodParameterName:
18
+ Naming/MethodParameterName:
19
19
  Enabled: false
20
20
 
21
21
  Metrics:
@@ -23,3 +23,6 @@ Metrics:
23
23
 
24
24
  Style/Documentation:
25
25
  Enabled: false
26
+
27
+ Gemspec/RequireMFA:
28
+ Enabled: false
data/README.md CHANGED
@@ -1,22 +1,29 @@
1
1
  # Isaac
2
2
 
3
- TODO: Describe the gem here.
3
+ Isacc-rb is FREE and OPEN SOURCE ruby gem for drawing in terminal.
4
4
 
5
5
  ## Installation
6
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
7
  Install the gem and add to the application's Gemfile by executing:
10
8
 
11
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
9
+ $ bundle add isaac-rb
12
10
 
13
11
  If bundler is not being used to manage dependencies, install the gem by executing:
14
12
 
15
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install isaac-rb
16
14
 
17
15
  ## Usage
18
-
19
- TODO: Write usage instructions here
16
+ ```ruby
17
+ require_relative "lib/isaac/canvas"
18
+ canvas = Isaac::Canvas.new(5, 5)
19
+ 250.times do |y|
20
+ x = y % 25
21
+ canvas.clear
22
+ canvas.draw_pixel(x / 5, x % 5, "#", Isaac::Color::RED)
23
+ canvas.display
24
+ sleep 0.1
25
+ end
26
+ ```
20
27
 
21
28
  ## Development
22
29
 
data/lib/isaac/canvas.rb CHANGED
@@ -7,10 +7,11 @@ module Isaac
7
7
  # Screen representation.
8
8
  # Consists of a width x height matrix of pixels
9
9
  class Canvas
10
- attr_reader :pixels, :width, :height
10
+ attr_reader :pixels, :colors, :width, :height
11
11
 
12
12
  def initialize(width, height)
13
13
  @pixels = Pixels.new(width, height)
14
+ @colors = Colors.new(width, height)
14
15
  @width = width
15
16
  @height = height
16
17
  end
@@ -23,53 +24,53 @@ module Isaac
23
24
  @pixels.fill(item)
24
25
  end
25
26
 
26
- def draw_pixel(width, height, new_value)
27
+ def draw_pixel(width, height, new_value, color = Color::WHITE)
27
28
  @pixels[width, height] = new_value
29
+ @colors[width, height] = color
28
30
  end
29
31
 
30
32
  def display
31
33
  (system "cls") || (system "clear") # clears terminal
32
34
  print "\e[H\e[?25l" # hides cursor (its annoying)
33
35
  # 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]
36
+ height.times do |i|
37
+ width.times do |j|
38
+ print "\x1b[38;2;#{@colors[i, j].r};#{@colors[i, j].g};#{@colors[i, j].b}m", @pixels[i, j]
38
39
  end
39
40
  print "\n"
40
41
  end
41
- print "\e[H\e[?25h" # makes cursor visible
42
+ print "\x1b[0m" # resets
42
43
  end
43
44
 
44
- def draw_rect(x, y, width, height, symbol = "#", _color = Colors::WHITE)
45
+ def draw_rect(x, y, width, height, symbol = "#", color = Color::WHITE)
45
46
  return if x.negative? || y.negative? || x >= @width || y >= @height
46
47
 
47
48
  (x..x + width - 1).each do |i|
48
49
  break if i >= @width
49
50
 
50
51
  @pixels[y, i] = symbol
51
- # @colors[i][y] = color
52
+ @colors[y, i] = color
52
53
 
53
54
  next if y + height - 1 >= @height
54
55
 
55
56
  @pixels[y + height - 1, i] = symbol
56
- # @colors[i][y+height-1] = color
57
+ @colors[y + height - 1, i] = color
57
58
  end
58
59
 
59
60
  (y..y + height - 1).each do |j|
60
61
  break if j >= @height
61
62
 
62
63
  @pixels[j, x] = symbol
63
- # @colors[x][j] = color
64
+ @colors[j, x] = color
64
65
 
65
66
  next if x + width - 1 >= @width
66
67
 
67
68
  @pixels[j, x + width - 1] = symbol
68
- # @colors[x+weight-1][j] = color
69
+ @colors[j, x + width - 1] = color
69
70
  end
70
71
  end
71
72
 
72
- def fill_rect(x, y, width, height, symbol = "#", _color = Colors::WHITE)
73
+ def fill_rect(x, y, width, height, symbol = "#", color = Color::WHITE)
73
74
  return if x.negative? || y.negative? || x >= @width || y >= @height
74
75
 
75
76
  (x..x + width - 1).each do |i|
@@ -77,12 +78,12 @@ module Isaac
77
78
  next if i >= @width || j >= @height
78
79
 
79
80
  @pixels[j, i] = symbol
80
- # @colors[i][j] = color
81
+ @colors[j, i] = color
81
82
  end
82
83
  end
83
84
  end
84
85
 
85
- def draw_text(x, y, string, _color = Colors::WHITE, transparent_spaces: false)
86
+ def draw_text(x, y, string, color = Color::WHITE, transparent_spaces: false)
86
87
  return if x.negative? || y.negative? || x >= @width || y >= @height
87
88
 
88
89
  first = x
@@ -92,7 +93,7 @@ module Isaac
92
93
 
93
94
  unless transparent_spaces && char == " "
94
95
  @pixels[y, x] = char
95
- # @colors[x][y] = color
96
+ @colors[y, x] = color
96
97
  end
97
98
  x += 1
98
99
 
data/lib/isaac/colors.rb CHANGED
@@ -1,18 +1,21 @@
1
1
  module Isaac
2
2
  class Color
3
+ attr_reader :r, :g, :b
4
+
3
5
  def initialize(r, g, b)
4
6
  @r = r
5
7
  @g = g
6
8
  @b = b
7
9
  end
8
- end
9
10
 
10
- class Colors
11
11
  BLACK = Color.new(0, 0, 0)
12
12
  WHITE = Color.new(255, 255, 255)
13
13
  RED = Color.new(255, 0, 0)
14
14
  GREEN = Color.new(0, 255, 0)
15
15
  BLUE = Color.new(0, 0, 255)
16
+ end
17
+
18
+ class Colors
16
19
  def initialize(width, height)
17
20
  @matrix = Array.new(width) { Array.new(height) }
18
21
  clear
@@ -29,7 +32,7 @@ module Isaac
29
32
  end
30
33
 
31
34
  def clear
32
- @matrix.each { |arr| arr.fill(Colors::WHITE) }
35
+ @matrix.each { |arr| arr.fill(Color::WHITE) }
33
36
  end
34
37
 
35
38
  def height
data/lib/isaac/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Isaac
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isaac-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kawaii-Code
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-06-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,7 +23,6 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
- - display_tester.rb
27
26
  - lib/isaac.rb
28
27
  - lib/isaac/canvas.rb
29
28
  - lib/isaac/colors.rb
data/display_tester.rb DELETED
@@ -1,9 +0,0 @@
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