Segue o projeto do royboy utilizando Arduino para simular este mesmo efeito. Bom salientar que o projeto utiliza somente uma fonte de iluminação e o Ambilight ao que me parece tem duas fontes de iluminação, uma em cada lado da tela. Eu gostei do projeto e acabei adaptando em Java para utilizar as duas laterais da tela. Como eu não tenho nada de LEDs RGB ao alcance para testes, vou disponibilizar o código e quem tiver interesse em utilizá-lo pode ficar a vontade. Deixa nos comentários um link pro seu projeto que eu referencio ele aqui. Segue o projeto e o código.
Código Java:
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main extends JFrame {
private static final int WIDTH = 1440;
private static final int HEIGHT = 900;
public Main() {
setSize(100, 100);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setAlwaysOnTop(true);
setLayout(new BorderLayout());
JPanel leftPanel = new JPanel();
leftPanel.setSize(getWidth() / 2, getHeight());
add(leftPanel, BorderLayout.WEST);
JPanel rightPanel = new JPanel();
rightPanel.setSize(getWidth() / 2, getHeight());
add(rightPanel, BorderLayout.EAST);
Robot robby = null; // creates object "robby" of robot class
try { //standard Robot class error check
robby = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
int pixel; //ARGB variable with 32 int bytes where
// sets of 8 bytes are: Alpha, Red, Green, Blue
float red = 0;
float green = 0;
float blue = 0;
BufferedImage screenshot = null;
while (true) {
// get screenshot into object "screenshot" of class BufferedImage
screenshot = robby.createScreenCapture(new Rectangle(new Dimension(WIDTH, HEIGHT)));
// 1368*928 is the screen resolution
int i = 0;
int j = 0;
// 1368 * 928
// I skip every alternate pixel making my program 4 times faster
for (i = 0; i < (WIDTH / 2) ; i = i + 2) {
for (j = 0; j < HEIGHT; j = j + 2) {
pixel = screenshot.getRGB(i, j); // the ARGB integer has the colors of pixel (i, j)
red = red + (int) (255 & (pixel >> 16)); // add up reds
green = green + (int) (255 & (pixel >> 8)); // add up greens
blue = blue + (int) (255 & (pixel)); // add up blues
}
}
red = red / ((WIDTH / 4) * (HEIGHT / 2)); // average red (remember that I skipped ever alternate pixel)
green = green / ((WIDTH / 4) * (HEIGHT / 2)); // average green
blue = blue / ((WIDTH / 4) * (HEIGHT / 2)); // average blue
//System.out.println("red: " + red + "\t green: " + green + " \t blue: " + blue);
leftPanel.setBackground(new Color(Math.round(red), Math.round(green), Math.round(blue)));
// RIGHT SIDE
for (i = (WIDTH / 2); i < WIDTH; i = i + 2) {
for (j = 0; j < HEIGHT; j = j + 2) {
pixel = screenshot.getRGB(i, j); // the ARGB integer has the colors of pixel (i, j)
red = red + (int) (255 & (pixel >> 16)); // add up reds
green = green + (int) (255 & (pixel >> 8)); // add up greens
blue = blue + (int) (255 & (pixel)); // add up blues
}
}
red = red / ((WIDTH / 4) * (HEIGHT / 2)); // average red (remember that I skipped ever alternate pixel)
green = green / ((WIDTH / 4) * (HEIGHT / 2)); // average green
blue = blue / ((WIDTH / 4) * (HEIGHT / 2)); // average blue
//System.out.println("red: " + red + "\t green: " + green + " \t blue: " + blue);
rightPanel.setBackground(new Color(Math.round(red), Math.round(green), Math.round(blue)));
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new Main();
}
}
Resultado:
Ambilight - Java version |
[Página do projeto via Hack A Day]
2 comments:
Buenas tardes he probado tu codigo en el programa processing pero me marca error y lo mio no es el software
It's Java not Processing.
Postar um comentário