Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias ball {
- window -apd +e @pic 50 50 518 540
- set %pos[0].x 200.0 | set %pos[0].y 200.0
- set %dp[0].x 0.7 | set %dp[0].y 0.5
- set %pos[1].x 400.0 | set %pos[1].y 400.0
- set %dp[1].x -0.7 | set %dp[1].y -0.4
- set %rad 20
- var %max 0
- while (1) {
- dll WhileFix.dll WhileFix .
- var %t $ticks
- drawrect -fn @pic 0 1 0 0 500 500
- move 0
- move 1
- drawdot -n @pic 1 %rad %pos[0].x %pos[0].y
- drawdot -n @pic 1 %rad %pos[1].x %pos[1].y
- if ($calc((%pos[0].x - %pos[1].x)*(%pos[0].x - %pos[1].x)+(%pos[0].y - %pos[1].y)*(%pos[0].y - %pos[1].y)) $&
- <= $calc(4 * %rad * %rad)) {
- var %vx = $calc(%pos[1].x - %pos[0].x),%vy = $calc(%pos[1].y - %pos[0].y)
- var %len $dist(%vx,%vy,0,0)
- if (len > 0) {
- var %vx $calc(%vx / %len)
- var %vy $calc(%vy / %len)
- }
- push 0 $calc(-0.2 * %vx) $calc(-0.2 * %vy)
- push 1 $calc(0.2 * %vx) $calc(0.2 * %vy)
- var %rvx = $calc(%dp[0].x - %dp[1].x),%rvy = $calc(%dp[0].y - %dp[1].y)
- var %exv $calc(%rvx * %vx + %rvy * %vy)
- if (%exv > 0) {
- bs %dp[0].x $calc(%dp[0].x + %vx * 0.2 * %exv)
- bs %dp[0].y $calc(%dp[0].y + %vy * 0.2 * %exv)
- bs %dp[1].x $calc(%dp[1].x - %vx * 0.2 * %exv)
- bs %dp[1].y $calc(%dp[1].y - %vy * 0.2 * %exv)
- }
- }
- drawdot @pic
- var %t $calc($ticks - %t)
- if (%t > %max) { var %max %t | echo -a %max }
- }
- }
- alias dist return $sqrt($calc(( $1 - $3) * ( $1 - $3)) - (( $2 - $4) * ( $2 - $4)))
- alias move {
- var %px = $+(pos[,$1,].x),%py = $+(pos[,$1,].y)
- var %dx = $+(dp[,$1,].x),%dy = $+(dp[,$1,].y)
- bs %px $calc($bg(%px) + $bg(%dx))
- bs %py $calc($bg(%py) + $bg(%dy))
- if ($calc($bg(%py) - %rad) <= 0.0 && $bg(%dy) <= 0.0) bs %dy $calc($bg(%dy) * -1)
- if ($calc($bg(%py) + %rad) >= 500.0 && $bg(%dy) >= 0.0) bs %dy $calc($bg(%dy) * -1)
- if ($calc($bg(%px) - %rad) <= 0.0 && $bg(%dx) <= 0.0) bs %dx $calc($bg(%dx) * -1)
- if ($calc($bg(%px) + %rad) >= 500.0 && $bg(%dx) >= 0.0) bs %dx $calc($bg(%dx) * -1)
- }
- alias push {
- bs $+(pos[, $1 ,].x) $calc($bg($+(pos[, $1 ,].x)) + $2 )
- bs $+(pos[, $1 ,].y) $calc($bg($+(pos[, $1 ,].y)) + $3 )
- bs $+(dp[, $1 ,].x) $calc($bg($+(dp[, $1 ,].x)) + $2 )
- bs $+(dp[, $1 ,].y) $calc($bg($+(dp[, $1 ,].y)) + $3 )
- }
- alias bg return % [ $+ [ $1- ] ]
- alias bs set % [ $+ [ $1 ] ] $2
Advertisement
Add Comment
Please, Sign In to add comment