aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Matarese <dominicmatarese@gmail.com>2021-10-08 23:53:42 +0000
committerDominic Matarese <dominicmatarese@gmail.com>2021-10-08 23:53:42 +0000
commit7a98f8d9761de8061178ec7bce79bca7cb48aade (patch)
treee3fb2cd6a137b3921a54673ca858cc43bb7e4552
Created git repo, added README.md
-rw-r--r--README.md8
-rw-r--r--randomimages.java75
2 files changed, 83 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..98bc14f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,8 @@
+#Java Random Image Generator
+
+This command line java program generates a specified number of png images at a specified resolution, and populates them with pixels of a random color.
+The images are stored in the same folder as the compiled jar file.
+
+#Usage
+`javac randomImages.java`
+`java -jar randomImages.jar`
diff --git a/randomimages.java b/randomimages.java
new file mode 100644
index 0000000..72baffe
--- /dev/null
+++ b/randomimages.java
@@ -0,0 +1,75 @@
+//generate a specified number of random images and place them in the
+//directory of the source file.
+//It is very unlikely something of meaning will be generated, but
+//this is why the program can generate hundreds of them...
+
+//By Dominic Matarese
+
+import java.awt.*;
+import java.io.*;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.util.Scanner;
+
+public class randomimages{
+ public static void main(String[] args)
+ {
+
+ //int defaultWidth = 720, defaultHeight = 480, defaultNum = 5;
+ int width = 720, height = 480, num = 5;
+
+
+ Scanner reader = new Scanner(System.in); // Reading from System.in
+ System.out.println("How many images do you want to generate?");
+ System.out.println("Enter a number: ");
+ num = reader.nextInt(); // Scans the next token of the input as an int.
+
+ System.out.println("");
+ System.out.println("What will be the resolution of the images? \n(enter both width and height)");
+ System.out.println("Enter width in # of pixels: ");
+ width = reader.nextInt();
+ System.out.println("Enter height in # of pixels: ");
+ height = reader.nextInt();
+ reader.close();
+
+ generateImages(width, height, num);
+
+ if(num == 1) {
+ System.out.println("The image has been generated!");
+ }
+ else {
+ System.out.println(num + "images have been generated!");
+ }
+ return;
+
+ }
+ public static void generateImages(int width, int height, int num)
+ {
+ for(int i = 1; i < num + 1; i++)
+ {
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+
+ //generate random RGB values for each pixel
+ for(int x = 0; x < width; x++) {
+ for(int y = 0; y < height; y++) {
+
+ int r = (int)(Math.random()*256);
+ int g = (int)(Math.random()*256);
+ int b = (int)(Math.random()*256);
+
+ Color color = new Color(r, g, b);
+ image.setRGB(x, y, color.getRGB());
+ }
+ }
+
+ try {
+ File random = new File("Random" + i + ".png");
+ ImageIO.write(image, "png", random);
+ }
+ catch (IOException exception){
+ System.out.println("Error: IOException occured!");
+ return; //prints error if IOException occurs
+ }
+ }
+ }
+}