h5自旋转六面体

css代码

* {
        margin: 0;
        padding: 0;
      }
      ul li {
        list-style: none;
      }
      .stage {
        width: 800px;
        height: 600px;
        background: #eee;
        margin: 50px auto;
        position: relative;
        perspective: 1200px;
      }
      .lmt {
        width: 400px;
        height: 400px;
        border: 1px #000 solid;
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        margin: auto;
        transform-style: preserve-3d;
        animation: xuanzhuan 5s linear infinite alternate;
      }
      .lmt li {
        width: 400px;
        height: 400px;
        font-size: 72px;
        text-align: center;
        line-height: 400px;
        position: absolute;
      }
      .lmt li:nth-child(1) {
        background: rgba(255, 0, 0, 0.5);
        transform: translateZ(200px);
      }
      .lmt li:nth-child(2) {
        background: rgba(0, 255, 0, 0.5);
        transform: translateZ(-200px) rotateY(180deg);
      }
      .lmt li:nth-child(3) {
        background: rgba(0, 0, 255, 0.5);
        transform: translateX(-200px) rotateY(-90deg);
      }
      .lmt li:nth-child(4) {
        background: rgba(255, 255, 0, 0.5);
        transform: translateX(200px) rotateY(90deg);
      }
      .lmt li:nth-child(5) {
        background: rgba(255, 0, 255, 0.5);
        transform: translateY(-200px) rotateX(90deg);
      }
      .lmt li:nth-child(6) {
        background: rgba(0, 255, 255, 0.5);
        transform: translateY(200px) rotateX(-90deg);
      }

      @keyframes xuanzhuan {
        from {
          transform: rotateX(0) rotateY(0);
        }
        to {
          transform: rotateX(360deg) rotateY(360deg);
        }
      }

html代码

 <div class="stage">
      <ul class="lmt">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是使用OpenGL和C++编写的可旋转六面体的示例代码: ```c++ #include <GL/glut.h> // 六面体的顶点坐标 GLfloat vertices[][3] = { {-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0} }; // 六面体的面 GLint faces[][4] = { {0, 1, 2, 3}, {1, 5, 6, 2}, {5, 4, 7, 6}, {4, 0, 3, 7}, {0, 4, 5, 1}, {3, 2, 6, 7} }; // 六面体的颜色 GLfloat colors[][3] = { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 1.0, 0.0}, {1.0, 0.0, 1.0}, {0.0, 1.0, 1.0} }; // 六面体旋转的角度 GLfloat angleX = 0.0; GLfloat angleY = 0.0; // 绘制六面体 void drawCube() { for (int i = 0; i < 6; i++) { glBegin(GL_QUADS); glColor3fv(colors[i]); for (int j = 0; j < 4; j++) { glVertex3fv(vertices[faces[i][j]]); } glEnd(); } } // 显示回调函数 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(angleX, 1.0, 0.0, 0.0); glRotatef(angleY, 0.0, 1.0, 0.0); drawCube(); glutSwapBuffers(); } // 鼠标回调函数 void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { angleX += 5.0; } else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { angleY += 5.0; } glutPostRedisplay(); } // 初始化函数 void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); } // 主函数 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow("Rotating Cube"); glutDisplayFunc(display); glutMouseFunc(mouse); init(); glutMainLoop(); return 0; } ``` 在这个示例中,我们定义了一个六面体的顶点坐标、面和颜色。然后,我们使用OpenGL绘制六面体,并在回调函数中旋转六面体。我们使用glRotatef函数来旋转六面体,其中angleX和angleY分别存储了旋转的角度。在鼠标回调函数中,我们检测鼠标左键和右键的单击事件,并相应地调整角度。最后,我们使用glutMainLoop函数进入主循环,等待事件的发生。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值