Skip to content

Commit

Permalink
Update md, tweaks, and Image
Browse files Browse the repository at this point in the history
  • Loading branch information
aspiringLich committed May 23, 2023
1 parent 9e3bcee commit 6d1bac4
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 57 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@

# PaintingCanvas

## Todo

I would like to redo the drawable system a little bit - adding support for textures and gradient fills.
In addition, adding interfaces like `Colorable`, `Resizable`, `Rotatable`, etc. to avoid useless methods would be nice.
Also - anchors would be cool.

## What is this?

This is a complete overhaul to the old graphics library used in our AP comp science class. It adds more shapes, more features, a *much* more robust and capable animation system, and more!

This is a complete overhaul to the old graphics library used in our AP comp science class. It adds more shapes, more
features, a *much* more robust and capable animation system, and more!

## Features

The default font is comic sans (important feature) (you're welcome).

This is a relatively capable library, and it has most of the features you would expect out of a canvas. You can draw shapes, rotate them, and move them around. If you would like a more complete overview of what this library is capable of, check out the [javadoc](https://aspiringlich.github.io/PaintingCanvas/paintingcanvas/package-summary.html).
This is a relatively capable library, and it has most of the features you would expect out of a canvas. You can draw
shapes, rotate them, and move them around. If you would like a more complete overview of what this library is capable
of, check out the [javadoc].

## Simplicity First!

This library is designed to be as simple as possible, while still being somewhat robust. It's made to be simple enough for absolute beginners to use, but powerful and extensible enough to satisfy all the biggest nerds out there.
This library is designed to be as simple as possible, while still being somewhat robust. It's made to be simple enough
for absolute beginners to use, but powerful and extensible enough to satisfy all the biggest nerds out there.

So don't complain about how the rendering runs completely asynchronously from the main thread.

## Examples

You can find various examples in `src/test/java/examples/`. These are all runnable, and they should give you a good idea of how to use the library, and give good *examples* (haha get it) of the library's capabilities.
You can find various examples in `src/test/java/examples/`. These are all runnable, and they should give you a good idea
of how to use the library, and give good *examples* (haha get it) of the library's capabilities.

### Animation Test

Expand All @@ -28,3 +38,5 @@ https://user-images.githubusercontent.com/48413902/223738287-396ffca5-8bcd-48a8-
### Easing Demo

https://user-images.githubusercontent.com/48413902/224180302-c79f398b-5772-42b3-9aa5-6139518b5d22.mp4

[javadoc]: https://aspiringlich.github.io/PaintingCanvas/paintingcanvas/package-summary.html
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

// what should the group-id be breon
group 'paintingcanvas'
version '1.4.1'
version '1.4.2'

repositories {}
dependencies {}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/paintingcanvas/drawable/Drawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public T removeOutline() {
* @param g Graphics context
* @return The object's center-point
*/
public abstract Point center(Graphics g);
public Point center(Graphics g) {
return new Point(this.x, this.y);
}

/**
* Actually render the object itself
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/paintingcanvas/drawable/Ellipse.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ protected void drawFilled(Graphics2D gc) {
gc.fillOval(x - width / 2, y - height / 2, width, height);
}

@Override
public Point center(Graphics g) {
return new Point(x, y);
}

@Override
protected Ellipse getThis() {
return this;
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/paintingcanvas/drawable/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package paintingcanvas.drawable;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
* <p>
* Draws an image from the specified path.
* </p>
* <p>
* {@code setColor} and {@code getColor} don't do anything for this drawable as
* it is not a traditional solid color shape
* </p>
*
* <pre>{@code
* // get the working directory of the program / where it is looking for your image
* System.out.println(System.getProperty("user.dir"));
* // create a new image object
* Image img = new Image(100, 100, "path/to/image.png");
* }</pre>
*/
public class Image extends Drawable<Image> {
BufferedImage image;
int width, height;

/**
* Create a new Image element.
* @param x The X-position of the image
* @param y The Y-position of the image
* @param src The path to the image file
*/
public Image(int x, int y, String src) {
super(x, y, Color.BLACK);
try {
image = ImageIO.read(new File(src));
} catch (IOException e) {
throw new RuntimeException(e);
}

width = image.getWidth();
height = image.getHeight();
}

/**
* Set the scale of the image to the specified multiplier.
*
* <pre>{@code
* Image img = new Image(0, 0, "image.png");
* img.setScale(2.0, 1.0); // the image is now stretched in the x direction
* }</pre>
* @param x The multiplier to scale x by
* @param y The multiplier to scale y by
* @return The original object to allow method chaining
*/
public Image setScale(double x, double y) {
this.width = (int)(image.getWidth() * x);
this.height = (int)(image.getHeight() * y);
return this;
}

@Override
protected void drawFilled(Graphics2D gc) {
gc.drawImage(image, x - width / 2, y - height / 2, width, height, null);
}

@Override
protected void drawOutline(Graphics2D gc) {
gc.drawRect(x - width / 2, y - height / 2, width, height);
}

@Override
protected Image getThis() {
return this;
}
}
5 changes: 0 additions & 5 deletions src/main/java/paintingcanvas/drawable/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ protected void drawFilled(Graphics2D gc) {
gc.fillRect(x - width / 2, y - height / 2, width, height);
}

@Override
public Point center(Graphics g) {
return new Point(x, y);
}

@Override
protected Rectangle getThis() {
return this;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/paintingcanvas/drawable/Square.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ protected void drawOutline(Graphics2D gc) {
gc.drawRect(x - size / 2, y - size / 2, size, size);
}

@Override
public Point center(Graphics g) {
return new Point(x, y);
}

@Override
public Square getThis() {
return this;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/paintingcanvas/drawable/Triangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ protected void drawOutline(Graphics2D gc) {
gc.drawPolygon(this.getPolygon());
}

@Override
public Point center(Graphics g) {
return new Point(x, y);
}

@Override
protected Triangle getThis() {
return this;
Expand Down
29 changes: 8 additions & 21 deletions src/test/java/examples/Test.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package examples;

import paintingcanvas.canvas.Canvas;
import paintingcanvas.drawable.Image;
import paintingcanvas.drawable.Line;
import paintingcanvas.drawable.Polygon;
import paintingcanvas.extensions.FrameCounter;
import paintingcanvas.extensions.InfoDisplay;

import java.awt.*;
import java.awt.Color;


@SuppressWarnings("unused")
public class Test {
Expand All @@ -16,26 +18,11 @@ static Color randomColor() {

public static void main(String[] args) {
Canvas canvas = new Canvas();
new FrameCounter().line(
() -> String.format("Animations: %d", canvas.animations.size())
).attach();
new InfoDisplay().attach();

Line l = new Line(0, 0, 100, 100, Color.RED).setColor(Color.blue);
Polygon[] shapes = new Polygon[10];
for (int i = 0; i < shapes.length; i++) {
shapes[i] = new Polygon(0, 200, randomColor());
for (int j = 0; j < 5; j++) {
int x = (int) (Math.random() * 200);
int y = (int) (Math.random() * 200);
shapes[i].point(x, y);
}
}
while (true) {
for (int i = 0; i < 20; i++) {
for (Polygon c : shapes) c.move(10, 0);
for (Polygon c : shapes) c.move(-10, 0);
}
}
String dir = System.getProperty("user.dir");
Image image = new Image(0, 0, "src/test/java/examples/flop.jpg")
.rotate(90);

while(true) {}
}
}
Binary file added src/test/java/examples/flop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions todo.md

This file was deleted.

0 comments on commit 6d1bac4

Please sign in to comment.