Skip to content

Commit 033ebca

Browse files
author
Rafael Grigorian
committed
Released Version 1.0.2
1 parent c17cfae commit 033ebca

File tree

9 files changed

+51
-12
lines changed

9 files changed

+51
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
> Pixel graphics in terminal implemented with unicode braille characters
33
44
![MIT License](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=for-the-badge)
5-
![Version 1.0.0](https://img.shields.io/badge/Version-1.0.0-lightgrey.svg?style=for-the-badge)
5+
![Version 1.0.2](https://img.shields.io/badge/Version-1.0.2-lightgrey.svg?style=for-the-badge)
66
![Travis CI](https://img.shields.io/travis/null93/drawille.svg?style=for-the-badge&colorB=9f9f9f)
77

88
## About

dist/drawille-1.0.0.jar

-6.46 KB
Binary file not shown.

dist/drawille-1.0.2.jar

6.74 KB
Binary file not shown.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>io.raffi</groupId>
77
<artifactId>drawille</artifactId>
88
<packaging>jar</packaging>
9-
<version>1.0.1</version>
9+
<version>1.0.2</version>
1010
<name>drawille</name>
1111
<url>http://maven.apache.org</url>
1212
<properties>

src/main/java/io/raffi/drawille/BrailleMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* This class stores a 4 by 2 pixel matrix that is eventually translated into a braille character.
77
* This method abstracts away all the calculations that is needed to transform a matrix into a
88
* braille character. This class is meant to be used as a sub-matrix.
9-
* @version 1.0.1
9+
* @version 1.0.2
1010
* @package io.raffi.drawille
1111
* @author Rafael Grigorian <[email protected]>
1212
* @copyright 2018 Rafael Grigorian — All Rights Reserved

src/main/java/io/raffi/drawille/Canvas.java

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.raffi.drawille;
22

3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
35
import java.util.Arrays;
46

57
/**
68
* This class is used to hold all the BrailleMap objects and uses them as sub-matrices. It is an
79
* abstraction of a pixel screen. Methods to interact with those pixels can be found in this class.
8-
* @version 1.0.1
10+
* @version 1.0.2
911
* @package io.raffi.drawille
1012
* @author Rafael Grigorian <[email protected]>
1113
* @copyright 2018 Rafael Grigorian — All Rights Reserved
@@ -145,15 +147,39 @@ public void clear () {
145147
/**
146148
* This method traverses through all the BrailleMap objects and renders out the sub-matrices by
147149
* asking for the object's string value with the getString method. It then prints them all out
148-
* to the screen.
150+
* to the screen by using the overloaded cooresponding render method.
151+
* @return void
149152
*/
150153
public void render () {
154+
ByteArrayOutputStream stream = new ByteArrayOutputStream ();
155+
try {
156+
this.render ( stream );
157+
}
158+
catch ( IOException e ) {
159+
System.out.print ( e );
160+
}
161+
System.out.print ( stream.toString () );
162+
}
163+
164+
/**
165+
* This method traverses through all the BrailleMap objects and renders out the sub-matrices by
166+
* asking for the object's string value with the getString method. It then writes said output to
167+
* the specified ByteArrayOutputStream. This stream is then returned back to caller for method
168+
* chaining.
169+
* @param ByteArrayOutputStream stream Stream to write to
170+
* @return ByteArrayOutputStream Same stream that was passed in
171+
* @throws IOException ByteArrayOutputStream throws exception
172+
*/
173+
public ByteArrayOutputStream render ( ByteArrayOutputStream stream ) throws IOException {
151174
for ( int i = 0; i < this.width * this.height; i++ ) {
152-
System.out.print ( this.screen [ i ] );
175+
String brailleMap = this.screen [ i ].toString ();
176+
byte [] buffer = brailleMap.getBytes ();
177+
stream.write ( buffer );
153178
if ( i % this.width == this.width - 1 ) {
154-
System.out.println ("");
179+
stream.write ( "\n".toString ().getBytes () );
155180
}
156181
}
182+
return stream;
157183
}
158184

159-
}
185+
}

src/main/java/io/raffi/drawille/DrawilleException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This class inherits from the RuntimeException class. It is meant to be thrown whenever an out of
55
* range value is passed to the Canvas and BrailleMap class. The message is statically defined in
66
* this class and the caller only has to pass in the out of bounds (x,y) value pairs.
7-
* @version 1.0.1
7+
* @version 1.0.2
88
* @package io.raffi.drawille
99
* @author Rafael Grigorian <[email protected]>
1010
* @copyright 2018 Rafael Grigorian — All Rights Reserved

src/main/java/io/raffi/drawille/Turtle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This class inherits from the Canvas class and it tries to implement turtle graphics. The methods
55
* in this class can be abstracted with an idea of a pen and paper. One can move the pen in three
66
* axis and based on the z axis, when the pen moves it either draws on the paper or not.
7-
* @version 1.0.1
7+
* @version 1.0.2
88
* @package io.raffi.drawille
99
* @author Rafael Grigorian <[email protected]>
1010
* @copyright 2018 Rafael Grigorian — All Rights Reserved

src/test/java/io/raffi/drawille/CanvasTest.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.raffi.drawille;
22

33
import java.io.ByteArrayOutputStream;
4-
import java.io.PrintStream;
54
import junit.framework.Test;
65
import junit.framework.TestCase;
76
import junit.framework.TestSuite;
@@ -126,4 +125,18 @@ public void testClearWorks () {
126125
assertFalse ( canvas.get ( 1, 2 ) );
127126
}
128127

129-
}
128+
public void testRenderOverload () {
129+
try {
130+
ByteArrayOutputStream output = new ByteArrayOutputStream ();
131+
Canvas canvas = new Canvas ( 1, 2 );
132+
canvas.set ( 1, 1 );
133+
canvas.set ( 1, 2 );
134+
String result = canvas.render ( output ).toString ().replace ( "\n", "" );
135+
assertTrue ( result.equals ("\u2830\u2800") );
136+
}
137+
catch ( Exception e ) {
138+
assertTrue ( false );
139+
}
140+
}
141+
142+
}

0 commit comments

Comments
 (0)