2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,8 +1,9 @@
|
|||
The task is to draw a [http://en.wikipedia.org/wiki/Cuboid cuboid]
|
||||
with relative dimensions of 2x3x4.
|
||||
;Task:
|
||||
Draw a [http://en.wikipedia.org/wiki/Cuboid cuboid] with relative dimensions of <big> 2x3x4. </big> The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities. To fulfill the criteria of being a cuboid, three faces must be visible.
|
||||
|
||||
The cuboid can be represented graphically, or in ascii art,
|
||||
depending on the language capabilities.
|
||||
|
||||
To fulfil the criteria of being a cuboid, three faces must be visible. <br>
|
||||
Either static or rotational projection is acceptable for this task.
|
||||
<br><br>
|
||||
|
||||
;Related tasks
|
||||
* [[Draw_a_rotating_cube|Draw a rotating cube]]
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -15,19 +15,19 @@ defmodule Cuboid do
|
|||
area = Enum.reduce(0..nz-1, area, fn i,acc -> draw_line(acc, y, x, @z*i, :/) end)
|
||||
area = Enum.reduce(0..nx, area, fn i,acc -> draw_line(acc, y, @x*i, z, :/) end)
|
||||
Enum.each(y+z..0, fn j ->
|
||||
IO.puts Enum.map(0..x+y, fn i -> Dict.get(area, {i,j}, " ") end) |> Enum.join
|
||||
IO.puts Enum.map_join(0..x+y, fn i -> Map.get(area, {i,j}, " ") end)
|
||||
end)
|
||||
end
|
||||
|
||||
defp draw_line(area, n, sx, sy, c) do
|
||||
{dx, dy} = Dict.get(@dir, c)
|
||||
{dx, dy} = Map.get(@dir, c)
|
||||
draw_line(area, n, sx, sy, c, dx, dy)
|
||||
end
|
||||
|
||||
defp draw_line(area, n, _, _, _, _, _) when n<0, do: area
|
||||
defp draw_line(area, n, i, j, c, dx, dy) do
|
||||
area2 = Dict.update(area, {i,j}, c, fn _ -> :+ end)
|
||||
draw_line(area2, n-1, i+dx, j+dy, c, dx, dy)
|
||||
Map.update(area, {i,j}, c, fn _ -> :+ end)
|
||||
|> draw_line(n-1, i+dx, j+dy, c, dx, dy)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
// This will produce a simple cuboid
|
||||
cube([2,3,4])
|
||||
cube([2,3,4]);
|
||||
|
|
|
|||
25
Task/Draw-a-cuboid/PARI-GP/draw-a-cuboid.pari
Normal file
25
Task/Draw-a-cuboid/PARI-GP/draw-a-cuboid.pari
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
\\ Simple "cuboid". Try different parameters of this Cuboid() function.
|
||||
\\ 4/11/16 aev
|
||||
Cuboid(a,b,c,u=10)={
|
||||
my(dx,dy,ttl="Cuboid AxBxC: ",size=200,da=a*u,db=b*u,dc=c*u);
|
||||
print(" *** ",ttl,a,"x",b,"x",c,"; u=",u);
|
||||
plotinit(0);
|
||||
plotscale(0, 0,size, 0,size);
|
||||
plotcolor(0,7); \\grey
|
||||
plotmove(0, 0,0);
|
||||
plotrline(0,dc,da\2); plotrline(0,db,0); plotrline(0,-db,0);
|
||||
plotrline(0,0,da);
|
||||
plotcolor(0,2); \\black
|
||||
plotmove(0, db,da);
|
||||
plotrline(0,0,-da); plotrline(0,-db,0);
|
||||
plotrline(0,0,da); plotrline(0,db,0);
|
||||
plotrline(0,dc,da\2); plotrline(0,-db,0); plotrline(0,-dc,-da\2);
|
||||
plotmove(0, db,0);
|
||||
plotrline(0,dc,da\2); plotrline(0,0,da);
|
||||
plotdraw([0,size,size]);
|
||||
}
|
||||
|
||||
{\\ Executing:
|
||||
Cuboid(2,3,4,20); \\Cuboid1.png
|
||||
Cuboid(5,3,1,20); \\Cuboid2.png
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ sub cuboid ( [$x, $y, $z] ) {
|
|||
my \x = $x * 4;
|
||||
my \y = $y * 4;
|
||||
my \z = $z * 2;
|
||||
my Bool %t;
|
||||
my %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 }
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/*REXX program displays a cuboid (dimensions must be positive integers). */
|
||||
parse arg x y z indent . /*x,y,z: dimensions and indentation. */
|
||||
x=p(x 2); y=p(y 3); z=p(z 4) /*use the defaults if not specified. */
|
||||
in=p(indent 0)
|
||||
call show y+2 , , "+-"
|
||||
do j=1 for y; call show y-j+2, j-1, "/ |" ; end
|
||||
call show , y , "+-|"
|
||||
do z-1; call show , y , "| |" ; end
|
||||
call show , y , "| +"
|
||||
do j=1 for y; call show , y-j, "| /" ; end
|
||||
call show , , "+-"
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
p: return word(arg(1), 1) /*pick the first number or word in list*/
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
show: parse arg #,$,a 2 b 3 c 4 /*get the arguments (or parts thereof).*/
|
||||
say left('',in)right(a,p(# 1))copies(b,4*x)a || right(c,p($ 0)+1); return
|
||||
/*REXX program displays a cuboid (dimensions, if specified, must be positive integers).*/
|
||||
parse arg x y z indent . /*x, y, z: dimensions and indentation.*/
|
||||
x=p(x 2); y=p(y 3); z=p(z 4); in=p(indent 0) /*use the defaults if not specified. */
|
||||
pad=left('', in) /*indentation must be non-negative. */
|
||||
call show y+2 , , "+-"
|
||||
do j=1 for y; call show y-j+2, j-1, "/ |" ; end /*j*/
|
||||
call show , y , "+-|"
|
||||
do z-1; call show , y , "| |" ; end /*z-1*/
|
||||
call show , y , "| +"
|
||||
do j=1 for y; call show , y-j, "| /" ; end /*j*/
|
||||
call show , , "+-"
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
p: return word( arg(1), 1) /*pick the first number or word in list*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: parse arg #,$,a 2 b 3 c 4 /*get the arguments (or parts thereof).*/
|
||||
say pad || right(a, p(# 1) )copies(b, 4*x)a || right(c, p($ 0) + 1); return
|
||||
|
|
|
|||
6
Task/Draw-a-cuboid/ZX-Spectrum-Basic/draw-a-cuboid.zx
Normal file
6
Task/Draw-a-cuboid/ZX-Spectrum-Basic/draw-a-cuboid.zx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
10 LET width=50: LET height=width*1.5: LET depth=width*2
|
||||
20 LET x=80: LET y=10
|
||||
30 PLOT x,y
|
||||
40 DRAW 0,height: DRAW width,0: DRAW 0,-height: DRAW -width,0: REM Front
|
||||
50 PLOT x,y+height: DRAW depth/2,height: DRAW width,0: DRAW 0,-height: DRAW -width,-height
|
||||
60 PLOT x+width,y+height: DRAW depth/2,height
|
||||
Loading…
Add table
Add a link
Reference in a new issue