Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
36
Task/Bitmap/Julia/bitmap-1.julia
Normal file
36
Task/Bitmap/Julia/bitmap-1.julia
Normal 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))
|
||||
10
Task/Bitmap/Julia/bitmap-2.julia
Normal file
10
Task/Bitmap/Julia/bitmap-2.julia
Normal 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))
|
||||
1
Task/Bitmap/Julia/bitmap-3.julia
Normal file
1
Task/Bitmap/Julia/bitmap-3.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
Base.fill!(a::Image, c::Color) = Base.fill!(a.pic, c)
|
||||
4
Task/Bitmap/Julia/bitmap-4.julia
Normal file
4
Task/Bitmap/Julia/bitmap-4.julia
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
function splat!(a::Image, x::Int, y::Int, c::Color)
|
||||
a.pic[x, y] = c
|
||||
nothing
|
||||
end
|
||||
3
Task/Bitmap/Julia/bitmap-5.julia
Normal file
3
Task/Bitmap/Julia/bitmap-5.julia
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function color(a::Image, x::Int, y::Int)
|
||||
a.pic[x, y]
|
||||
end
|
||||
21
Task/Bitmap/Julia/bitmap-6.julia
Normal file
21
Task/Bitmap/Julia/bitmap-6.julia
Normal 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
|
||||
|
|
@ -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] }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue