Monday, September 6, 2010

Zig Zag painting Java program

Have you ever wondered how you started to paint of fill a block with cryon. It was in manner pictured here
http://en.wikipedia.org/wiki/File:JPEG_ZigZag.svg
What a initution this is the manner that is used in JPEG compression encoding algorithm.
Figuring out to pattern for programming. You can't best is to store all the 64 values in an array.
like structure.
Following program can be handy

public class ZigZag {
    public static int ZAG[] = {
             0,   1,   8, 16,   9,   2,  3,  10,
            17, 24, 32, 25, 18, 11,  4,   5,
            12, 19, 26, 33, 40, 48, 41, 34,
            27, 20, 13,  6,  7, 14, 21, 28,
            35, 42, 49, 56, 57, 50, 43, 36,
            29, 22, 15, 23, 30, 37, 44, 51,
            58, 59, 52, 45, 38, 31, 39, 46,
            53, 60, 61, 54, 47, 55, 62, 63
        };
   
   
    public static void main(String[] args) {
        for (int i=0 ; i< 64 ; i++)
        {
          // Matrix values  (Row , Column
          System.out.println(ZAG[i] +"= ("+ ZAG[i]/8 +","+ZAG[i]%8+")" );
             
        }   
    }

Such techniques can be extended into circular concentric spiral approximation.
Similar pages http://java.about.com/od/beginnerlevel/a/doublyevenmagic_2.htm

No comments:

Followers