Skip to content

Instantly share code, notes, and snippets.

@hyobyun
Created June 2, 2013 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyobyun/5695034 to your computer and use it in GitHub Desktop.
Save hyobyun/5695034 to your computer and use it in GitHub Desktop.
Turns a 25x25 gif single frame image into arduino code for a 25x25 led matrix
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.lang.*;
public class Convert {
public static void main(String[] args) {
boolean preview = false;
if (args.length >0 && args[0].equals("p")) {
preview=true;
}
BufferedImage image = null;
try {
image = ImageIO.read(new File("gif.gif"));
} catch (IOException e) {
}
for (int i=0; i<25; i++) {
for (int j=0; j<25; j++) {
int c = image.getRGB(j,i);
int red = (c & 0x00ff0000) >> 16;
int green = (c & 0x0000ff00) >> 8;
int blue = c & 0x000000ff;
// and the Java Color is ...
int lum = (int) Math.sqrt( .241*red*red + .691*green*green + .068*blue*blue);
if (lum >200) {
if (preview) {
System.out.print("#");
} else {
System.out.println("displayArea.SetPoint(" + i + ", " + j + ");");
}
} else {
if (preview) {
System.out.print(" ");
}
}
}
if (preview) {
System.out.println();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment