Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,36 @@
using Color, Images, FixedPointNumbers
function hexify(pxl::RGB)
p = reinterpret(Uint8, [pxl.r, pxl.g, pxl.b])
join(map(x->hex(x, 2), p))
end
function showimagehex(a::Image)
s = " "
for i in 1:height(a)
for j in 1:width(a)
s *= " "*hexify(a["x", j, "y", i])
end
s *= "\n "
end
return s
end
w = 5
h = 7
cback = RGB(1, 0, 1)
cfore = RGB(0, 1, 0)
a = Array(RGB{Ufixed8}, h, w)
img = Image(a)
println("Uninitialized image:")
println(showimagehex(img))
fill!(img, cback)
println("Image filled with background color:")
println(showimagehex(img))
img["x", 2, "y", 3] = cfore
println("Image with a pixel set for foreground color:")
println(showimagehex(img))

View file

@ -0,0 +1,10 @@
type Color
r::Uint8
g::Uint8
b::Uint8
end
type Image
pic::Array{Color,2}
end
Image(w::Int, h::Int) = Image(Array(Color, w, h))

View file

@ -0,0 +1 @@
Base.fill!(a::Image, c::Color) = Base.fill!(a.pic, c)

View file

@ -0,0 +1,4 @@
function splat!(a::Image, x::Int, y::Int, c::Color)
a.pic[x, y] = c
nothing
end

View file

@ -0,0 +1,3 @@
function color(a::Image, x::Int, y::Int)
a.pic[x, y]
end

View file

@ -0,0 +1,21 @@
function showpixel(a::Image, x::Int, y::Int)
c = color(a, x, y)
hex(c.r, 2)*hex(c.g, 2)*hex(c.b, 2)
end
w = 5
h = 7
a = Image(w, h)
purple = Color(0xff, 0, 0xff)
green = Color(0, 0xff, 0)
fill!(a, purple)
splat!(a, 2, 3, green)
for i in 1:h
for j in 1:w
print(showpixel(a, j, i), " ")
end
println()
end

View file

@ -1,16 +1,14 @@
class Pixel { has Int ($.R, $.G, $.B) }
class Pixel { has UInt ($.R, $.G, $.B) }
class Bitmap {
has Int ($.width, $.height);
has Pixel @.data;
has UInt ($.width, $.height);
has Pixel @!data;
method fill(Pixel $p) {
for ^$!width X ^$!height -> $i, $j {
self.pixel($i, $j) = $p.clone;
}
@!data = $p.clone xx ($!width*$!height)
}
method pixel(
$i where ^self.width,
$j where ^self.height
$i where ^$!width,
$j where ^$!height
--> Pixel
) is rw { @!data[$i*$!height + $j] }