From 8171d7445f0f9af0bf266fb972fbb03a16406866 Mon Sep 17 00:00:00 2001 From: marcus13345 Date: Mon, 29 Sep 2014 16:51:46 -0400 Subject: [PATCH] first --- .idea/.name | 1 + .idea/compiler.xml | 23 ++ .idea/copyright/profiles_settings.xml | 3 + .idea/encodings.xml | 5 + .idea/misc.xml | 26 ++ .idea/modules.xml | 9 + .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 7 + .idea/workspace.xml | 335 ++++++++++++++++++++++++++ StarGen.iml | 12 + src/Main.java | 127 ++++++++++ src/Variable.java | 136 +++++++++++ src/VariableNotFoundException.java | 8 + 13 files changed, 697 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 StarGen.iml create mode 100644 src/Main.java create mode 100644 src/Variable.java create mode 100644 src/VariableNotFoundException.java diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a0c6b26 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +StarGen \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6766b47 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + 1.7 + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4fe57c2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..2e81338 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,335 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + 1411434724817 + 1411434724817 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StarGen.iml b/StarGen.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/StarGen.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..215be11 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,127 @@ +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.Random; + +import javax.imageio.ImageIO; + +public class Main { + private static Variable nameVar = new Variable("", "name", "0", false); + private static int stars = 100; + + public static void main(String[] args) { + try { + while (true) { + String name = "" + Integer.parseInt(nameVar.getValue()); + nameVar.setValue("" + (Integer.parseInt(nameVar.getValue()) + 1)); + + Random rand = new Random(); + BufferedImage image = new BufferedImage(1024, 600, 3); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + + + for (int y = 0; y < 600; y++) + for (int x = 0; x < 1024; x++) { + + int k = rand.nextInt(10); + int r = 0 + k; + int g = 0 + k; + int b = 0 + k; + graphics.setColor(new Color(r, g, b)); + graphics.fillRect(x, y, 1, 1); + } + + // int stars = 1; + for (int i = 0; i < stars; i++) { + int size = (int) Math.pow(2, rand.nextInt(4) + 3) + 1; + double x = rand.nextInt(1024 - size); + double y = rand.nextInt(600 - size); + int r = (rand.nextInt(4) * 10) + 10; + int g = (rand.nextInt(4) * 10) + 10; + int b = (rand.nextInt(4) * 10) + 10; + graphics.drawImage(getScaledImage(getStar(r, g, b), size, size), (int) x, (int) y, null); + if (size == 65 && rand.nextBoolean() && rand.nextBoolean() && rand.nextBoolean()) { + + x += 32; + y += 32; + + double angle = rand.nextDouble() * 360; + double modifier = 5 + (rand.nextDouble() * 16); + + // UIFM UNIDENTIFIABLE FLYING MATH + + x += Math.sin(angle) * modifier; + y += Math.cos(angle) * modifier; + + size = (int) Math.pow(2, rand.nextInt(2) + 3) + 1; + + x -= (size - 1) / 2; + y -= (size - 1) / 2; + + r = (rand.nextInt(6) * 10) + 20; + g = (rand.nextInt(6) * 10) + 20; + b = (rand.nextInt(6) * 10) + 20; + graphics.drawImage(getScaledImage(getStar(r, g, b), size, size), (int) x, (int) y, null); + } + } + System.out.println("Saving..."); + + ImageIO.write(image, "png", new File(name + ".png")); + + System.out.println("Saved!"); + } + } catch (Exception e) { + + } + } + + public static BufferedImage getStar(int r, int g, int b) { + // abs(sqrt(sqrt(abs(3.14x))+sqrt(abs(3.14y)))-2.4) + + BufferedImage image = new BufferedImage(1001, 1001, 3); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + + //lets make a huge image... + for (int y = 0; y < 1001; y++) + for (int x = 0; x < 1001; x++) { + + //lets use variables that dont make sense + double x2 = x - 500; + x2 /= 50; + double y2 = y - 500; + y2 /= 50; + double a = 0 - (Math.sqrt(Math.sqrt(Math.abs(Math.PI * (x2))) + Math.sqrt(Math.abs(Math.PI * (y2)))) - 2.35); + int baseColor = a >= 0 ? 255 : 0; + int opacity = (int) ((a / 6d) * 255); + opacity = opacity >= 255 ? 255 : opacity <= 0 ? 0 : opacity; + graphics.setColor(new Color(baseColor == 255 ? baseColor - r : 0, baseColor == 255 ? baseColor - g : 0, baseColor == 255 ? baseColor - b : 0, opacity)); + graphics.fillRect(x, y, 1, 1); + //whatever, this works. + } + + try { + //scale that shit down. + image = getScaledImage(image, 129, 129); + } catch (IOException e) { + e.printStackTrace(); + } + + return image; + + } + + public static final BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException { + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + double scaleX = (double) width / imageWidth; + double scaleY = (double) height / imageHeight; + AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); + AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); + return bilinearScaleOp.filter(image, new BufferedImage(width, height, image.getType())); + } + +} diff --git a/src/Variable.java b/src/Variable.java new file mode 100644 index 0000000..3c99d6c --- /dev/null +++ b/src/Variable.java @@ -0,0 +1,136 @@ + + +import java.io.File; +import java.io.IOException; +import java.util.Formatter; +import java.util.Scanner; + +/** + * to note, will not work on Mac yet. + * edit: WILL WORK ON MAC MOTHER FUCKERS + * + * + * @author Marcus + * + */ +public class Variable { + private String value; + private String filePath; + private String fileDir; + private static String fileExtension; + + static { + // first the default value is set. this is used + // only to get the real value. + fileExtension = "var"; + // make a new variable, for the extension + // do not force it to be var. + Variable var = new Variable("" + System.getenv("APPDATA") + "\\MAndApps\\core\\", "extension", "var", false); + // grab its value and reset the extension. + fileExtension = var.getValue(); + } + + /** + * dir - where the variable file is stored. - should be formatted like this: + * - "C:/folder/folder/" - or on mac, - "~/folder/folder/" + * + * name - simple, name of variable file + * + * value - value to try and set the file to. though if it already has a + * value, it won't do anything + * + * force - if true, value will always be set to the value given, regardless + * of if the value is already there. + * + * @param dir + * @param name + * @param value + * @param force + */ + + public Variable(String dir, String name, String value, boolean force) { + // first lets get the full path. + if (dir.startsWith("~/")) { //TODO FIX THIS LATER + dir = dir.substring(1); + } else { + dir = dir.replace('/', '\\'); + } + // dir should now be fixed... i guess. + + fileDir = dir; + filePath = dir + name + "." + fileExtension; + // try and load value from file, if null, screw it. + + String str = getValueFromFile(); + + // if we could not load a value from the file + // AKA didnt fucking exist. + // ORRRRRRR if you were an ass, and forced + // the value. + if (str == null) { + this.value = value; + saveValue(); + } else if(force) { + this.value = value; + saveValue(); + } else { + this.value = str; + } + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + saveValue(); + } + + private void saveValue() { + deleteFile(); + createFile(); + try { + // Q&D write value to current filepath. + Formatter f = new Formatter(filePath); + f.format("" + value); + f.close(); + } catch (Exception e) { + // if(weArriveHere){ + // we.are("fucked"); + // } + e.printStackTrace(); + } + } + + private void deleteFile() { + File f = new File(filePath); + f.delete(); + } + + private void createFile() { + File f = new File(fileDir); + f.mkdirs(); + f = new File(filePath); + try { + f.createNewFile(); + } catch (IOException e) { + // if(weArriveHere){ + // we.are("fucked"); + // } + e.printStackTrace(); + } + } + + private String getValueFromFile() { + try { + File f = new File(filePath); + Scanner s = new Scanner(f); + String str = s.nextLine(); + s.close(); + return str; + } catch (Exception e) { + return null; + } + } +} diff --git a/src/VariableNotFoundException.java b/src/VariableNotFoundException.java new file mode 100644 index 0000000..20dade6 --- /dev/null +++ b/src/VariableNotFoundException.java @@ -0,0 +1,8 @@ + + +public class VariableNotFoundException extends Exception { + @Override + public String getMessage() { + return "Variable not found"; + } +}