From 514ddbfe1d3c1f773f911d17479094503ab26d95 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 23 Mar 2015 22:20:04 +0100 Subject: Framework week 8 --- Week8/src/qtrees/Bitmap.java | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Week8/src/qtrees/Bitmap.java (limited to 'Week8/src/qtrees/Bitmap.java') diff --git a/Week8/src/qtrees/Bitmap.java b/Week8/src/qtrees/Bitmap.java new file mode 100644 index 0000000..551c4c4 --- /dev/null +++ b/Week8/src/qtrees/Bitmap.java @@ -0,0 +1,73 @@ +package qtrees; + +/** + * Bitmap: A class for representing bitmap; + * @author Sjaak Smetsers + * @version 18-03-2015 + */ +public class Bitmap { + // each bit is stored into an two dimensional array + private final boolean[][] raster; + private final int bmWidth, bmHeight; + + /** + * Creates an empty bitmap of size width * height + * @param width + * @param height + */ + public Bitmap( int width, int height ) { + raster = new boolean[width][height]; + bmWidth = width; + bmHeight = height; + } + + /** + * Gets a bit at the specified position + * @param x: x coordinate + * @param y: y coordinate + */ + public boolean getBit( int x, int y ) { + return raster[x][y]; + } + + /** + * Sets a bit at the specified position + * @param x: x coordinate + * @param y: y coordinate + * @param val: the bit value + */ + public void setBit( int x, int y, boolean val ){ + raster[x][y] = val; + } + + /** + * Converts a bitmap into a string + * 1 is represented by '*'; 0 by 'O' + * @return the string representation + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int y = 0; y < bmHeight; y++) { + for (int x = 0; x < bmWidth; x++) { + sb.append( raster[x][y] ? '*' : 'O' ); + } + sb.append( '\n' ); + } + return sb.toString(); + } + + /** + * @return the width of the bitmap + */ + public int getWidth() { + return bmWidth; + } + + /** + * @return the height of the bitmap + */ + public int getHeight() { + return bmHeight; + } +} -- cgit v1.2.3