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 +4 -4
- data/.rubocop.yml +4 -1
- data/README.md +14 -7
- data/lib/isaac/canvas.rb +17 -16
- data/lib/isaac/colors.rb +6 -3
- data/lib/isaac/version.rb +1 -1
- metadata +2 -3
- data/display_tester.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 051cd899085a927f8cc8763d4aa302e368df8b0a13a34b23996227f2616eb844
|
4
|
+
data.tar.gz: 46a6c4974849761dc969c0951f22fa34c169b0346f41909b10f79f17b7b9e7da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
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
|
13
|
+
$ gem install isaac-rb
|
16
14
|
|
17
15
|
## Usage
|
18
|
-
|
19
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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 "\
|
42
|
+
print "\x1b[0m" # resets
|
42
43
|
end
|
43
44
|
|
44
|
-
def draw_rect(x, y, width, height, symbol = "#",
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
69
|
+
@colors[j, x + width - 1] = color
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
def fill_rect(x, y, width, height, symbol = "#",
|
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
|
-
|
81
|
+
@colors[j, i] = color
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
def draw_text(x, y, string,
|
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
|
-
|
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(
|
35
|
+
@matrix.each { |arr| arr.fill(Color::WHITE) }
|
33
36
|
end
|
34
37
|
|
35
38
|
def height
|
data/lib/isaac/version.rb
CHANGED
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.
|
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-
|
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
|