首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >门门,快到门店去!

门门,快到门店去!
EN

Code Golf用户
提问于 2012-07-13 15:15:21
回答 5查看 821关注 0票数 10

挑战是双重的:

制作一个程序来建造一扇门。ASCII、HTML或其他

把门修好。开闭

可以通过输入或交互打开!

  • 非功能性门+5分。
  • 只是一扇可开的门+10分。
  • 互动门+15点。
  • 高级门+20分。这意味着旋转、双倍等。
  • 动画+20分。
  • <100个字符+50分。
  • -使用专门为绘图或动画设计的程序的100分。

如果你有标准建议,把它们放在评论中。

非功能性开放式门示例:

代码语言:javascript
复制
<?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";
}

}
}

示例输出:

代码语言:javascript
复制
----------.
-        -  \
-        -    \
-        -      \
-        -        \
-        -        |
-        -        |
-        -        |
-        -        |
----------       o|
          \       |
           \      |
            \     |
             \    |
              \   |
EN

回答 5

Code Golf用户

发布于 2012-07-15 00:11:15

JavaScript,4380字符,65(?)点

ASCII?检查一下。HTML?检查一下。是门吗?检查一下。可开的门?检查一下。互动?检查一下。花哨?双门有正确的位置铰链,我希望这很重要。动画片?检查一下。100字以下?哈哈。不使用用于绘图的设施?检查一下。

现场演示。 (注:在我用火狐进行的测试中,不止一次地点击门不起作用-由于某种原因,事件处理程序不再启动,我对为什么感到困惑;指出我做错了什么将是值得欢迎的。不过,为了获得良好的JS性能,您可能希望在Chrome中运行这个程序。)

代码语言:javascript
复制
<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>

关门的时候,门看起来是这样的:

票数 21
EN

Code Golf用户

发布于 2012-07-17 21:21:58

HTML & CSS3,55点

花哨,互动,动画门是55分,我想。

是的,这个门和其他门一样打开,但是如果滑动门算得上是花哨的话,为什么旋转的门就不开呢?如果一个旋转的门不是花哨的,那么,滑动门是没有问题的,:)

http://result.dabblet.com/gist/3132160/ac475112dbba493d2dd7d98493d4f4ceaa209a7c提供了一个演示。点击门把手打开和关闭。不涉及JavaScript;这只是CSS3的魔力。

代码语言:javascript
复制
#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;
}
代码语言:javascript
复制
<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>
票数 9
EN

Code Golf用户

发布于 2012-07-14 00:35:32

Mathematica 271 chars

代码语言:javascript
复制
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}]

双门

  • 从零到90度旋转打开(使用滑块r)
  • 可以由滑块(hw)设置它们的高度和宽度。
  • 在三维照明环境中
  • 可以交互旋转,从不同角度观看。

代码是基于Sándor Kabal的程序

票数 6
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/6613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档