• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ASCII renderer in pure java with no external dependencies

Java ASCII Render

Maven Central Java CI with Maven Quality Gate Status Lines of Code GitHub

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

Download and Install

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:

Compatibility

Java ASCII Render requires Java 6 (or higher).

Available graphical elements and usage examples

Rectangle

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
		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);

Dot

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚         *        โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ”‚                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
		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);

Line

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  โ”‚
โ”‚ โ—โ—               โ”‚
โ”‚   โ—โ—โ—            โ”‚
โ”‚      โ—โ—โ—         โ”‚
โ”‚         โ—โ—โ—      โ”‚
โ”‚            โ—โ—โ—   โ”‚
โ”‚               โ—โ— โ”‚
โ”‚                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

		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);

Circle

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       ***        โ”‚
โ”‚      *   *       โ”‚
โ”‚     *     *      โ”‚
โ”‚     *     *      โ”‚
โ”‚     *     *      โ”‚
โ”‚      *   *       โ”‚
โ”‚       ***        โ”‚
โ”‚                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
		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);

Ellipse

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     *******      โ”‚
โ”‚   **       **    โ”‚
โ”‚                  โ”‚
โ”‚ *             *  โ”‚
โ”‚                  โ”‚
โ”‚   **       **    โ”‚
โ”‚     *******      โ”‚
โ”‚                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
		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);

Label

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);

Text

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);

PseudoText

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

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

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);

Overlay

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);

PseudoCanvas

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);

Download release

https://github.com/indvd00m/java-ascii-render/releases

Release notes

Version 0.9.0

Version 1.0.0

  • Reworking API. Add new elements.

Version 1.1.0

  • Add PseudoText element.
  • Use Bresenham's algorithm for line drawing.

Version 1.2.0

  • Simplify extending existing elements.

Version 1.2.1

  • Pass axis type to format method in AxisLabels element.

Version 1.2.2

  • Add deploy to maven central.

Version 1.2.3

  • Add url to pom's.

Version 1.2.4

  • Add some useful methods to builder.

Version 1.3.0

  • Add table element.

Version 1.4.0

  • Add overlay element.
  • Added possibility to trim canvas.
  • Simplified extending of existing implementation.

Version 1.5.0

  • Improved canvas draw performance.

Version 2.0.0

  • 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.

Version 2.1.0

  • Added table cells highlighting.

Version 2.1.1

  • Added some useful constructors.

Version 2.1.2

  • Fixed javadoc.

Version 2.1.3

  • Simplified extending of Table element.

Version 2.2.0

  • Added possibility to increase "pixel" resolution.

Roadmap

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.

Issue tracking

The issues for this project are tracked on its github.com page. All bug reports and feature requests are appreciated.

Building and running tests

git clone https://github.com/indvd00m/java-ascii-render.git
cd java-ascii-render
mvn clean install

Contributions

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

License & Author

Java ASCII Render is distributed under Apache License 2.0. For license terms, see LICENSE.

Java ASCII Render is written by David E. Veliev.