Created
June 2, 2013 21:24
-
-
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
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
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