September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,24 +1,24 @@
|
|||
subset Int < Number {|n| n.is_int }
|
||||
subset Uint < Int {|n| n >= 0 }
|
||||
subset Uint8 < Int {|n| n ~~ ^256 }
|
||||
subset UInt < Int {|n| n >= 0 }
|
||||
subset UInt8 < Int {|n| n ~~ ^256 }
|
||||
|
||||
struct Pixel {
|
||||
R < Uint8,
|
||||
G < Uint8,
|
||||
B < Uint8
|
||||
R < UInt8,
|
||||
G < UInt8,
|
||||
B < UInt8
|
||||
}
|
||||
|
||||
class Bitmap(width < Uint, height < Uint) {
|
||||
class Bitmap(width < UInt, height < UInt) {
|
||||
has data = []
|
||||
|
||||
method fill(Pixel p) {
|
||||
data = (width*height -> of { Pixel(p.R, p.G, p.B) })
|
||||
}
|
||||
|
||||
method setpixel(i < Uint, j < Uint, Pixel p) {
|
||||
method setpixel(i < UInt, j < UInt, Pixel p) {
|
||||
|
||||
subset WidthLimit < Uint { |n| n ~~ ^width }
|
||||
subset HeightLimit < Uint { |n| n ~~ ^height }
|
||||
subset WidthLimit < UInt { |n| n ~~ ^width }
|
||||
subset HeightLimit < UInt { |n| n ~~ ^height }
|
||||
|
||||
func (w < WidthLimit, h < HeightLimit) {
|
||||
data[w*height + h] = p
|
||||
|
|
@ -26,8 +26,11 @@ class Bitmap(width < Uint, height < Uint) {
|
|||
}
|
||||
|
||||
method p6 {
|
||||
"P6\n#{width} #{height}\n255\n" +
|
||||
data.map {|p| [p.R, p.G, p.B].pack('C3') }.join
|
||||
<<-EOT + data.map {|p| [p.R, p.G, p.B].pack('C3') }.join
|
||||
P6
|
||||
#{width} #{height}
|
||||
255
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +40,4 @@ for i,j in (^b.height ~X ^b.width) {
|
|||
b.setpixel(i, j, Pixel(2*i, 2*j, 255 - 2*i))
|
||||
}
|
||||
|
||||
var file = File("palette.ppm")
|
||||
var fh = file.open('>:raw')
|
||||
fh.print(b.p6)
|
||||
fh.close
|
||||
%f"palette.ppm".write(b.p6, :raw)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue