ASCII renderer in pure java with no external dependencies. Java ASCII Render supports graphical primitives/elements, layers, context, canvas.
EXPERIMENTAL RESULT
Theme: Teleportation of matter through extremely dense elements
Date: 1998-11-19
Time: 08:47
Subject: Gordon Freeman
ββββββββββββββββββββββββββββββββββββββββ Observation of Einstein-Podo
β 1.00βΌ**** *****β lsky-Rosen Entanglement on S
β 0.75βΌ *** *** β upraquantum Structures by In
β 0.50βΌ ** ** β duction Through Nonlinear Tr
β 0.25βΌ ** ** β ansuranic Crystal of Extreme
β 0.00βΌ ** ** β ly Long Wavelength (ELW) Pul
β-0.25βΌ *** *** β se from Mode-Locked Source A
β-0.50βΌ ********* β rray shows a very promising
β-0.75βΌ * β result.
β-1.00βΌββββββββΌββββββββΌββββββββΌββββββββΌβ
β 0 90 180 270 360β *******************
ββββββββββββββββββββββββββββββββββββββββ CONCLUSION: APPROVE
To download and install Java ASCII Render you currently have the following options.
Maven
Add dependency to com.indvd00m.ascii.render:ascii-render
:
<dependency>
<groupId>com.indvd00m.ascii.render</groupId>
<artifactId>ascii-render</artifactId>
<version>2.2.0</version>
</dependency>
Plain-old JAR
Download the following JARs and add them to your classpath:
Java ASCII Render requires Java 6 (or higher).
ββββββββββββββββββββ
β β
β β
β β
β β
β β
β β
β β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
ββββββββββββββββββββ
β β
β β
β β
β β
β * β
β β
β β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
builder.element(new Dot());
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
ββββββββββββββββββββ
β β
β ββ β
β βββ β
β βββ β
β βββ β
β βββ β
β ββ β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
builder.element(new Line(new Point(2, 2), new Point(17, 7)));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
ββββββββββββββββββββ
β *** β
β * * β
β * * β
β * * β
β * * β
β * * β
β *** β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
builder.element(new Circle(9, 4, 3));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
ββββββββββββββββββββ
β ******* β
β ** ** β
β β
β * * β
β β
β ** ** β
β ******* β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
builder.element(new Ellipse(9, 4, 14, 6));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Single-line string.
ββββββββββββββββββββ
β β
β β
β β
βLabel with long tβ¦β
β β
β β
β β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
builder.element(new Label("Label with long text", 1, 4, 18));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Multiline string.
ββββββββββββββββββββ
β β
β β
βLorem Ipsum is simβ
βply dummy text of β
βthe printing and β¦β
β β
β β
β β
ββββββββββββββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(20).height(10);
builder.element(new Rectangle());
builder.element(new Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry.", 1, 3, 18, 3));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Antialising option is customizable, enabled by default.
ββ
βββββββ ββ ββββββββββ ββ
ββ βββββ ββ ββ ββ
ββ βββ ββ ββ ββ
ββ βββ ββββββββ ββββββ ββ ββ βββββββ ββββββ ββ ββββββ ββββββββ βββββββ
ββ βββ ββββββββ ββββββββ ββ ββ ββββββββ ββββββββ ββ ββββββββ ββββββββ ββ
ββ βββββ ββββ βββ βββ ββ ββ βββ βββ βββ βββ ββ βββ βββ ββββββ ββ
βββββββ βββββββ βββ βββ ββ ββ βββ βββ βββ βββ ββ βββ βββ ββββ ββ
ββ ββββββββ ββββββββ ββ ββ βββ βββ βββ βββ ββ ββββββββ ββββ ββ
ββ βββββ βββ βββ βββ βββ βββ βββ βββ ββ βββ ββββ ββ
ββ βββ βββ βββ βββ βββ βββ βββ βββ ββ βββ ββββββ βββ
ββ ββββββββ ββββββββ ββββββββ ββββββββ ββββββββ ββ ββββββββ ββββββββ ββββ
ββ ββββββββ βββββββ ββββββββ βββββββ ββββββ ββ βββββββ ββββββββ βββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(120).height(20);
builder.element(new PseudoText("PseudoText"));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Plot with axis and labels based on array of points.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3.73βΌ * ** β
β β ** * β
β β * ** β
β β * ** β
β 1.87βΌ ** *** β
β β **** **** β
β β ****** ***** β
β β*** ******* ****β
β-0.00βΌ ***** ****** β
β β **** **** β
β β *** ** β
β β ** * β
β-1.87βΌ ** * β
β β * ** β
β β ** * β
β β * β
β-3.73βΌββββββββββββββββββΌββββββββββββββββββΌββββββββββββββββββΌββββββββββββββββββΌβ
β 0 90 180 270 360β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
List<IPlotPoint> points = new ArrayList<IPlotPoint>();
for (int degree = 0; degree <= 360; degree++) {
if (degree > 75 && degree < 105) {
continue;
}
if (degree > 255 && degree < 285) {
continue;
}
double val = Math.tan(Math.toRadians(degree));
IPlotPoint plotPoint = new PlotPoint(degree, val);
points.add(plotPoint);
}
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(80).height(20);
builder.element(new Rectangle(0, 0, 80, 20));
builder.layer(new Region(1, 1, 78, 18));
builder.element(new Axis(points, new Region(0, 0, 78, 18)));
builder.element(new AxisLabels(points, new Region(0, 0, 78, 18)));
builder.element(new Plot(points, new Region(0, 0, 78, 18)));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Table with rows and columns.
ββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ
β12345678β β β β
ββββββββββΌβββββββββΌβββββββββΌβββββββββ€
β β β β β
βββββββββββββββββββ
ββββββββββββββββββͺ
β β β β1234567β¦β
ββββββββββΊβββββββββΉβββββββββΊβββββββββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(37).height(7);
Table table = new Table(4, 3);
table.setElement(1, 1, new Label("1234567890"));
table.setElement(4, 3, new Text("1234567890"), true);
table.setHighlighted(2, 3, true);
builder.element(table);
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Possibility to combine results of several renders.
ββββββββββββββββββββ
β β
β β
βLoreβββββββββs simβ
βply βOverlayβt of β
βthe βββββββββand β¦β
β β
β β
β β
ββββββββββββββββββββ
IRender render1 = new Render();
IContextBuilder builder1 = render1.newBuilder();
builder1.width(9).height(3);
builder1.element(new Rectangle());
builder1.element(new Text("Overlay", 1, 1, 7, 1));
ICanvas canvas1 = render1.render(builder1.build());
IRender render2 = new Render();
IContextBuilder builder2 = render2.newBuilder();
builder2.width(20).height(10);
builder2.element(new Rectangle());
builder2.element(
new Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry.", 1, 3, 18, 3));
builder2.element(new Overlay(5, 3, canvas1, true));
ICanvas canvas2 = render2.render(builder2.build());
String s = canvas2.getText();
System.out.println(s);
In some cases you can get better results by synthetic increasing of "pixel resolution". This is possible by calling
render.setPseudoCanvas(true)
method. After that render would use βββββββββββββββ
chars for drawing 4 points in 1 char.
This is would work only if you do not use any special symbols for drawing (but you still can use Overlay to combine
two different renders).
Example 1: line in 30x10 resolution:
ββ
βββ
ββββ
βββ
βββ
βββ
βββ
ββββ
βββ
ββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(30).height(10);
builder.element(new Line(new Point(0, 0), new Point(29, 9), 'β'));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
And same line in 60x20 resolution:
βββ
ββββ
ββββ
βββ
βββ
βββ
βββ
ββββ
ββββ
βββ
IRender render = new Render();
render.setPseudoCanvas(true);
IContextBuilder builder = render.newBuilder();
builder.width(60).height(20);
builder.element(new Line(new Point(0, 0), new Point(59, 19)));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
Example 2: pseudo text in 60x10 resolution:
β
βββ β βββββ
β β β β β
β β ββββ ββ β β βββ ββ β ββ β β ββββ
βββ β β β β β β β β β β β β ββ β
β βββ ββββ β β β β β β β ββββ ββ β
β β β β β β β β β β β ββ β
β ββββ βββ ββββ βββ ββ β βββ β β βββ
IRender render = new Render();
IContextBuilder builder = render.newBuilder();
builder.width(60).height(10);
builder.element(new PseudoText("PseudoText", false));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
And same pseudo text in 120x20 resolution:
β
ββββ β βββββ ββ
ββ ββ βββ ββ β β βββ βββ β βββ ββββ ββββ
ββ ββββ β ββββ β β ββββ ββ ββ β ββ ββ ββββ ββ
ββββ βββββ ββββ β β β β ββ ββ β βββββ ββ ββ
ββ ββ β β β β β ββ ββ β ββ ββ ββ
ββ βββββ ββββ ββββ ββββ βββ β ββββ ββββ βββ
IRender render = new Render();
render.setPseudoCanvas(true);
IContextBuilder builder = render.newBuilder();
builder.width(120).height(20);
builder.element(new PseudoText("PseudoText", false));
ICanvas canvas = render.render(builder.build());
String s = canvas.getText();
System.out.println(s);
https://github.com/indvd00m/java-ascii-render/releases
- First release. Project reworked from https://github.com/indvd00m/java-ascii-plotter
- Reworking API. Add new elements.
- Add PseudoText element.
- Use Bresenham's algorithm for line drawing.
- Simplify extending existing elements.
- Pass axis type to format method in AxisLabels element.
- Add deploy to maven central.
- Add url to pom's.
- Add some useful methods to builder.
- Add table element.
- Add overlay element.
- Added possibility to trim canvas.
- Simplified extending of existing implementation.
- Improved canvas draw performance.
- Canvas now is empty by default - contains only \0 and \n symbols. Previous Canvas implementation contained \s and \n symbols. This new changes break backward compatibility for drawing behavior in some cases (but do not break compile time API compatibility). Now overlapping of layers would work correctly when you directly draw spaces \s to layer.
- Added opacity for layers.
- Added table cells highlighting.
- Added some useful constructors.
- Fixed javadoc.
- Simplified extending of Table element.
- Added possibility to increase "pixel" resolution.
This component is developed as a hobby with no public roadmap or any guarantees of upcoming releases. That said, the following features are planned for upcoming releases:
- Fluent API for elements.
The issues for this project are tracked on its github.com page. All bug reports and feature requests are appreciated.
git clone https://github.com/indvd00m/java-ascii-render.git
cd java-ascii-render
mvn clean install
Contributions are welcome, but there are no guarantees that they are accepted as such. Process for contributing is the following:
- Fork this project
- Create an issue to this project about the contribution (bug or feature) if there is no such issue about it already. Try to keep the scope minimal.
- Develop and test the fix or functionality carefully. Only include minimum amount of code needed to fix the issue.
- Refer to the fixed issue in commit
- Send a pull request for the original project
- Comment on the original issue that you have implemented a fix for it
Java ASCII Render is distributed under Apache License 2.0. For license terms, see LICENSE.
Java ASCII Render is written by David E. Veliev.