how to put a function inside animation
显示 更早的评论
Hi, I have to program a bouncing ball using a function I created before called drawball, now I can't implement this function inside my program, it only shows me a big ball, here are the scripts I used:
function drawdisc(x0,y0,r,c)
t=0:0.01:2*pi;
x=r*cos(t)+x0;
y=r*sin(t)+y0;
fill(x,y,c)
end
the bouncing ball script:
clc;
initpos=0; %Ball's initial vertical position
initvel=20; %Ball's initial vertical velocity
r_ball=1; %Ball's radius
gravity=10; %Gravity's acceleration
c_bounce=0.85; %Bouncing's coefficient of elasticity
dt=0.0125; %Animation timestep;
pos=r_ball; %Ball's current vertical position
vel=initvel;%Ball's current vertical velocity
axis([0 20 0 25])
while 1
pos=pos+(vel*dt); %Ball's current vertical position
vel=vel-(gravity*dt); %Ball's current vertical velocity
if pos<0
vel=-vel*c_bounce; %Balls' current vertical velocity
end
drawball(1,pos,1,'b')
pause(0.01)
end
your help is appreciated!!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Animation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!