Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 15, 2024
1 parent 01f16d4 commit 4a5f8b0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/tanks/gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source "https://rubygems.org"

gem "live"
gem "lively", path: "../../"

gem "activerecord", "~> 7.1"
gem "sqlite3", "~> 1.4"
gem "markly"

gem "base64"
38 changes: 38 additions & 0 deletions examples/tanks/png.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'zlib'

module PNG
def self.greyscale(width, height, data)
# PNG file signature
png_signature = "\x89PNG\r\n\x1a\n".b

# IHDR chunk
bit_depth = 8 # 8 bits per pixel
color_type = 0 # Greyscale
compression_method = 0
filter_method = 0
interlace_method = 0

ihdr_data = [width, height, bit_depth, color_type, compression_method, filter_method, interlace_method].pack('N2C5')
ihdr_crc = Zlib.crc32("IHDR" + ihdr_data)
ihdr_chunk = [ihdr_data.bytesize].pack('N') + "IHDR" + ihdr_data + [ihdr_crc].pack('N')

# IDAT chunk
raw_data = ""
height.times do |y|
row = data.get_string(y * width, width)
raw_data << "\x00" + row
end

# Compress data with no compression (just to fit PNG structure)
compressed_data = Zlib::Deflate.deflate(raw_data, Zlib::NO_COMPRESSION)
idat_crc = Zlib.crc32("IDAT" + compressed_data)
idat_chunk = [compressed_data.bytesize].pack('N') + "IDAT" + compressed_data + [idat_crc].pack('N')

# IEND chunk
iend_crc = Zlib.crc32("IEND")
iend_chunk = [0].pack('N') + "IEND" + [iend_crc].pack('N')

# Combine all parts into the final PNG
return png_signature + ihdr_chunk + idat_chunk + iend_chunk
end
end
28 changes: 28 additions & 0 deletions examples/tanks/public/_static/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Center the table in the page */

body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

/* Make a table display as a regular size 10px x 10px per cell */

table {
border-collapse: collapse;
border-spacing: 0;
}

td {
width: 2rem;
height: 2rem;
padding: 0;
margin: 0;
border: 1px solid black;

/* Center the character in the cell */
text-align: center;
vertical-align: middle;
}

0 comments on commit 4a5f8b0

Please sign in to comment.