Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,13 @@
constant dimx = 512, dimy = 512
constant fn = open("first.ppm","wb") -- b - binary mode
sequence color
printf(fn, "P6\n%d %d\n255\n", {dimx,dimy})
for y=0 to dimy-1 do
for x=0 to dimx-1 do
color = {remainder(x,256), -- red
remainder(y,256), -- green
remainder(x*y,256)} -- blue
puts(fn,color)
end for
end for
close(fn)

View file

@ -0,0 +1,16 @@
procedure write_ppm(sequence filename, sequence image)
integer fn,dimx,dimy
sequence colour_triple
fn = open(filename,"wb")
dimx = length(image)
dimy = length(image[1])
printf(fn, "P6\n%d %d\n255\n", {dimx,dimy})
for y = 1 to dimy do
for x = 1 to dimx do
colour_triple = sq_div(sq_and_bits(image[x][y], {#FF0000,#FF00,#FF}),
{#010000,#0100,#01})
puts(fn, colour_triple)
end for
end for
close(fn)
end procedure

View file

@ -0,0 +1,43 @@
subset Int < Number {|n| n.is_int }
subset Uint < Int {|n| n >= 0 }
subset Uint8 < Int {|n| n ~~ ^256 }
struct Pixel {
R < Uint8,
G < Uint8,
B < Uint8
}
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) {
subset WidthLimit < Uint { |n| n ~~ ^width }
subset HeightLimit < Uint { |n| n ~~ ^height }
func (w < WidthLimit, h < HeightLimit) {
data[w*height + h] = p
}(i, j)
}
method p6 {
"P6\n#{width} #{height}\n255\n" +
data.map {|p| [p.R, p.G, p.B].pack('C3') }.join
}
}
var b = Bitmap(width: 125, height: 125)
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