制作一个程序来建造一扇门。ASCII、HTML或其他
把门修好。开闭
可以通过输入或交互打开!
如果你有标准建议,把它们放在评论中。
<?php
$idiots_in_room=true;
if($idiots_in_room)
{
$count=20;
$count2=7;
for($i=0;$i<$count;$i++)
{
if($i==0)
{
echo str_repeat("-",10);
if($i==0){echo ".";}
echo "\n";
}
elseif($i==9)
{
echo str_repeat("-",10);
echo str_repeat("Â ",7)."o"."|";
echo "\n";
}
elseif($i<=9)
{
echo str_repeat("-",1).str_repeat("Â ",8).str_repeat("-",1);
echo ($i<5) ? str_repeat("Â ",$i*2)."\\" : str_repeat("Â ",8)."|";
echo "\n";
}
elseif($i<=14)
{
if($i>9){echo str_repeat("Â ",$i)."\\";}
echo str_repeat("Â ",$count2--)."|";
echo "\n";
}
}
}----------.
- - \
- - \
- - \
- - \
- - |
- - |
- - |
- - |
---------- o|
\ |
\ |
\ |
\ |
\ |发布于 2012-07-15 00:11:15
ASCII?检查一下。HTML?检查一下。是门吗?检查一下。可开的门?检查一下。互动?检查一下。花哨?双门有正确的位置铰链,我希望这很重要。动画片?检查一下。100字以下?哈哈。不使用用于绘图的设施?检查一下。
现场演示。 (注:在我用火狐进行的测试中,不止一次地点击门不起作用-由于某种原因,事件处理程序不再启动,我对为什么感到困惑;指出我做错了什么将是值得欢迎的。不过,为了获得良好的JS性能,您可能希望在Chrome中运行这个程序。)
<title>Door</title>
<pre onmouseup="turn();" style="display: table; margin: auto; font-family: 'Monaco', monospace; font-size: 0.6em; line-height: 0.7em;">
</pre>
<p>Click doors to open or close.</p>
<script>
// Appearance of hit surface - global used to avoid allocating a record to return
var mat;
// Scene construction tools
function box(size,ms) {
return function (x, y, z) {
var vdist0 = Math.abs(x) - size[0];
var vdist1 = Math.abs(y) - size[1];
var vdist2 = Math.abs(z) - size[2];
mat = vdist0 > vdist1 && vdist0 > vdist2 ? ms[0] :
vdist1 > vdist0 && vdist1 > vdist2 ? ms[1] :
ms[2];
return Math.max(vdist0, vdist1, vdist2);
};
}
function translate(vec, obj) {
var dx = vec[0];
var dy = vec[1];
var dz = vec[2];
return function (x, y, z) { return obj(x - dx, y - dy, z - dz); };
}
function mirror(obj) {
return function (x, y, z) { return obj(-x, y, z); };
}
function spin(obj) {
return function (x, y, z) {
var a = Date.now() / 1000;
var s = Math.sin(a);
var c = Math.cos(a);
return obj(
x * c + z * s,
y,
x * -s + z * c
);
};
}
function doorturn(obj) {
return function (x, y, z) {
var a = pos;
var s = Math.sin(a);
var c = Math.cos(a);
return obj(
x * c + z * s,
y,
x * -s + z * c
);
};
}
function rotx(a, obj) {
return function (x, y, z) {
var s = Math.sin(a);
var c = Math.cos(a);
return obj(
x,
y * c + z * s,
y * -s + z * c
);
};
}
function roty(a, obj) {
return function (x, y, z) {
var s = Math.sin(a);
var c = Math.cos(a);
return obj(
x * c + z * s,
y,
x * -s + z * c
);
};
}
function union(as, bs) {
return function (x, y, z) {
var a = as(x, y, z); var am = mat;
var b = bs(x, y, z);
if (a < b) {
mat = am;
return a;
} else {
return b;
}
};
}
// Display parameters
var vw = 80, vh = 80;
var timestep = 1/30;
// Scene
var wallhwidth = 30;
var wallhheight = 35;
var wallmat = [";", "\u2014", ":"];
var dhwidth = 10;
var dhheight = 20;
var hthick = 2;
var door = translate([-dhwidth*2, 0, 0], doorturn(translate([hthick, 0, dhwidth], box([hthick, dhheight, dhwidth], [".", "\u2014", "|"]))));
var doors = union(door, mirror(door));
var wall = union(
union(
translate([dhwidth*2+wallhwidth, 0, -hthick], box([wallhwidth, wallhheight, hthick], wallmat)),
translate([-dhwidth*2-wallhwidth, 0, -hthick], box([wallhwidth, wallhheight, hthick], wallmat))),
translate([0, wallhheight-(wallhheight-dhheight)/2, -hthick], box([dhwidth*2, (wallhheight-dhheight)/2, hthick], wallmat)));
var floor = translate([0, -dhheight - 1.1, 0], box([100, 1, 100], ["/","/","/"]));
var sill = translate([0, -dhheight - 1, -hthick], box([dhwidth*2, 1, hthick], ["\\","%","\\"]));
var sbox = translate([0, 0, -12], spin(box([8, 8, 8], ["x", "y", "z"])))
var scene = union(sbox, union(union(wall, doors), union(floor, sill)));
var view = translate([vw/2, vh/2, -100], rotx(0.2, roty(-0.6, scene)));
// Animation state
var pos = -Math.PI/2;
var dpos = 0;
var interval;
// Main loop function
function r() {
// Update state
pos += dpos * timestep;
if (Math.abs(pos) >= Math.PI/2) {
dpos = 0;
pos = Math.PI/2 * pos / Math.abs(pos);
if (pos < 0) { // no animation needed
clearInterval(interval); interval = undefined;
}
}
// Render scene
var t = [];
for (var y = vh - 1; y >= 0; y--) {
for (var x = 0; x < vw; x++) {
var z = 0, distance;
while ((distance = view(x,y,z)) > 0.12) {
z -= distance;
if (!isFinite(z) || z < -1000) {
mat = " ";
break;
}
}
t.push(mat);
}
t.push("\n");
}
document.getElementsByTagName("pre")[0].textContent = t.join("");
}
// Click handler
function turn() {
if (dpos !== 0) {
dpos *= -1;
} else {
dpos = (pos < 0 ? 1 : -1) * 2.3;
}
if (!interval) {
interval = setInterval(r, timestep*1000);
}
}
// Render initial state
r();
</script>关门的时候,门看起来是这样的:

发布于 2012-07-17 21:21:58
花哨,互动,动画门是55分,我想。
是的,这个门和其他门一样打开,但是如果滑动门算得上是花哨的话,为什么旋转的门就不开呢?如果一个旋转的门不是花哨的,那么,滑动门是没有问题的,:)
http://result.dabblet.com/gist/3132160/ac475112dbba493d2dd7d98493d4f4ceaa209a7c提供了一个演示。点击门把手打开和关闭。不涉及JavaScript;这只是CSS3的魔力。
#wall {
background-color: #eee;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
transform: rotateX(-10deg);
transform-origin: 0 100%;
transform-style: preserve-3d;
}
#door-container {
background-color: black;
height: 100%;
margin: 0 auto;
width: 300px;
}
#door {
background-color: brown;
height: 100%;
margin: auto;
position: relative;
transform-origin: 0 0;
transition: transform 0.5s ease;
width: 300px;
}
#door .knob {
background-color: gold;
border-radius: 10px;
height: 20px;
margin-top: -10px;
position: absolute;
right: 10px;
top: 50%;
width: 20px;
}
#open:target + #wall #door {
transform: rotateY(-145deg);
}
#open:target + #wall #open-link {
display: none;
}
#close-link {
display: none;
}
#open:target + #wall #close-link {
display: inline;
}<span id="open"></span>
<div id="wall">
<div id="door-container">
<div id="door">
<a href="#open" id="open-link" class="knob"></a>
<a href="#closed" id="close-link" class="knob"></a>
</div>
</div>
</div>发布于 2012-07-14 00:35:32
Manipulate[a = {0, 0, 0}; b = {0, 0, h}; p = Polygon; c = Cuboid; t = Rotate;Graphics3D[{c@{{-w - 1, 0, 0}, {-w, 1, h}}, c@{{w + 1, 0, 0}, {w, 1, h}},t[p@{a, b, {-w, 0, h}, {-w, 0, 0}}, r, {0, 0, 1}, {- 2 w/3, -w/3, 0}], t[p@{a, b, {w, 0, h}, {w, 0, 0}}, -r, {0, 0, 1}, { 2 w/3, -w/3, 0}]}],{{r, 0}, 0, 3/2}, {{w, 2}, 1, 3}, {{h, 4}, 3, 5}]
双门
r)h和w)设置它们的高度和宽度。代码是基于Sándor Kabal的程序。
https://codegolf.stackexchange.com/questions/6613
复制相似问题