langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
2
Task/Draw-a-cuboid/Openscad/draw-a-cuboid.scad
Normal file
2
Task/Draw-a-cuboid/Openscad/draw-a-cuboid.scad
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// This will produce a simple cuboid
|
||||
cube([2,3,4])
|
||||
15
Task/Draw-a-cuboid/POV-Ray/draw-a-cuboid.pov-ray
Normal file
15
Task/Draw-a-cuboid/POV-Ray/draw-a-cuboid.pov-ray
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
camera { perspective location <2.6,2.2,-4.2> look_at <0,-.5,0>
|
||||
aperture .05 blur_samples 100 variance 1/100000 focal_point <2,1,-2>}
|
||||
|
||||
light_source{< 60,20,-20> color rgb 2}
|
||||
|
||||
sky_sphere { pigment{ gradient z color_map{[0 rgb 0.3][.1 rgb <.7,.8,1>][1 rgb .2]} }}
|
||||
|
||||
box { <0,0,0> <3,2,4>
|
||||
texture {
|
||||
pigment{ agate }
|
||||
normal { checker }
|
||||
finish { reflection {0.20 metallic 0.2} }
|
||||
}
|
||||
translate <-1,-.5,-2>
|
||||
}
|
||||
69
Task/Draw-a-cuboid/Pascal/draw-a-cuboid.pascal
Normal file
69
Task/Draw-a-cuboid/Pascal/draw-a-cuboid.pascal
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
program Cuboid_Demo(output);
|
||||
|
||||
procedure DoCuboid(sWidth, sHeight, Depth: integer);
|
||||
const
|
||||
widthScale = 4;
|
||||
heightScale = 3;
|
||||
type
|
||||
TPage = array of array of char;
|
||||
var
|
||||
Cuboid: TPage;
|
||||
i, j: integer;
|
||||
Width, Height: integer;
|
||||
totalWidth, totalHeight: integer;
|
||||
begin
|
||||
Width := widthScale * sWidth;
|
||||
Height := heightScale * sHeight;
|
||||
totalWidth := 2 * Width + Depth + 3;
|
||||
totalHeight := Height + Depth + 3;
|
||||
setlength (Cuboid, totalHeight + 1);
|
||||
for i := 1 to totalHeight do
|
||||
setlength (Cuboid[i], totalwidth + 1);
|
||||
// points
|
||||
for i := low(Cuboid) to high(Cuboid) do
|
||||
for j := low(Cuboid[i]) to high(Cuboid[i]) do
|
||||
Cuboid[i,j] := ' ';
|
||||
Cuboid [1, 1] := '+';
|
||||
Cuboid [Height + 2, 1] := '+';
|
||||
Cuboid [1, 2 * Width + 2] := '+';
|
||||
Cuboid [Height + 2, 2 * Width + 2] := '+';
|
||||
Cuboid [totalHeight, Depth + 2] := '+';
|
||||
Cuboid [Depth + 2, totalWidth] := '+';
|
||||
Cuboid [totalHeight, totalWidth] := '+';
|
||||
// width lines
|
||||
for I := 1 to 2 * Width do
|
||||
begin
|
||||
Cuboid [1, I + 1] := '-';
|
||||
Cuboid [Height + 2, I + 1] := '-';
|
||||
Cuboid [totalHeight, Depth + I + 2] := '-';
|
||||
end;
|
||||
// height lines
|
||||
for I := 1 to Height do
|
||||
begin
|
||||
Cuboid [I + 1, 1] := '|';
|
||||
Cuboid [I + 1, 2 * Width + 2] := '|';
|
||||
Cuboid [Depth + I + 2, totalWidth] := '|';
|
||||
end;
|
||||
// depth lines
|
||||
for I := 1 to Depth do
|
||||
begin
|
||||
Cuboid [Height + 2 + I, 1 + I] := '/';
|
||||
Cuboid [1 + I, 2 * Width + 2 + I] := '/';
|
||||
Cuboid [Height + 2 + I, 2 * Width + 2 + I] := '/';
|
||||
end;
|
||||
for i := high(Cuboid) downto 1 do
|
||||
begin
|
||||
for j := 1 to high(Cuboid[i]) do
|
||||
write (Cuboid[i,j]);
|
||||
writeln;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
writeln('1, 1, 1:');
|
||||
DoCuboid(1, 1, 1);
|
||||
writeln('2, 3, 4:');
|
||||
DoCuboid(2, 3, 4);
|
||||
writeln('6, 2, 1:');
|
||||
DoCuboid(6, 2, 1);
|
||||
end.
|
||||
44
Task/Draw-a-cuboid/Perl-6/draw-a-cuboid.pl6
Normal file
44
Task/Draw-a-cuboid/Perl-6/draw-a-cuboid.pl6
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
sub braille-graphics (%a) {
|
||||
my ($ylo, $yhi, $xlo, $xhi);
|
||||
for %a.keys -> $y {
|
||||
$ylo min= +$y; $yhi max= +$y;
|
||||
for %a{$y}.keys -> $x {
|
||||
$xlo min= +$x; $xhi max= +$x;
|
||||
}
|
||||
}
|
||||
|
||||
for $ylo, $ylo + 4 ...^ * > $yhi -> \y {
|
||||
for $xlo, $xlo + 2 ...^ * > $xhi -> \x {
|
||||
my $cell = 0x2800;
|
||||
$cell += 1 if %a{y + 0}{x + 0};
|
||||
$cell += 2 if %a{y + 1}{x + 0};
|
||||
$cell += 4 if %a{y + 2}{x + 0};
|
||||
$cell += 8 if %a{y + 0}{x + 1};
|
||||
$cell += 16 if %a{y + 1}{x + 1};
|
||||
$cell += 32 if %a{y + 2}{x + 1};
|
||||
$cell += 64 if %a{y + 3}{x + 0};
|
||||
$cell += 128 if %a{y + 3}{x + 1};
|
||||
print chr($cell);
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub cuboid ( [$x, $y, $z] ) {
|
||||
my \x = $x * 4;
|
||||
my \y = $y * 4;
|
||||
my \z = $z * 2;
|
||||
my Bool %t;
|
||||
sub horz ($X, $Y) { %t{$Y }{$X + $_} = True for 0 .. x }
|
||||
sub vert ($X, $Y) { %t{$Y + $_}{$X } = True for 0 .. y }
|
||||
sub diag ($X, $Y) { %t{$Y - $_}{$X + $_} = True for 0 .. z }
|
||||
|
||||
horz(0, z); horz(z, 0); horz( 0, z+y);
|
||||
vert(0, z); vert(x, z); vert(z+x, 0);
|
||||
diag(0, z); diag(x, z); diag( x, z+y);
|
||||
|
||||
say "[$x, $y, $z]";
|
||||
braille-graphics %t;
|
||||
}
|
||||
|
||||
cuboid $_ for [2,3,4], [3,4,2], [4,2,3], [1,1,1], [8,1,1], [1,8,1], [1,1,8];
|
||||
66
Task/Draw-a-cuboid/PureBasic/draw-a-cuboid.purebasic
Normal file
66
Task/Draw-a-cuboid/PureBasic/draw-a-cuboid.purebasic
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
Procedure Draw_a_Cuboid(Window, X,Y,Z)
|
||||
w=WindowWidth(Window)
|
||||
h=WindowHeight(Window)
|
||||
diag.f=1.9
|
||||
If Not (w And h): ProcedureReturn: EndIf
|
||||
xscale.f = w/(x+z/diag)*0.98
|
||||
yscale.f = h/(y+z/diag)*0.98
|
||||
If xscale<yscale
|
||||
Scale.f = xscale
|
||||
Else
|
||||
Scale = yscale
|
||||
EndIf
|
||||
x*Scale: Y*Scale: Z*Scale
|
||||
CreateImage(0,w,h)
|
||||
If StartDrawing(ImageOutput(0))
|
||||
c= RGB(250, 40, 5)
|
||||
|
||||
;- Calculate the cones in the Cuboid
|
||||
xk = w/50 : yk = h/50
|
||||
x0 = Z/2 + xk : y0 = yk
|
||||
x1 = x0 + X : y1 = y0
|
||||
x2 = xk : y2 = y0 + Z/2
|
||||
x3 = x2 + X : y3 = y2
|
||||
x4 = x2 : y4 = y2 + Y
|
||||
x5 = x4 + X : y5 = y4
|
||||
x6 = x5 + Z/2 : y6 = y5 - Z/2
|
||||
|
||||
;- Draw it
|
||||
LineXY(x0,y0,x1,y1,c)
|
||||
LineXY(x0,y0,x2,y2,c)
|
||||
LineXY(x2,y2,x3,y3,c)
|
||||
LineXY(x1,y1,x3,y3,c)
|
||||
LineXY(x2,y2,x4,y4,c)
|
||||
LineXY(x4,y4,x5,y5,c)
|
||||
LineXY(x5,y5,x4,y4,c)
|
||||
LineXY(x5,y5,x6,y6,c)
|
||||
LineXY(x5,y5,x3,y3,c)
|
||||
LineXY(x6,y6,x1,y1,c)
|
||||
|
||||
;- Fill the areas
|
||||
FillArea(x,y,-1,RGB(255, 0, 0))
|
||||
FillArea(x,y-z/2,-1,RGB(0, 0, 255))
|
||||
FillArea(x+z/2,y,-1,RGB(0, 255, 0))
|
||||
StopDrawing()
|
||||
EndIf
|
||||
;- Update the graphic
|
||||
ImageGadget(0,0,0,w,h,ImageID(0))
|
||||
EndProcedure
|
||||
|
||||
#WFlags = #PB_Window_SystemMenu|#PB_Window_SizeGadget
|
||||
#title = "PureBasic Cuboid"
|
||||
MyWin = OpenWindow(#PB_Any, 0, 0, 200, 250, #title, #WFlags)
|
||||
|
||||
Repeat
|
||||
WEvent = WaitWindowEvent()
|
||||
If WEvent = #PB_Event_SizeWindow
|
||||
Draw_a_Cuboid(MyWin, 2, 3, 4)
|
||||
EndIf
|
||||
Until WEvent = #PB_Event_CloseWindow
|
||||
|
||||
;- Save the image?
|
||||
UsePNGImageEncoder()
|
||||
respons = MessageRequester("Question","Save the image?",#PB_MessageRequester_YesNo)
|
||||
If respons=#PB_MessageRequester_Yes
|
||||
SaveImage(0, SaveFileRequester("","","",0),#PB_ImagePlugin_PNG,9)
|
||||
EndIf
|
||||
19
Task/Draw-a-cuboid/Retro/draw-a-cuboid-1.retro
Normal file
19
Task/Draw-a-cuboid/Retro/draw-a-cuboid-1.retro
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
3 elements d h w
|
||||
|
||||
: spaces ( n- ) &space times ;
|
||||
: --- ( - ) '+ putc @w 2 * [ '- putc ] times '+ putc ;
|
||||
: ? ( n- ) @h <> [ '| ] [ '+ ] if ;
|
||||
: slice ( n- ) '/ putc @w 2 * spaces '/ putc @d swap - dup spaces ? putc cr ;
|
||||
: |...|/ ( - ) @h [ '| putc @w 2 * spaces '| putc 1- spaces '/ putc cr ] iterd ;
|
||||
: face ( - )
|
||||
--- @w 1+ spaces '/ putc cr
|
||||
|...|/
|
||||
--- cr ;
|
||||
|
||||
: cuboid ( whd- )
|
||||
!d !h !w cr
|
||||
@d 1+ spaces --- cr
|
||||
@d [ dup spaces slice ] iterd
|
||||
face ;
|
||||
|
||||
2 3 4 cuboid
|
||||
10
Task/Draw-a-cuboid/Retro/draw-a-cuboid-2.retro
Normal file
10
Task/Draw-a-cuboid/Retro/draw-a-cuboid-2.retro
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
+----+
|
||||
/ /|
|
||||
/ / |
|
||||
/ / |
|
||||
/ / +
|
||||
+----+ /
|
||||
| | /
|
||||
| | /
|
||||
| |/
|
||||
+----+
|
||||
30
Task/Draw-a-cuboid/XPL0/draw-a-cuboid.xpl0
Normal file
30
Task/Draw-a-cuboid/XPL0/draw-a-cuboid.xpl0
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
real X, Y, Z, Farthest; \arrays: 3D coordinates of vertices
|
||||
int I, J, K, SI, Segment;
|
||||
def Size=50.0, Sz=0.008, Sx=-0.013; \drawing size and tumbling speeds
|
||||
[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:= [0,1, 1,2, 2,3, 3,0, 4,5, 5,6, 6,7, 7,4, 0,4, 1,5, 2,6, 3,7];
|
||||
SetVid($101); \set 640x480 graphics with 256 colors
|
||||
repeat Farthest:= 0.0; \find the farthest vertex
|
||||
for I:= 0 to 8-1 do
|
||||
if Z(I) > Farthest then [Farthest:= Z(I); SI:= I];
|
||||
Clear; \erase screen
|
||||
for I:= 0 to 2*12-1 do \for all the vertices...
|
||||
[J:= Segment(I); I:= I+1; \get vertex number
|
||||
Move(fix(X(J)*Size)+640/2, fix(Y(J)*Size)+480/2);
|
||||
K:= Segment(I);
|
||||
Line(fix(X(K)*Size)+640/2, fix(Y(K)*Size)+480/2,
|
||||
if J=SI ! K=SI then $F009 \dashed blue\ else $C \red\);
|
||||
];
|
||||
Sound(0, 1, 1); \delay 1/18 second to prevent flicker
|
||||
for I:= 0 to 8-1 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;
|
||||
];
|
||||
until KeyHit; \run until a key is struck
|
||||
SetVid(3); \restore normal text mode (for DOS)
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue