BlinkenArea - GitList
Repositories
Blog
Wiki
JEtherPix
Code
Commits
Branches
Tags
Search
Tree:
5b2f5f7
Branches
Tags
master
JEtherPix
org
blinkenarea
JFlexiPix
examples
Fade.java
change email address in file headers
Stefan Schuermans
commited
5b2f5f7
at 2011-09-11 12:35:49
Fade.java
Blame
History
Raw
/* JFlexiPix - Java implementation of FlexiPix output library * * Copyright 2010-2011 Stefan Schuermans <stefan schuermans info> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.blinkenarea.JFlexiPix.examples; import org.blinkenarea.JFlexiPix.*; public class Fade { // entry point public static void main(String [] args) { String config; Display display; int width, height, i, x, y; byte [] image; // check usage if (args.length < 1) { System.out.println("usage: java Fade <config.flp>"); return; } config = args[0]; /* create a display, take configuration from a file, deliver messages to message method of new Msg object */ try { display = new Display(config, new Msg()); } catch (Exception e) { System.out.println("could not create display\n"); e.printStackTrace(); return; } // get size and show it width = display.getWidth(); height = display.getHeight(); System.out.println("display size:"); System.out.println(String.format(" width: %5d", width )); System.out.println(String.format(" height: %5d", height)); /* create an image with a nice fade: black to red from left to right, black to green from top to bottom */ image = new byte [height * width * 3]; i = 0; for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { image[i++] = (byte)(255.0*x/(width -1)+0.5); // red image[i++] = (byte)(255.0*y/(height-1)+0.5); // green image[i++] = (byte)0; // no blue } } // output image display.data(image, 3, // consecutive pixels are 3 bytes apart width * 3, // consecutive lines are width * 3 bytes apart 0, // top-left pixel is at array index 0 0, 0, // top-left pixel is 0,0 width, height); // image size is width,height display.send(); // free display display = null; } }