The Source for Java Technology Collaboration
User: Password:



Kirill Grouchnikov's Blog

June 2006 Archives


Tetris Easter egg for Swing applications

Posted by kirillcool on June 30, 2006 at 10:51 AM | Permalink | Comments (2)

The Matrix rain project that was refactored to the laf-widget layer was not the first one. Even before that i took my first (ever) game written in Java and ported it to a (kind of) Easter egg for Swing apps. The project itself is called trellis and contains a collection Tetris-like games with pluggable shapes and rules. Currently, there are three different kinds of games and four different kinds of shapes. My personal would be the tetris on hexagonal grid, but it takes quite some time to get used to.

As with the previous entry, here is the WebStart link. You'll have to either save it to your machine or run javaws http://weblogs.java.net/blog/kirillcool/archive/trellis/trellis.jnlp from the command prompt. When you hit Ctrl+Alt+T, you will see the following (quite ugly, since this was written back in 2001) selector screen:

choose.png

Choose the game kind and the tile kind and click "Start the game". Based on your choice, you will have one of the 12 available games, such as the regular lines with square tiles:

square-lines.png

A more exotic tetris on hexagonal grid:

hexa-tetris.png

Or even the esoteric piles with Mitsubishi grid:

mitsu-pile.png

The controls are:
  • Left arrow to move left
  • Right arrow to move right
  • r to rotate shape
  • Up arrow to rotate colors (not relevant for Tetris)
  • Down arrow to rotate colors (not relevant for Tetris)
  • Space to drop shape (depends on the game kind)


Matrix screensaver for Swing apps - WebStart

Posted by kirillcool on June 28, 2006 at 12:03 PM | Permalink | Comments (11)

So, a number of people have asked for a WebStart version for the Matrix screensaver, so here goes:



Wait for the application to load, hit Ctrl+Alt+M and enjoy the animation. Mouse click stops the screensaver and returns the control to the frame.



Matrix screensaver for Swing apps

Posted by kirillcool on June 22, 2006 at 09:05 AM | Permalink | Comments (5)

The last thing i did before moving to the States was taking one of my old apps (written for Java 1.1, so the entire imaging stack was written from the ground up, including the alpha channel blending, antialiased line drawing, index color models and such) and turning it into a Swing screensaver. The project page is right here, and once you run your application under laf-widget compliant look and feel, simply place matrix-rain.jar in the classpath and press Ctrl+Alt+M in your frame. Here are a few screenshots of the screensaver in progress:



If you decide to use the screensaver in your app, you may need to specify the heap size to be 256 or 378 megs, since some of the stuff is precomputed for smoother animation framerate. Last thing - this was written back in 2000-2003, so don't view the code as the correct way to use Java2D (since it doesn't use any).

Liven up your app with fractal flames

Posted by kirillcool on June 21, 2006 at 04:20 PM | Permalink | Comments (1)

The latest addition to one of the Substance plugins (watermark pack) provides a playground to experiment with fractal-based artwork. Much like the noise-based watermarks, you can play with the API to create your own (and sometimes stunningly beautiful) watermarks.

The code is loosely based on the ideas from the flam3 site (see this PDF for some math). Feel free to explore some of the code right here. Here are some examples of the fractal flame watermarks along with the source code (the parameters are highly random chosen to create some interesting images. The first parameter is the degree of symmetry).

The first image is that of kaleidoscope and is obtained by the following code (note the degree of symmetry is 4):
public class Kaleidoscope extends IteratedFunctionSystem {
   public Kaleidoscope() {
      super(4, new Functions.SphericalFunction(0.365654, 0.18286, 0.23786324,
            0.234234, -0.4123234, 0.312123),
            new Functions.ExFunction(0.234234, 0.987234, 0.23786324,
                  0.5345456, -0.98456465, 0.312123),
            new Functions.SphericalFunction(0.88745, -0.8934734, -0.546312,
                  0.7896, -0.445899, 0.132468));
   }
}


The second one is vortex and is obtained by the following code (no symmetry added):
public class Vortex extends IteratedFunctionSystem {
   public Vortex() {
      super(1, new Functions.HorseShoeFunction(-0.654897, 0.16886, -0.32645,
            0.0598, 0.952376, -0.231534),
            new Functions.HorseShoeFunction(0.31378, 0.451321, -0.234235,
                  -0.321534, -0.12436, -0.761234));
   }
}


The third one is singularity and is obtained by the following code (degree of symmetry 2):
package org.jvnet.substance.watermarkpack.flamefractal;
public class Singularity extends IteratedFunctionSystem {
   public Singularity() {
      super(2, new Functions.SphericalFunction(0.365654, 0.987234, 0.23786324,
            0.234234, -0.4123234, 0.312123),
            new Functions.SphericalFunction(0.67656, 0.8934734, -0.546312,
                  -0.7896, -0.65487, 0.132468));
   }
}


The last one is scriptures (my favourite - just trace all the repetitive nested marks) and is obtained by the following code (no symmetry added):
public class Scriptures extends IteratedFunctionSystem {
   public Scriptures() {
      super(1, new Functions.HorseShoeFunction(-0.654897, 0.16886, -0.32645,
            0.0598, 0.452376, -0.231534),
            new Functions.HorseShoeFunction(0.31378, 0.451321, -0.234235,
                  -0.321534, -0.12436, -0.761234));
   }
}




Spicing up your JTabbedPane - part V

Posted by kirillcool on June 20, 2006 at 01:36 PM | Permalink | Comments (12)

This is the fifth part of the series that describes the additional capabilities that you can get on your tabbed panes.
  • The first part described close buttons and animation on modified tabs
  • The second part described vetoable close buttons and vertical tabs.
  • The third part described single-click close of multiple tabs and custom alignment of tab texts on left and right placement.
  • The fourth part described hover preview popup and tab overview dialog.
This entry describes the new feature available in the next version of Substance look-and-feel (code-named Grenada) and any other third-party LAF using laf-widget layer.

First, you're welcome to read this blog entry that introduces the notion of widget into the world of look-and-feels. While Substance LAF is currently the only LAF supporting the "feel" widgets, the approach has been successfuly tested on six other third-party LAFs (Squareness, Pagosoft, Looks, Liquid, Infonode and Napkin. While the previous four parts described Substance-specific features, the introduction of laf-widget now allows additional third-party LAFs to provide tab overview dialog and tab hover preview.

The new addition to laf-widget layer provides the functionality of Ctrl Tab Firefox plugin. Once you install that plugin, pressing Ctrl+Tab opens three windows, one in the middle that shows a large thumbnail of a tab (starts from the current tab), and two side windows displaying small thumbnails of previous and next tabs. Each press on Tab key (while Ctrl is pressed) moves the thumbnails forward (cycling). Once Ctrl is released, the currently shown tab (in the middle thumbnail window) is selected.

For those of you who don't know, Swing already provides keyboard accelerators for switching the tabs. These are Ctrl+Page Up for moving forward and Ctrl+Page Down for moving backward. Two major disadvantages are:
  • The selection actually changes (which may trigger some application event handlers - may be undesirable if the user just wants to see the tab preview).
  • It only works in the current tab run.
The newly added (quite small ~10K) widget in laf-widget project (and subsequently in the new version of Substance) provides the Ctrl+Right Arrow and Ctrl+Left Arrow keyboard shortcuts that provide thumbnail paging of all tabs in the currently focused tabbed pane (Ctrl+Tab can not be taken since Tab event is already consumed by Swing for the focus transfer). Here is a screenshot to illustrate (click to see the full size):





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds