/* Diese Werte kann man einstellen */ Rahmenhoehe : 20; Rahmenlaenge : 20; startposx : 1.0; startposy : 1.0; startvx : 5.0; startvy : 1.0; deltat : .5; anzahlBilder : 1000; R : 0.5; /* Hier beginnt das Programm */ xpos : startposx; ypos : startposy; vx : startvx; vy : startvy; load (draw); posberechnen(ttmp) := block ([x], /* Berechnet die Position nach ttmp */ xtmp : xpos + ttmp * vx, ytmp : ypos + ttmp * vy, ts : ttmp, /* Auftreffzeit finden, wenn etwas zu tun ist */ if (xtmp - R < 0) then ts : rhs (solve (xpos + t * vx = R, t)), if (xtmp + R > Rahmenlaenge) then ts : rhs (solve (xpos + t * vx = Rahmenlaenge - R, t)), if (ytmp - R < 0) then ts : rhs (solve (ypos + t * vy = R, t)), if (ytmp + R > Rahmenlaenge) then ts : rhs (solve (ypos + t * vy = Rahmenlaenge - R, t)), restzeit : ttmp - ts, xpos : xpos + ts * vx, ypos : ypos + ts * vy, /* Der Ball hat die neue Position, dann gilt restzeit = 0 */ /* Oder der Ball befindet sich am Rand */ /* vx oder vy wird gespiegelt */ if (xtmp - R <= 0) then vx : -vx, if (xtmp + R >= Rahmenlaenge) then vx : -vx, if (ytmp - R <= 0) then vy : -vy, if (ytmp + R >= Rahmenlaenge) then vy : -vy, if (restzeit > 0) then posberechnen (restzeit) ); bilderstellen() := block ([], [gr2d ( color = black, fill_color = black, xrange = [0, Rahmenlaenge], yrange = [0, Rahmenhoehe], implicit ( (x-xpos)^2 + (y-ypos)^2 = R^2, x, -R+xpos, R+xpos, y, -R+ypos, R+ypos) )] ); bildliste : []; for i thru anzahlBilder do block ([], bild : bilderstellen (), bildliste : append (bildliste, bild), posberechnen (deltat), print (xpos, ypos) ); draw ( dimensions = [500, 500], bildliste, file_name = "ball", terminal = 'animated_gif );