class Art{
public static void main( String [] args )
throws Exception{
System.out.println( "Type ‘q’ or nothing + Enter" );
while( true ){
int c = System.in.read();
if( c == ’q’ ){ break; }
clear();
moveTo( (int) Math.round( Math.random()*50 )
,
(int) Math.round( Math.random()*50 )
);
move(1,1); paintRect(8,8);
move(4,8); paintRect(4,4);
move(4,0); paintRect(2,2);
move(0,-6); paintRect(2,2);
move( 10,0);
paintText( "Type ‘q’ or nothing + Enter" );
} }
static char escape = (char) 27;
static char pen = ’#’;
static int row = 0, col = 0;
static void clear(){
System.out.print( escape + "[2J" );
row = 0;
col = 0;
}
static void setPen(char p){
pen = p;
}
static void moveTo(int r, int c){
row = r;
col = c;
}
static void move(int r, int c){
row += r;
col += c;
}
static void paintRect( int width, int height )
{
for( int i=0; i<height; i++) {
for( int j=0; j<width; j++ ){
System.out.print( escape + "["
+ (row+i) + ";" + (col+j) + "H" );
System.out.print( pen );
} } }
static void paintText( String text ){
System.out.print( escape + "[" + row + ";" + col + "H" );
System.out.print( text );
}
}
-_-_-