实现围绕某圆环旋转的效果,类似行星围绕地球旋转

如下图所示,虚线圆环上的文字已经打码,实际效果就是文字围绕圆环旋转,并到背面的时候文字虚化。

圆环直接使用的图片,文字自己绘制并添加动画。

原理:
利用动画的时间差,都让元素在同一个位置开始动画,运动轨迹使用塞尔曲线cubic-bezier()来定义,到元素背后的时候使用scale将透明度变高,让元素类似被遮盖一样。
注意:动画时间用负数,在第一次渲染的时候才不会出问题。
在这里插入图片描述

 <div class="topcenterbigitembox">
                        <div class="topcenbox1">
                            <div class="topcenboxitem topcenboxitem1">
                                文字
                            </div>
                            <div class="topcenboxitem topcenboxitem2">
                                文字
                            </div>
                            <div class="topcenboxitem topcenboxitem3">
                                文字
                            </div>
                            <div class="topcenboxitem topcenboxitem4">
                                文字
                            </div>
                            <div class="topcenboxitem topcenboxitem5">
                                文字
                            </div>
                            <div class="topcenboxitem topcenboxitem6">
                               文字
                            </div>
                        </div>
   <div>

//css
<style>
.topcenbox1 {
    width: 100%;
    height: 2rem;
    position: relative;
}
.topcenboxitem {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.18rem;
    font-family: YouShe;
    // background-image: -webkit-linear-gradient(bottom, #90e1ff, #d6eff8, #e5f6fd);
    // -webkit-background-clip: text;
    // -webkit-text-fill-color: transparent;
    color: #C0E7FF;
    background: rgba(0, 133, 247, 0.22);
    position: absolute;
    width: 1rem;
    z-index: 99;
}

.topcenboxitem1 {
    animation: animX0 10s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate,
        animY0 10s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate,
        scale 20s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate;
}

.topcenboxitem2 {
    animation: animX0 10s cubic-bezier(0.36, 0, 0.64, 1) -8.333s infinite alternate,
        animY0 10s cubic-bezier(0.36, 0, 0.64, 1) -3.333s infinite alternate,
        scale 20s cubic-bezier(0.36, 0, 0.64, 1) -3.333s infinite alternate;
}

.topcenboxitem3 {
    animation: animX0 10s cubic-bezier(0.36, 0, 0.64, 1) -11.666s infinite alternate,
        animY0 10s cubic-bezier(0.36, 0, 0.64, 1) -6.666s infinite alternate,
        scale 20s cubic-bezier(0.36, 0, 0.64, 1) -6.666s infinite alternate;
}

.topcenboxitem4 {
    animation: animX0 10s cubic-bezier(0.36, 0, 0.64, 1) -14.999s infinite alternate,
        animY0 10s cubic-bezier(0.36, 0, 0.64, 1) -9.999s infinite alternate,
        scale 20s cubic-bezier(0.36, 0, 0.64, 1) -9.999s infinite alternate;
}

.topcenboxitem5 {
    animation: animX0 10s cubic-bezier(0.36, 0, 0.64, 1) -18.332s infinite alternate,
        animY0 10s cubic-bezier(0.36, 0, 0.64, 1) -13.332s infinite alternate,
        scale 20s cubic-bezier(0.36, 0, 0.64, 1) -13.332s infinite alternate;
}

.topcenboxitem6 {
    animation: animX0 10s cubic-bezier(0.36, 0, 0.64, 1) -21.665s infinite alternate,
        animY0 10s cubic-bezier(0.36, 0, 0.64, 1) -16.665s infinite alternate,
        scale 20s cubic-bezier(0.36, 0, 0.64, 1) -16.665s infinite alternate;
}
//animX0 和animY0 控制运动的位置
@keyframes animX0 {
    0% {
        left: 0.05rem;//最左边的位置
    }

    100% {
        left: 8.3rem;//最右边的位置
    }
}

@keyframes animY0 {
    0% {
        top: 1rem;//最高
    }

    100% {
        top: 2.55rem;//最低
    }
}

@keyframes scale {
    0% {
        transform: scale(0.6);
        opacity: 0.7;
    }

    50% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(0.6);
        opacity: 0.7;
    }
}
</style>

效果图

  • 16
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,可以利用Java的多线程编程和Java的图形界面编程实现一个正在旋转地球。具体实现步骤如下: 1. 创建一个继承自JPanel的自定义面板组件,并在其中实现绘制旋转地球的方法。可以使用Java内置的图形库Graphics2D绘制地球。 2. 在主程序中创建一个JFrame窗体,并将自定义面板组件添加到窗体中。 3. 创建一个继承自Thread的自定义线程类,在其中实现地球旋转逻辑,并不断地调用自定义面板组件的repaint()方法刷新界面。 4. 在主程序中创建自定义线程类的实例,并启动线程。 下面是示例代码实现: ```java import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JFrame; import javax.swing.JPanel; public class EarthPanel extends JPanel { private static final long serialVersionUID = 1L; private int angle = 0; // 地球旋转角度 public EarthPanel() { setPreferredSize(new Dimension(400, 400)); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int width = getWidth() - 1; int height = getHeight() - 1; int x = width / 2; int y = height / 2; int radius = Math.min(width, height) / 2 - 10; g2d.setColor(Color.BLUE); g2d.fillOval(x - radius, y - radius, radius * 2, radius * 2); g2d.setColor(Color.WHITE); int innerRadius = (int) (radius * 0.9); int outerRadius = (int) (radius * 1.1); g2d.fillOval(x - innerRadius, y - innerRadius, innerRadius * 2, innerRadius * 2); g2d.fillOval(x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2); g2d.setColor(Color.GREEN); g2d.rotate(Math.toRadians(angle), x, y); g2d.fillOval(x - radius, y - radius, radius * 2, radius * 2); angle++; } public static void main(String[] args) { JFrame frame = new JFrame("Earth"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); EarthPanel panel = new EarthPanel(); frame.add(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); Thread thread = new Thread(() -> { while (true) { try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } panel.repaint(); } }); thread.start(); } } ``` 在该示例代码中,EarthPanel类是一个继承自JPanel的自定义面板组件,用于绘制旋转地球。在paintComponent()方法中,我们使用Graphics2D绘制了一个蓝色的圆形地球,并在地球周围绘制了白色的圆环。然后,我们使用绿色的颜色旋转绘制地球,并将旋转角度angle增加1。 在main()方法中,我们创建了一个JFrame窗体,并将自定义面板组件添加到窗体中。然后,我们创建了一个继承自Thread的自定义线程类,并在其中实现地球旋转逻辑。在while循环中,我们不断地调用自定义面板组件的repaint()方法刷新界面,从而实现地球旋转效果。 最后,我们创建了自定义线程类的实例,并启动线程。运行程序,即可看到正在旋转地球
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值