前端特效(2)--旋转的风车

旋转的风车效果主要利用的知识点:

  1. 变形:transform:rotate() // 旋转度数(deg)
  2. 过渡:
    transition集合样式(css3的动画的一种)
    transition-property:要运动的样式(all || [attr] || none)
    transition-duration:规定完成过渡效果需要多少秒或毫秒
    transition-delay:定义动画延迟多久开始
    transition-timing-function:运动速度曲线。

ease:(逐渐变慢)默认值;
linear:(匀速);
ease-in:(加速);
ease-out:(减速);
ease-in-out:(先加速后减速);
cubic-bezier 贝塞尔曲线( x1, y1, x2, y2)可以百度一下贝赛尔曲线的图

  1. 圆角:
    border-radius集合样式
    (border-top-left-radius/border-top-right-radius/border-bottom-right-radius/border-bottom-left-radius)

    1-4个数字 / 1-4个数字:/前面是水平方向圆角,后面是垂直方向圆角,不加/指的两个方向圆角相同,如:
    border-radius: 10px/5px;
    参数:各种长度单位都可以:px,%,…,%有时很方便,但宽高不一致时不太好
    参数个数1:四个方向都一样,border-radius: 一样
    参数个数2:对角,border-radius: 左上&右下 右上&左下
    参数个数3:斜对角,border-radius: 左上 右上&左下 右下
    参数个数4:全部,顺时针,border-radius: 左上 右上 右下 左

参考代码:

  <style>
    .parent{
        width:600px;
        height:600px;
        margin: 0 auto;
        overflow: hidden;
        /* border: 1px #000 solid; */
        transition: 10s all linear;

    }
    .parent>div {
        width:300px;
        height: 300px;
        background-color: red;
        float:left;
    }
     .parent>div:nth-child(1),.parent>div:nth-child(4){
        border-radius: 0%  90%;
    } 
    .parent>div:nth-child(2),.parent>div:nth-child(3){
        border-radius: 90% 0%;
    }
    .parent:hover{
        transform: rotate(1800deg);
    }
    </style>

效果图:(此处有动画效果 鼠标悬停在上面的时候进行旋转)
在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是用OpenGL绘制旋转风车的代码示例。首先,我们需要定义风车的各个部分,包括风车的支架、风车的叶片等。然后,我们需要定义风车旋转角度,以及旋转中心点的坐标。最后,我们使用OpenGL的旋转函数来实现风车旋转效果。 ```c++ #include <GL/glut.h> #include <math.h> #define PI 3.1415926535898 // 定义风车的各个部分 void drawWindmill() { // 绘制风车的支架 glBegin(GL_POLYGON); glColor3f(0.5, 0.5, 0.5); glVertex2f(-0.05, 0); glVertex2f(0.05, 0); glVertex2f(0.05, 1.5); glVertex2f(-0.05, 1.5); glEnd(); // 绘制风车的叶片 glBegin(GL_POLYGON); glColor3f(0.9, 0.9, 0.9); glVertex2f(0, 1.5); glVertex2f(0.2, 1.8); glVertex2f(0, 2.1); glVertex2f(-0.2, 1.8); glEnd(); } // 定义风车旋转角度和旋转中心点的坐标 float angle = 0; float centerX = 0; float centerY = 0; // 定义绘制函数 void display() { // 清空颜色缓存和深度缓存 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 绘制风车,并进行旋转 glPushMatrix(); glTranslatef(centerX, centerY, 0); glRotatef(angle, 0, 0, 1); glTranslatef(-centerX, -centerY, 0); drawWindmill(); glPopMatrix(); // 刷新缓存区 glutSwapBuffers(); } // 定义定时器函数,用于控制旋转角度 void timer(int value) { angle += 5; if (angle >= 360) { angle -= 360; } glutPostRedisplay(); glutTimerFunc(50, timer, 0); } // 定义窗口大小和标题 int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(400, 400); glutCreateWindow("Windmill"); // 设置背景颜色为白色 glClearColor(1, 1, 1, 0); // 设置投影矩阵 glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-2, 2, -2, 2); // 注册回调函数 glutDisplayFunc(display); glutTimerFunc(50, timer, 0); // 进入主循环 glutMainLoop(); return 0; } ``` 在上述代码中,我们首先定义了风车的支架和叶片的绘制函数`drawWindmill()`,并且定义了风车旋转角度和旋转中心点的坐标。在绘制函数`display()`中,我们使用OpenGL的旋转函数`glRotatef()`来实现风车旋转效果。在定时器函数`timer()`中,我们控制旋转角度的变化,并且在每次旋转时调用`glutPostRedisplay()`函数来刷新缓存区。 最后,在`main()`函数中,我们设置窗口大小和标题,并且注册回调函数。在`gluOrtho2D()`函数中,我们定义了投影矩阵,使得绘制的图形不会因为窗口大小的改变而变形。在主循环中,我们使用`glutMainLoop()`函数进入消息循环。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值