Code Monkey home page Code Monkey logo

graphics's Introduction

Using the Graphics Engine

Add the included jar to your projects workspace. This allows you to use DGraphics and GraphicsInterface. DGraphics handles all graphics directly using Java's built in Graphics2D. It creates a fullscreen window with a 16:9 aspect ratio and adds black bars accordingly. All objects are rendered on a 1920x1080 surface and then scaled to your monitor's resolution. DGraphics calls the tick() and render() methods in GraphicsInterface at about 60 hertz.

Example

import graphics.DGraphics;
import graphics.GraphicsInterface;

import java.awt.Color;
import java.awt.Graphics2D;

public class GraphicsTest implements GraphicsInterface {
	public static DGraphics g;
	public static int  a = 0;
	public static void main(String[] args) {
		g = new DGraphics(new GraphicsTest());
		
	}

	@Override
	public void render(Graphics2D g2d) {
		g2d.setColor(new Color(0, 0, 0));
		g2d.fillRect(a, a, 20, 20);

	}

	@Override
	public void tick() {
		a++;
		
	}
	
	
}

Multithreading

This graphics library has simple multithreading support. Simply declare a GraphicsInterface inline and put it in an ArrayList<GraphicsInterface> then put that array list in the DGraphics constructor.

Example

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;

import graphics.DGraphics;
import graphics.GraphicsInterface;

public class GraphicsTest {
	public static DGraphics g;
	public static int a = 0;
	public static ArrayList<GraphicsInterface> gis = new ArrayList<GraphicsInterface>();
	public static void main(String[] args) {
		gis.add(new GraphicsInterface() {
			@Override
			public void render(Graphics2D g2d) {
				g2d.setColor(new Color(0, 0, 0));
				g2d.fillRect(a, a, 20, 20);
				
			}

			@Override
			public void tick() {
				a++;
				
			}
			
		});
		
		gis.add(new GraphicsInterface() {
			@Override
			public void render(Graphics2D g2d) {
				g2d.setColor(new Color(255, 0, 0));
				g2d.fillRect(a, 1080 - a, 20, 20);
				
			}

			@Override
			public void tick() {
				a++;
				
			}
			
		});
		
		g = new DGraphics(gis);
		
	}

}

Image Sequence Output

This graphics library supports a png image sequence output. Simply declare a GraphicsInterface inline and put it in an ArrayList<GraphicsInterface> then put that array list in the DGraphics constructor. The next four paramaters of the constructor are the amount of frames to be rendered, the file path (as a string) the frames are to be rendered to, and the width and height of the image.

Example

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;

import graphics.DGraphics;
import graphics.GraphicsInterface;

public class GraphicsTest {
	public static DGraphics g;
	public static int a = 0;
	public static ArrayList<GraphicsInterface> gis = new ArrayList<GraphicsInterface>();
	public static void main(String[] args) {
		gis.add(new GraphicsInterface() {
			@Override
			public void render(Graphics2D g2d) {
				g2d.setColor(new Color(0, 0, 0));
				g2d.fillRect(a, a, 20, 20);
				
			}

			@Override
			public void tick() {
				a++;
				
			}
			
		});
		
		gis.add(new GraphicsInterface() {
			@Override
			public void render(Graphics2D g2d) {
				g2d.setColor(new Color(255, 0, 0));
				g2d.fillRect(a, 1080 - a, 20, 20);
				
			}

			@Override
			public void tick() {
				a++;
				
			}
			
		});
		
		g = new DGraphics(gis, 600, "C:/Users/Dactaxx/frames/", 1920, 1080);
		
	}

}

graphics's People

Contributors

dactaxx avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.