抛物运动轨迹线01

<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<style>
v/:* {behavior:url(#default#VML);}
o/:* {behavior:url(#default#VML);}
x/:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<SCRIPT LANGUAGE="JScript">
function Deg2Rad(Deg)
{
 return (Deg*Math.PI / 180);
}

//点x1,y1 经转af(角度)后的新点坐标x2,y2:(椭圆圈不能以此公式计算)
// x2 = x1 * Math.cos(alfa1) - (this.Earth0Rx/this.Earth0Ry) * y1 * Math.sin(alfa1);
// y2 = y1 * Math.cos(alfa1) + (this.Earth0Ry/this.Earth0Rx) * x1 * Math.sin(alfa1);

function rotpnt(x1,y1,af)
{
 this.x1 = x1;
 this.y1 = y1;

 var alfa1 = Deg2Rad(af);
 
 this.x2 = this.x1 * Math.cos(alfa1) - this.y1 * Math.sin(alfa1);
 this.y2 = this.x1 * Math.sin(alfa1) + this.y1 * Math.cos(alfa1);

}
//-----------------------------------------------------------------------------------

var originx0 = screen.availWidth/2;   //取屏幕宽度中值
var originy0 = screen.availHeight - 120; //取屏幕高度-120
var originz0 = 0;       //Z值
var flag = 0;

function line0(id,x0,y0,z0,from,to,strokecolor,strokeweight,dashstyle,rotation)
{
 var left,top,width,height
 var str = "";
 
 left = x0;
 top  = y0;
 str = str +"<v:line id="+id+" style='position:absolute; ";
 str = str +" left:"+left+"px;top:"+top+"px;Z-INDEX:"+z0+";rotation:"+rotation+";";
 str = str +" from='"+from+"' to='"+to+"' ";
 str = str +" strokeweight='"+strokeweight+"pt;' strokecolor='"+strokecolor+"'> ";
 str = str +" <v:stroke dashstyle='"+dashstyle+"' /> ";
 str = str +"</v:line>";
 document.write(str);
}

function line1(id,fromx,fromy,tox,toy)
{
 x0 = fromx;
 y0 = fromy;
 x1 = tox-fromx;
 y1 = toy-fromy;

 line0(id,x0,y0,3002,"0,0",""+x1+","+y1,"#00FFFF",1,"Dot",0)
}


function ellipsering(id,x0,y0,z0,ra,rb,filled,fillcolor,stroked,strokecolor,strokeweight,rotation)
{
 var left,top,width,height
 var str = "";
 
 left = x0-ra;
 top = y0-rb
 width = 2*ra;
 height = 2*rb;

 str = str +"<v:oval id="+id+" style='position:absolute; ";
 str = str +" left:"+left+"px;top:"+top+"px;width:"+width+"px;height:"+height+"px; ";
 str = str +" rotation:"+rotation+";z-index:"+z0+"' filled='"+filled+"' fillcolor="+fillcolor+" stroked='"+stroked+"' strokecolor="+strokecolor+" ";
 str = str +" strokeweight="+strokeweight+"pt> ";
 str = str +" <v:stroke dashstyle='solid'/> ";
 str = str +"</v:oval>";
 document.write(str);
}

function Parabola(a,b)
{
 this.ValueA = a;
 this.ValueB = Math.abs(b);
 this.num = 0;
 this.curr = 0;
}

function DrawParabola()
{
 var x0,y0,x1,y1,A,B,num;

// 抛物线虚点:
 A = this.ValueA;
 B = this.ValueB;

// clockwise: left -> right
// anticlockwise: right -> left
 this.CurrentX = 0 - (this.ValueB * this.BallDirection);
 this.num = 0;
 for(x0=(-B*this.BallDirection);
  x0*this.BallDirection <= B;
  x0 += this.BallStep*this.BallDirection) {

  this.num++;

  y0 =  A * ( x0 * x0 - B * B);
  ellipsering("p"+this.num,
   originx0 + x0,
   originy0 + y0,
   this.num,
   this.BallRadius,
   this.BallRadius,
   "t","#000222","t","#000222",0,"0");

 }
 window.status = ""+x0+"; "+y0+"; "+this.num;
}

function BallMove() {
 var x0,y0,x1,y1,A,B,num;

 A = this.ValueA;
 B = this.ValueB;

 if(flag==1) setTimeout("Parabola0.BallWv()",this.BallInterval);   //控制转停

 x0 = this.CurrentX;
 y0 =  A * ( x0 * x0 - B * B);

 x1 = originx0 + x0;
 y1 = originy0 + y0;

 this.curr++;

 obj1 = "p"+this.curr;
// eval(obj1+".style.left=" + x1);
// eval(obj1+".style.top="  + y1);

// 一个球着色时,前一个球的色要复原:

 if (this.curr == 1)
 {
  obj2 = "p"+this.num;
  eval(obj2+".fillcolor='#000222'");
  eval(obj2+".style.zIndex="+1);
 }
 if ((this.curr > 1) && (this.curr <= this.num))
 {
  obj2 = "p"+this.curr;
  eval(obj2+".fillcolor='##FF0000'");
  eval(obj2+".style.zIndex="+this.num);
  obj2 = "p"+(this.curr-1);
  eval(obj2+".fillcolor='#000222'");
  eval(obj2+".style.zIndex="+1);
 }

 if (this.curr >= this.num)
 {

  start.disabled=0;
  this.curr = 0;
  flag = 0;
 }
 window.status = ""+x0+"; "+y0+";"+this.curr;
}

</SCRIPT>

</head>
<body scroll=yes style="font-family: 宋体; background-color: #000000; color:#FF00FF">
抛物运动轨迹线。可改变大小,颜色等。(谷来成,2007-3-18)<br><br><br>

<button οnclick="flag=1;Parabola0.BallWv();this.disabled=1;" id='start'>开始</button>开始运动。<br>
<button οnclick="flag=0;start.disabled=0;">停止</button>停止运动。<br>
<button οnclick="flag=0;Parabola0.BallWv();start.disabled=0;">分解</button>分解动作。
<script>

line0("vml1",originx0-400,originy0,3001,"0,0","800,0","#0000FF",1,"Dot",0)
line0("vml2",originx0,originy0-600,3002,"0,0","0,620","#0000FF",1,"Dot",0)

// y = a * (x^2 - b^2)

Parabola0 = new Parabola(0.0115,200);

Parabola.prototype.Dp = DrawParabola;
Parabola.prototype.BallWv = BallMove;

//Parabola:

Parabola.prototype.BallRadius = 12;   //小球的半径
Parabola.prototype.BallAngle = 0;   //小球运动时的起始角
Parabola.prototype.BallStep  = 5;   //小球运动时的步长
Parabola.prototype.BallDirection = 1;  //小球运动方向(1:clockwise,-1:anticlockwise)
Parabola.prototype.BallInterval  = 60;  //时间间隔

Parabola0.Dp();

</script>
</body>
</html>
 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 要在Scratch中实现抛物线运动,需要使用计时器和移动积木。首先,创建一个计时器,然后设置一个变量来跟踪时间。接下来,使用运动积木让角色沿着x轴和y轴移动。最后,使用公式 (x = at^2 + bt + c) 和 (y = dt^2 + et + f) 来计算角色的位置,其中 a,b,c,d,e,f是常量。 ### 回答2: 抛物线运动是指一个物体在受到重力影响的情况下,沿着抛物线轨迹运动的现象。在Scratch中,我们可以通过利用角度与重力的概念,来实现抛物线运动的效果。 首先,我们需要创建一个角色,代表抛物线运动的物体。可以选择一个合适的图标来代表该角色,并设置其初始位置。接下来,我们需要定义相关的变量。 我们可以定义一个变量来表示物体在x轴方向上的位移,例如变量名为“x”。初始时,将其设为0。我们还可以定义一个变量来表示物体在y轴方向上的位移,例如变量名为“y”。初始时,将其设为0。 然后,我们需要设置物体的运动规律。在每一帧中,物体在x轴方向上的位移都应该增加一个固定值,例如1,以保持匀速直线运动。我们可以使用Scratch中的“改变x by 1”积木块实现这个功能。 接下来,我们需要根据物体的位置来计算物体在y轴方向上的位移。由于抛物线运动是受到重力影响的,物体在y轴方向上的位移应随时间递增,且增量随时间增大而增大。为了实现这个效果,我们可以使用一个循环,让每一帧中的y轴位移都增加一个较大的数值。例如,在每一帧中,可以使用“改变y by 10”积木块来让y轴位移增加10个单位。 最后,我们需要添加一个条件,以停止物体的运动。一般来说,当物体的y轴位移超过一定的值,或者物体的x轴位移超过一定的范围时,我们可以认为物体已经完成了抛物线运动。我们可以将这个条件写入一个判断语句中,例如,“如果y大于100 或者 x小于-200,则停止运动”。在满足这个条件时,我们可以使用Scratch中的“停止所有”积木块来停止物体的运动。 通过以上的步骤,我们就可以在Scratch中实现抛物线运动的效果。通过调节不同的参数,如角度、重力等,我们可以创建不同形状和大小的抛物线运动物体。 ### 回答3: 使用Scratch实现抛物线运动可以通过以下步骤实现: 1. 创建角色:在Scratch的舞台中创建一个角色,用于表示抛物线运动的物体。 2. 设置角色初始位置:将角色放置在舞台的起始位置,确保它位于抛物线的起点。 3. 设置角色的运动轨迹:点击角色,选择“运动”类别,在运动模块中选择“移动到x: [] y: []”模块。根据抛物线的方程,通过改变x和y的值来实现运动轨迹。 4. 添加重力效果:为了实现抛物线运动,我们需要加入重力的效果。点击角色,选择“运动”类别,在运动模块中选择“重力(0.2)加速度”模块。调整加速度的值以获得所需的抛物线效果。 5. 添加弹跳效果:如果需要让角色在抛物线的顶点反弹,可以点击角色,选择“事件”类别,然后选择“当接触边缘时反弹”模块。 6. 重复运动:使用“重复”模块或“循环”模块,使角色重复执行运动轨迹,以实现持续的抛物线运动。 7. 角色动作:可以为角色添加动作,如旋转、改变大小等,以增加视觉效果。 总结:使用Scratch可以通过设置角色的初始位置、运动轨迹和重力效果,结合重复运动来实现抛物线运动。此外,你还可以根据需要添加其他特效和动作来提升抛物线运动的视觉效果。以上步骤简要介绍了如何使用Scratch实现抛物线运动

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值