Last active
April 13, 2020 16:51
-
-
Save LeftistTachyon/39b25e3fab7453885ca4964502ce5324 to your computer and use it in GitHub Desktop.
A quick little Java program that can write a JavaScript program that draws a thing inside a canvas so you can use it as a pfp on an obscure website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package package3; | |
import java.awt.Color; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import javax.imageio.ImageIO; | |
/** | |
* A quick little script that converts an image to a slew of JavaScript that | |
* draws a pfp in DSi Paint.<br> | |
* This code needs the following script to be run before it to function:<br> | |
* <pre>function setColor(r,g,b) { | |
* context.strokeStyle = 'rgb('+r+','+g+','+b+')'; | |
* context.fillStyle = 'rgb('+r+','+g+','+b+')'; | |
* statusdiv.innerHTML = 'Color set to ('+r+','+g+','+b+')'; | |
* colordiv.style.background = 'rgb('+r+','+g+','+b+')'; | |
* }</pre><br> | |
* Once the code is outputted, type the above function and then copy/paste | |
* the given code in the output file and run it. It should paint a new profile | |
* picture in the DSi Paint application, which you can then save as a picture | |
* for later use as a pfp. | |
* | |
* @author GuiedGui | |
*/ | |
public class NewMain3 { | |
/** | |
* The main method that runs the code. | |
* | |
* @param args the command line arguments. Shouldn't matter | |
* @throws IOException if the image path doesn't exist or could not be read | |
* or the file could not be written to or if something just goes wrong with | |
* the file system. | |
*/ | |
public static void main(String[] args) throws IOException { | |
// change this string if you want to edit a different image | |
// in this case, this program reads from "breaker.png" in the base directory | |
String filePath = "breaker.png"; | |
BufferedImage image = ImageIO.read(new File(filePath)); | |
// the PrintWriter is automatically directed to output to "js.txt" in | |
// the base project directory. | |
try (PrintWriter out = new PrintWriter(new File("js.txt"))) { | |
// need for speed | |
int height = image.getHeight(), width = image.getWidth(); | |
// iterating through each row | |
for (int y = 0; y < height; y++) { | |
int prevX = 0; | |
Color prev = new Color(image.getRGB(0, y)); | |
// iterating through row | |
for (int x = 1; x < width; x++) { | |
Color curr = new Color(image.getRGB(x, y)); | |
System.out.println(x + ", " + y); | |
// System.out.println("color @ (" + x + ", " + y + "): " + curr); | |
if (curr.equals(prev)) { | |
// Same color; postponing command | |
} else { | |
// Different color; draw previous | |
out.println("setColor(" + prev.getRed() + "," | |
+ prev.getGreen() + "," + prev.getBlue() + ");"); | |
out.println("context.fillRect(" + prevX + "," + y | |
+ "," + (x - prevX) + ",1);"); | |
// update things | |
prev = curr; | |
prevX = x; | |
} | |
} | |
// draw last pixel in row | |
out.println("setColor(" + prev.getRed() + "," | |
+ prev.getGreen() + "," + prev.getBlue() + ");"); | |
out.println("context.fillRect(" + prevX + "," + y | |
+ "," + (width - prevX) + ",1);"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment