import java.util.Scanner;
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
/**
* Partial solution for Stage 1 of the digital billboard
*
* @author Darren Jones (10132281)
* @version 2011 2
*/
public class ArraysBillboard
{
private static final int LETTER_WIDTH = 5;
private static final int LETTER_HEIGHT = 12;
private static final int GAP = 1;
private static final int[][] _s =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 1},
{0, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _p =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0}
};
private static final int[][] _a =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, },
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 1, 1, 0, 1},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _r =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 0, 1, 1, 0},
{0, 1, 0, 0, 1},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _e =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{0, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
public static void main(String[] args)
{
String text;
Scanner keyboard = new Scanner(System.in);
// initial size of the display in pixels
final int WINDOW_WIDTH = 300;
final int WINDOW_HEIGHT = 120;
// size of the grid for the digital billboard
final int BB_WIDTH = 50;
final int BB_HEIGHT = 30;
// create a billboard
BillboardInterface billboard = new DigitalBillboardFrame(
"SCSS",
WINDOW_WIDTH, WINDOW_HEIGHT,
BB_WIDTH, BB_HEIGHT);
// we will make letters 5 cells wide and 12 high
final int LETTER_WIDTH = 5;
final int LETTER_HEIGHT = 12;
// and leave a 1 cell gap between letters
final int GAP = 1;
final int START_X = 11;
final int START_Y = 8;
String inputText;
// first make sure the display is blank
billboard.allOff();
// forever
for(;;)
{
// get a message from the user
keyboard = new Scanner(System.in);
System.out.print("Enter a 5 letter word made up of a,e,p,r,s: ");
inputText = keyboard.nextLine();
// first make sure the display is blank
billboard.allOff();
// for each letter in the message
int x = START_X;
int y = START_Y;
writeText(billboard, x, y, inputText);
billboard.redisplay(0);
}
}
private static void writeText(BillboardInterface billboard, int x, int y, String text)
{
for(int i = 0; i < 5; i++)
{
writeLetter(billboard, x, y,(text).charAt(i));
x += LETTER_WIDTH + GAP;
}
}
private static void writeLetter(BillboardInterface billboard, int x, int y, char c)
{
// display the i_th letter
switch(c)
{
case 's':
write_s(billboard, x, y);
break;
case 'p':
write_p(billboard, x, y);
break;
case 'a':
write_a(billboard, x, y);
break;
case 'r':
write_r(billboard, x, y);
break;
case 'e':
write_e(billboard, x, y);
break;
default:
}
}
private static void write_s(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(x+1, y+2);
billboard.turnOn(x+2, y+2);
billboard.turnOn(x+3, y+2);
billboard.turnOn(x+4, y+2);
billboard.turnOn(x, y+3);
billboard.turnOn(x, y+4);
billboard.turnOn(x+1, y+5);
billboard.turnOn(x+2, y+5);
billboard.turnOn(x+3, y+5);
billboard.turnOn(x+4, y+6);
billboard.turnOn(x+4, y+7);
billboard.turnOn(x, y+8);
billboard.turnOn(x+1, y+8);
billboard.turnOn(x+2, y+8);
billboard.turnOn(x+3, y+8);
}
private static void write_p(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(x+1, y+2);
billboard.turnOn(x, y+3);
billboard.turnOn(x, y+4);
billboard.turnOn(x, y+5);
billboard.turnOn(x, y+6);
billboard.turnOn(x, y+7);
billboard.turnOn(x, y+8);
billboard.turnOn(x, y+9);
billboard.turnOn(x, y+10);
billboard.turnOn(x, y+11);
billboard.turnOn(x+4, y+3);
billboard.turnOn(x+4, y+4);
billboard.turnOn(x+4, y+5);
billboard.turnOn(x+4, y+6);
billboard.turnOn(x+4, y+7);
billboard.turnOn(x+1, y+8);
billboard.turnOn(x+2, y+8);
billboard.turnOn(x+3, y+8);
billboard.turnOn(x, y+2);
billboard.turnOn(x+2, y+2);
billboard.turnOn(x+3, y+2);
}
private static void write_a(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(x, y+3);
billboard.turnOn(x, y+4);
billboard.turnOn(x, y+5);
billboard.turnOn(x, y+6);
billboard.turnOn(x, y+7);
billboard.turnOn(x+1, y+2);
billboard.turnOn(x+2, y+2);
billboard.turnOn(x+3, y+3);
billboard.turnOn(x+3, y+4);
billboard.turnOn(x+3, y+5);
billboard.turnOn(x+3, y+6);
billboard.turnOn(x+3, y+7);
billboard.turnOn(x+1, y+8);
billboard.turnOn(x+2, y+8);
billboard.turnOn(x+4, y+8);
}
private static void write_r(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(x, y+2);
billboard.turnOn(x+1, y+3);
billboard.turnOn(x+1, y+4);
billboard.turnOn(x+1, y+5);
billboard.turnOn(x+1, y+6);
billboard.turnOn(x+1, y+7);
billboard.turnOn(x+1, y+8);
billboard.turnOn(x+2, y+2);
billboard.turnOn(x+3, y+2);
billboard.turnOn(x+4, y+3);
}
private static void write_e(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(x, y+3);
billboard.turnOn(x, y+4);
billboard.turnOn(x, y+5);
billboard.turnOn(x, y+6);
billboard.turnOn(x, y+7);
billboard.turnOn(x+1, y+8);
billboard.turnOn(x+2, y+8);
billboard.turnOn(x+3, y+8);
billboard.turnOn(x+4, y+7);
billboard.turnOn(x+1, y+5);
billboard.turnOn(x+2, y+5);
billboard.turnOn(x+3, y+5);
billboard.turnOn(x+1, y+2);
billboard.turnOn(x+2, y+2);
billboard.turnOn(x+3, y+2);
billboard.turnOn(x+4, y+3);
billboard.turnOn(x+4, y+4);
}
private static void writeArray(BillboardInterface billboard, int x, int y,int[][] pixels)
{
for(int row = 0; row < pixels.length; row++)
{
for(int col = 0; col < pixels[row].length; col++)
{
// if the pixel for this row and column is a 1
// then call turnOn for the grid cell that
// corresponds to this pixel
}
}
}
}