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,19 @@
import strutils
proc cline(n, x, y: int, cde: string) =
echo cde[0..0].align n+1,
repeatChar(9*x-1, cde[1]),
cde[0], cde[2..2].align y+1
proc cuboid(x, y, z: int) =
cline y+1, x, 0, "+-"
for i in 1..y: cline y-i+1, x, i-1, "/ |"
cline 0, x, y, "+-|"
for i in 0..4*z-y-3: cline 0, x, y, "| |"
cline 0, x, y, "| +"
for i in countdown(y-1, 0): cline 0, x, i, "| /"
cline 0, x, 0, "+-\n"
cuboid 2, 3, 4
cuboid 1, 1, 1
cuboid 6, 2, 1

View file

@ -0,0 +1,76 @@
include ..\arwen\arwen.ew
include ..\arwen\axtra.ew
constant main = create(Window, "Draw Cuboid", 0, 0, 20, 20, 625, 690, 0),
mainDC = getPrivateDC(main),
backDC = c_func(xCreateCompatibleDC, {NULL}), -- the background
viewDC = c_func(xCreateCompatibleDC, {NULL}), -- with animation
grey = #909090
constant MainTimer = createTimer()
integer dw = 0, dh = 0 -- client area width and height
atom bmBack, bmView
integer bmX = 0, bmY = 0 -- actual size of the bitmaps
-- arrays: 3D coordinates of vertices
sequence x = {-2.0, +2.0, +2.0, -2.0, -2.0, +2.0, +2.0, -2.0},
y = {-1.5, -1.5, +1.5, +1.5, -1.5, -1.5, +1.5, +1.5},
z = {-1.0, -1.0, -1.0, -1.0, +1.0, +1.0, +1.0, +1.0},
Segment = {1,2, 2,3, 3,4, 4,1, 5,6, 6,7, 7,8, 8,5, 1,5, 2,6, 3,7, 4,8}
constant Size=50.0, Sz=0.008, Sx=-0.013 -- drawing size and tumbling speeds
function mainHandler(integer id, integer msg, atom wParam, object lParam)
atom farthest
integer v1, v2, farv, c
if msg=WM_SIZE then
{{},{},dw,dh} = getClientRect(main)
if dw>bmX or dh>bmY then
-- we need bigger bitmaps
bmBack = c_func(xCreateCompatibleBitmap, {mainDC, dw, dh})
{} = deleteObject(selectObject(backDC,bmBack))
-- clear the background
setPenColor(grey)
setPenBkColor(grey)
drawRectangleh(backDC, True, 0, 0, dw, dh)
bmView = c_func(xCreateCompatibleBitmap, {mainDC, dw, dh})
{} = deleteObject(selectObject(viewDC,bmView))
{bmX,bmY} = {dw,dh}
end if
elsif msg=WM_PAINT then
-- start with a fresh copy of the background
void = c_func(xBitBlt,{viewDC,0,0,dw,dh,backDC,0,0,SRCCOPY})
farthest = 0.0 -- find the farthest vertex
for i=1 to 8 do
if z[i]>farthest then farthest = z[i] farv = i end if
end for
for v=1 to 2*12 by 2 do -- for all the vertices...
v1 = Segment[v] -- get vertex number
v2 = Segment[v+1]
c = Red; setPenStyle(Solid)
if v1=farv or v2=farv then c=Blue; setPenStyle(Dash) end if
drawLinesh(viewDC,{c,{x[v1]*Size+dw/2, y[v1]*Size+dh/2,
x[v2]*Size+dw/2, y[v2]*Size+dh/2}})
end for
void = c_func(xBitBlt,{mainDC,0,0,dw,dh,viewDC,0,0,SRCCOPY})
elsif msg=WM_TIMER then
for i=1 to 8 do
x[i] = x[i]+y[i]*Sz -- rotate vertices in X-Y plane
y[i] = y[i]-x[i]*Sz
y[i] = y[i]+z[i]*Sx -- rotate vertices in Y-Z plane
z[i] = z[i]-y[i]*Sx
end for
repaintWindow(main)
elsif msg=WM_SHOWWINDOW then
startTimer(MainTimer,main,33)
elsif msg=WM_CHAR
and wParam=VK_ESCAPE then
closeWindow(main)
if id or object(lParam) then end if -- suppress warnings
end if
return 0
end function
setHandler({main},routine_id("mainHandler"))
WinMain(main, SW_NORMAL)

View file

@ -0,0 +1,31 @@
var DIR = Hash.new("-" => [1,0], "|" => [0,1], "/" => [1,1]);
func cuboid(nx, ny, nz) {
say("cuboid %d %d %d:" % [nx, ny, nz]);
var(x, y, z) = (8*nx, 2*ny, 4*nz);
var area = [];
var line = func(n, sx, sy, c) {
var(dx, dy) = DIR{c}...;
0..n -> each {|i|
var (xi, yi) = (sx + i*dx, sy + i*dy);
area[yi] \\= [" "]*(x+y+1);
area[yi][xi] = (area[yi][xi] == " " ? c : '+');
};
};
0 .. nz-1 -> each {|i| line.call(x, 0, 4*i, "-")};
0 .. ny -> each {|i| line.call(x, 2*i, z + 2*i, "-")};
0 .. nx-1 -> each {|i| line.call(z, 8*i, 0, "|")};
0 .. ny -> each {|i| line.call(z, x + 2*i, 2*i, "|")};
0 .. nz-1 -> each {|i| line.call(y, x, 4*i, "/")};
0 .. nx -> each {|i| line.call(y, 8*i, z, "/")};
area.reverse.each { |line|
say line.join('');
};
}
cuboid(2, 3, 4);
cuboid(1, 1, 1);
cuboid(6, 2, 1);
cuboid(2, 4, 1);

View file

@ -0,0 +1,30 @@
func cuboid (x=1,y=1,z=1,s=' ',c='+',h='-',v='|',d='/') {
say("cuboid %d %d %d:" % (x, y, z));
' ' * z+1 + c + h*x + c -> say;
{ |i|
' ' * (z - i + 1) + d + s*x + d +
(s * (i - (i > y ? i-y : 1))) +
(i - 1 == y ? c : (i > y ? d : v)) -> say
} * z;
c + h*x + c + (s * (z < y ? z : y) +
(z < y ? v : (z == y ? c : d))) -> say;
{ |i|
v + s*x + v + (z > y
? (i >= z ? (s*x + c) : (s * y-i + d))
: (y - i > z
? (s * z + v)
: (s * y-i + (y-i == z ? c : d))
)
) -> say;
} * y;
c + h*x + c -> say;
};
cuboid(2, 3, 4);
cuboid(1, 1, 1);
cuboid(6, 2, 1);
cuboid(2, 4, 1);