【问题标题】:Dynamic alteration of graphic/canvas/divs图形/画布/div的动态变化
【发布时间】:2015-05-16 18:48:29
【问题描述】:

我需要能够拥有某种画布,我可以在其中绘制 A 并将其动态地操纵到 B。(对于 A 和 B,请参见示例绘图)

  • 所有矩形的尺寸都必须能适应
  • 红色矩形的倾斜
  • 和整个集合的旋转

我不确定哪条路是正确的。我尝试了简单的 HTML 和 CSS3 转换,如果没有大量的 JS 计算,我将无法真正到达任何地方,因为我必须伪造 3D 中的红色矩形以获得预期的印象 - 然后需要 A 和 B 的“伪造”定位以连接它们的方式他们应该这样做。

还有其他想法吗?用 imagemagick 和 PHP 绘制它? SVG 操作?我对这种方法比较开放。

不胜感激。

示例图:http://www.steffen-behn.de/m3/reifen.jpg

【问题讨论】:

    标签: php css svg graphics imagemagick


    【解决方案1】:

    我认为转换可以为您提供所需的一切

    div {
        transition: all 1s;
    }
    .base {
        height: 200px;
        width: 100px;
      border: solid 1px black;
      left: 50px;
      top: 100px;
      position: absolute;
       perspective: 100px;
    }
    
    .side {
      width: 100%;
      height: 50px;
      border: solid 1px red;
      position: absolute;
      }
    
    #side1 {
      bottom: 100%;
      transform-origin: bottom center;
    }
    
    #side2 {
      top: 100%;
      transform-origin: top center;
    }
    
    .base:hover {
      transform: scale(1.2) rotate(20deg);
      }
    
    .base:hover #side1 {
      transform: scaleY(1.1) rotateX(-20deg);
    ;
    }
    .base:hover #side2 {
      transform: scaleY(1.1) rotateX(20deg);
    }
    <div class="base">
      <div class="side" id="side1"></div>
      <div class="side" id="side2"></div>
    </div>

    悬停查看变换

    编辑

    另一个想法。不确定它是否适合您,但让我们试一试。不能制作红色区域的边框 - 只有纯色。

    // customize here
    .base {
        width: 80px;
        height: 200px;
    }
    .side {
        height: 42px;
    }
    .side:after, .side:before {
        width: 10px;
    }
    // end of customization part
    
    
    div {
        box-sizing: content-box;
    }
    .base {
        position: absolute;
        left: 40px;
        top: 100px;
        width: 80px;
        height: 200px;
        border: solid black 1px;
    }
    
    
    
    .side {
        width: 100%;
        border: solid 1px red;
        position: absolute;
        left: -1px;
        background-color: red;
    }
    
    #side1 {
        top: 100%;
    }
    
    #side2 {
        bottom: 100%;
    }
    
    .side:after, .side:before {
        content: "";
        position: absolute;
        height: 100%;
    }
    
    .side:before {
        right: 100%;
    }
    .side:after {
        left: 100%;
    }
    
    #side1:before {
        background: linear-gradient(to top left, red 50%, transparent 50%);
        border-bottom: solid red 1px;
    }
    
    #side1:after {
        background: linear-gradient(to top right, red 50%, transparent 50%);
        border-bottom: solid red 1px;
    }
    
    #side2:before {
        background: linear-gradient(to bottom left, red 50%, transparent 50%);
        border-top: solid red 1px;
        top: -1px;
    }
    
    #side2:after {
        background: linear-gradient(to bottom right, red 50%, transparent 50%);
        border-top: solid red 1px;
        top: -1px;
    }
    <div class="base">
    <div class="side" id="side1"></div>
    <div class="side" id="side2"></div>
    </div>

    【讨论】:

    • 谢谢!我对这个解决方案的问题是,我不能简单地参数化它。如果不以某种方式计算新位置和“旋转”,我无法设置矩形的宽度、高度和倾斜。我希望能够设置红色矩形的上部宽度和下部宽度并产生倾斜或能够计算它。
    • 你能提供一个你想要的参数化的例子吗?你必须从什么价值观开始,最终结果是什么?
    • 基本上我希望能够设置红色矩形的确切上部宽度,下部宽度应该完全等于黑色矩形。这应该成为轮胎计算器的图形表示。基本上黑色矩形代表轮辋,红色矩形代表它周围的轮胎。我已经设法使用可以通过 PHP/CSS 更改的手动编写的 SVG 走得很远。到目前为止,这似乎是最简单的方法。
    • 我现在有一个工作原型,里面有一些简单的意大利面条 PHP 行;)steffen-behn.de/RaederRechner/…
    • 真的很酷的想法。边界甚至没有必要。如果你把它们拿出来并去掉所有的“-1px”,它实际上是非常直接的!对我来说唯一的问题,我还需要能够“偏斜”到负值。由于我没有正确描述,我会接受你的回答 - 我真的很喜欢这种方法。负值示例:steffen-behn.de/RaederRechner/…
    猜你喜欢
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2021-09-08
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多