/*
软件作者:https://xuhss.com/oxox/pro
*/
/**
* 作者: 家
* QQ: 203118908
* 功能: 小球边缘运动
* 日期: 2019.3.5
*/
"ui";
var MarqueeView = (function() {
//继承至ui.Widget
util.extend(MarqueeView, ui.Widget);
function MarqueeView() {
//调用父类构造函数
ui.Widget.call(this);
this.defineAttr("speed", (view, name, defaultGetter) => {
return this.speed;
}, (view, name, value, defaultSetter) => {
this.speed = value;
});
}
MarqueeView.prototype.render = function() {
return (
<img id="ball" src="@drawable/ic_stars_black_48dp"
circle="true" layout_width="wrap_content" layout_height="wrap_content" />
);
}
function getInfo(view){
var width=view.getWidth()
var height=view.getHeight()
var left=view.x
var right=left+width
var top=view.y
var bottom=top+height
ui.run(
()=>{
view.left=left
view.right=right
view.top=top
view.bottom=bottom
view.setRightPosition=function (position){
view.setX(position-width)
}
}
)
return view
}
function ballMove(ball,startPoint,endPoint,sleepTime,moveDistance){
log("ballMove 66666666666")
var sleepTime=ball.sleepTime || sleepTime
var moveDistance=ball.moveDistance || moveDistance
var startX=startPoint.x
var endX=endPoint.x
var startY=startPoint.y
var endY=endPoint.y
if(startX==endX){
var start=startY
var end=endY
var flag="y"
}else if(startY==endY){
var start=startX
var end=endX
var flag="x"
}else{
alert('你自己加运动方式')
exit()
}
log('运动轴是',flag)
if(flag=="x"){
moveDistance=end-start>0 ? moveDistance : moveDistance * -1
var count=0
var MaxCount=Math.abs(Math.floor(Math.abs(end-start) / moveDistance))
log('运动次数=',MaxCount)
while(count<=MaxCount){
var position=start+moveDistance*count++;
ball.setX(position)
sleep(sleepTime)
}
}else if(flag=="y"){
moveDistance=end-start>0 ? moveDistance : moveDistance * -1
var count=0
var MaxCount=Math.abs(Math.floor(Math.abs(end-start) / moveDistance))
while(count<=MaxCount){
var position=start+moveDistance*count++;
ball.setY(position)
sleep(sleepTime)
}
}else{
alert('flag=',flag)
exit()
}
}
MarqueeView.prototype.move = function() {
var that=this;
var moveThread=threads.start(
function (){
var sleepTime=rndNum(20,100)
var moveDistance=rndNum(20,100)
while(1){
var view=that.view.ball
view=getInfo(view)
view.sleepTime=sleepTime
view.moveDistance=moveDistance
if(view ){
log('viewyyyyyyyyyyyyyyyyyyyyy')
var startPoint=null;
var endPoint=null;
//左面,从下往上
startPoint={
x:0,
y:view.y
}
endPoint={x:0,y:0}
log('左面运动开始')
ballMove(view,startPoint,endPoint)
log('左面运动结束')
//上面,从左往右
startPoint={x:0,y:0}
endPoint={x:device.width-view.width,y:0}
log('上面运动开始')
ballMove(view,startPoint,endPoint)
log('上面运动结束')
//右面,从上往下
startPoint=endPoint
endPoint={x:device.width-view.width,y:device.height-view.height}
log('右面运动开始')
ballMove(view,startPoint,endPoint)
log('右面运动结束')
//下面,从右往左
startPoint=endPoint
endPoint={x:0,y:device.height-view.height}
log('下面运动开始')
ballMove(view,startPoint,endPoint)
log('下面运动结束')
//左面,从下往上
startPoint=endPoint
endPoint={x:0,y:0}
log('左面运动开始')
ballMove(view,startPoint,endPoint)
log('左面运动结束')
if(moveThread){
moveThread.interrupt();
}
}
// sleep(sleepTime)
}
}
)
}
function rndNum(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
function rndColor(){
return colors.rgb(random(0, 255), random(0, 255), random(0, 255))
}
ui.registerWidget("MarqueeView", MarqueeView);
return MarqueeView;
})();
ui.layout(
<vertical>
<vertical id="parentView" text="parent">
<MarqueeView />
<MarqueeView />
<MarqueeView />
<MarqueeView />
<MarqueeView />
<MarqueeView />
<MarqueeView />
<MarqueeView />
</vertical>
<button id="ok" text="结束"/>
</vertical>
);
threads.start(
function(){
var flag=false
while(1){
ui.run(
function(){
var view=ui.parentView
log("view.childCount=",view.childCount)
if(view.childCount>=8){
for(var i=0;i<view.childCount;i++){
var sonView=view.getChildAt(i)
sonView.widget.move()
}
flag=true;
}
}
)
if(flag){
break
}
sleep(100)
}
}
)
ui.ok.on("click", function () {
ui.finish()
exit()
});
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
[虚幻私塾】
- 粉丝: 336
- 资源: 1558
最新资源
- 1517-基于51单片机的双机通信(数码管,数字,LED)proteus、原理图、流程图、物料清单、仿真图、源代码.zip
- 1516-基于51单片机的双机通信(键值,LCD)proteus,原理图、流程图、物料清单、仿真图、源代码.zip
- 鲸鱼算法算支持向量机SVM回归分析,鲸鱼算法优化支持向量机SVM沉降预测(代码完整,数据齐全)
- 1512-基于51单片机的数字时钟闹钟设计(液晶显示器)proteus,原理图、流程图、物料清单、仿真图、源代码.zip
- 1510-基于51单片机的数控电源(TLC1543,温度,电压,电流,可调)proteus,原理图、流程图、物料清单、仿真图、源
- 1509-基于51单片机的数控电流源(8挡)proteus,原理图、流程图、物料清单、仿真图、源代码.zip
- 计算机网络第八版(谢希仁)课后习题答案
- 1507-基于51单片机的数电交通灯1proteus,流程图、物料清单、仿真图、源代码.zip
- 主成分分析MATLAB实现
- 1505-基于51单片机的输液报警控制系统设计(滴速,液位)proteus,原理图、流程图、物料清单、仿真图、源代码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)