Skip to main content
2 of 3
deleted 1 character in body
R. Kap
  • 5k
  • 2
  • 16
  • 38

Java, 184 bytes

class A{public static void main(String[]a)throws Exception{for(int X=0,Y=0,x=1,y=1;;System.out.print("\033["+X+";"+Y+"H"),Thread.sleep(50),X+=x=X<1?1:X>24?-1:x,Y+=y=Y<1?1:Y>84?-1:y);}} 

This makes use of ANSI Escape Sequences to relocate the cursor, which is the object that bounces around a 85 x 25 terminal display. Save in a file named A.java.

Ungolfed

class Terminal_Bouncing_Ball { public static void main(String[] args) throws InterruptedException { int X = 0, Y = 0, dx = 1, dy = 1; while (true) { System.out.print(String.format("\033[%d;%dH",X,Y)); Thread.sleep(50); dx = (X < 1) ? 1 : (X > 71) ? -1 : dx; dy = (Y < 1) ? 1 : (Y > 237) ? -1 : dy; X += dx; Y += dy; } } } 

Demo

Example

R. Kap
  • 5k
  • 2
  • 16
  • 38