QML让圆形物体按照圆形轨迹运动和color使用rgba值的Demo
来源:互联网 发布:淘宝培训机构 编辑:程序博客网 时间:2024/05/01 13:06
看一下效果:
按照圆形运动,主要用到以下函数:
var angle = Math.PI * currentValue / 50.0;
var a1 = Math.cos(angle) * win.width/2;
var b1 = Math.sin(angle) * win.width/2;
这里面angle是旋转角度,currentValue是0到100的数值,win.width/2是半径,a1和b1是x,y。
代码我粘到下面:
import QtQuick 2.4
import QtQuick.Window 2.2
Window {
id:win
visible: true
width: 400
height: 400
property real currentValue : 0;
Rectangle {
width: parent.width/2
height: width
x: parent.width/4
y: parent.width/4
radius: width/2
color:"yellow"
}
Rectangle {
id: ball1
width: 50
height: width
radius: width/2
x:parent.width - width/2
y:parent.height/2 - height/2
color: "green"
}
Rectangle {
id: ball2
width: 40
height: width
radius: width/2
x:parent.width/4*3 - width/2
y:parent.height/2 - height/2
color:Qt.rgba(0.5,0.5,0.5,0.5)
}
Text {
id: txt
anchors.centerIn: parent
font.pixelSize: parent.width/5
color: "blue"
text: "0%";
}
Timer{
id: timer
interval: 50;
running: true;
repeat: true;
onTriggered: {
if(currentValue == 100) {
currentValue = 0;
}
currentValue += 1;
txt.text = currentValue.toString()+"%";
var angle = Math.PI * currentValue / 50.0;
var a1 = Math.cos(angle) * win.width/2;
var b1 = Math.sin(angle) * win.width/2;
var a2 = Math.cos(angle) * win.width/4;
var b2 = Math.sin(angle) * win.width/4;
ball1.x = win.width/2-ball1.width/2 + a1
ball1.y = win.height/2-ball1.width/2 + b1
ball2.x = win.width/2-ball2.width/2 + a2
ball2.y = win.height/2-ball2.width/2 + b2
}
}
}
- QML让圆形物体按照圆形轨迹运动和color使用rgba值的Demo
- 实现精灵沿着圆形轨迹运动
- 让精灵按照自己设定的轨迹运动
- 空间圆形物体的检测
- QML中圆形进度仪表盘控件的使用
- Unity 3d让物体成弧线运动(可以制作炮弹发射的轨迹)
- 让精灵按照自己设定的运动轨迹行动(曲线移动)。(以椭圆轨迹为例)。
- 让精灵按照自己设定的运动轨迹行动(曲线移动)。(以椭圆轨迹为例)。
- QML 实现圆形按钮
- Qml圆形图片
- Qml圆形进度条
- Qml圆形进度按钮
- Qml圆形波浪进度条
- 识别圆形物体
- 圆形图片CircleImageView的使用和分析
- 圆形图片CircleImageView的使用和分析
- sprite 圆形运动,圆周运动
- 让你的div 按轨迹运动
- Python进阶
- 初学者的CNN搭建示例(torch,cifar10数据集)
- 1012. 数字分类 (20)
- SpringMVC 文档学习笔记
- RxJava 从入门到爱上它
- QML让圆形物体按照圆形轨迹运动和color使用rgba值的Demo
- Linux下启动和停止apache服务
- hadoop涉及到分摊磁盘io负载的配置
- <Shader> 最终版本的水纹效果
- ubuntu12.04 挂载samba网盘命令
- (138)lightmass 全局光照
- nginx memcache Tomcat
- Linux(CentOS7) 系统中指定机器的IP地址(静态IP)
- Oravcle积累