About

Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

6/14/11

Coding: Pixel ripple effect

Obfuscated C code! This is the inner core loop of a water rippling effect, though I spent some time rearranging the code, because it looked cool for some reason. Do you get what is going on here ? :p
switch    (renderflag)          {
case      0                  :  {
for(int i=1; i < resy-1 ; i  ++ )  {
for(int j=1; j < resx-1 ; j  ++ )  {
    buf1   [ j ]     [ i     ]  =
    ((                          (
    buf2   [ j + 1 ] [ i     ]  +
    buf2   [ j - 1 ] [ i     ]  +
    buf2   [ j ]     [ i - 1 ]  +
    buf2   [ j ]     [ i + 1 ]  )
    >>                     1 )  -
    buf1   [ j ]     [ i     ] );
    buf1   [ j ]     [ i     ] -=
    buf1   [ j ]     [ i     ] >>
    7                           ;
    offsetx                     =
    buf1   [ j ]     [ i     ]  -
    buf1   [ j + 1 ] [ i     ]  ;
    offsety                     =
    buf1   [ j ]     [ i     ]  -
    buf1   [ j ]     [ i + 1 ]  ;
    _putpixel(  water, j , i   ,(
    128      -  offsetx        )&
    255                        );
    offsetx                   >>=
    8        ;  offsety       >>=
    8                           ;
    indexu   =  offsetx  + j    ;
    indexv   =  offsety  + i    ;
    if       (  indexu         >=
    resx     )  indexu         -=
    resx                        ;
    else if  (  indexu   < 0    )
    indexu                     +=
    resx                        ;
    if       (  indexv         >=
    resy     )  indexv         -=
    resy                        ;
    else if  (  indexv   < 0    )
    indexv                     +=
    resy                        ;
    _putpixel(  vscreen  , j    ,
    i                         ,((
    _getpixel(  backdrop        ,
    indexu                      ,
    indexv   )                 <<
    8                          )+
    _getpixel(  water, j , i   ))
    >>                     8   );
    }}}         break           ;
case 1                         :{
for(int i=1; i < resy-1 ; i  ++ )  {
for(int j=1; j < resx-1 ; j  ++ )  {
    buf2   [ j ]     [ i     ]  =
    ((                          (
    buf1   [ j + 1 ] [ i     ]  +
    buf1   [ j - 1 ] [ i     ]  +
    buf1   [ j ]     [ i - 1 ]  +
    buf1   [ j ]     [ i + 1 ]  )
    >>                     1 )  -
    buf2   [ j ]     [ i     ] );
    buf2   [ j ]     [ i     ] -=
    buf2   [ j ]     [ i     ] >>
    7                           ;
    offsetx                     =
    buf2   [ j ]     [ i     ]  -
    buf2   [ j + 1 ] [ i     ]  ;
    offsety                     =
    buf2   [ j ]     [ i     ]  -
    buf2   [ j ]     [ i + 1 ]  ;
    _putpixel(  water, j , i   ,(
    128      -  offsetx        )&
    255                        );
    offsetx                   >>=
    8        ;  offsety       >>=
    8                           ;
    indexu   =  offsetx  + j    ;
    indexv   =  offsety  + i    ;
    if       (  indexu         >=
    resx     )  indexu         -=
    resx                        ;
    else if  (  indexu   < 0    )
    indexu                     +=
    resx                        ;
    if       (  indexv         >=
    resy     )  indexv         -=
    resy                        ;
    else if  (  indexv   < 0    )
    indexv                     +=
    resy                        ;
    _putpixel(  vscreen  , j    ,
    i                         ,((
    _getpixel(  backdrop        ,
    indexu                      ,
    indexv   )                 <<
    8                          )+
    _getpixel(  water, j , i   ))
    >>                     8   );
    }}}         break           ;
    default:    break;          }

2/14/10

Coding: Graftal snowtree

Recursive deterministic graftal algorithm

This nice algorithm that I found in Computer Graphics: Principles & Practice inspired me to implement it. I it will generate a set of data that you can parse to construct a tree-like graphics structure. This algorithm is bases on a alphabet of 6 symbols:

The algorithm shall use those 6 symbols to mutate a starting-axiom into a full tree. These are the two simple rules of this sorta game-of-life:

To initialize the algorithm, you must choose a starting axiom. Following the rules indicates that 'A' is not a good choice, since that will only produce new 'A's. (A->AA). Therefore we choose 'B' wich will tranform into A(B)AA[B] and produce a standard pattern to generate the tree off. This is the produce string after just ONE recursion.

This is the string buffer after two runs. When implementing this algorithm, it is recommended to have overflow-safe stacks and buffers!. Now it is up to you to parse the tree and make the drawing happen. When parsing the tree after generating it, the 6 symbols have the current meaning: A and B(nodes) = continue to draw in current direction; [ and ) means rotate left; ] and ( means rotate right.

Basically you want two char[] buffers so as to render from buffer 1 to buffer 2 and from 2 to 1 in the next iteration. Remember that the buffer is filled up at a exponential rate. (In this picture, snowfall was also simulated). This code of mine implements it. (Never ask me about that code)

Lore: 90's copyparties

(Updated May 17th 2012)

I was introduced to the scene sometime in the late 80's and a friend of mine knew a couple of coders that he introduced me to. They helped me step from BASIC to assembler, and after that I was hooked on coding. On aminet page, you can find some pruductions. The demo 'Response' got 2nd place at TG95. I my self won some animation compo with a funny and brutal stick-figure animation. (made in DeluxePaint II) This anim was called 'Kjell og Bjarne tar kvelden'. This anim actually exists in two versions: the original and an extended version. I don't even own a copy of these anims myself anymore, so I'd appreciate if someone could provide those anims in a PC-viewable format. If you by any chance should have this old IFF anim from the Amiga or more preferably a conversion to a PC format. (But even an MPG will do, like our runner-up in the demo compo in 1995. I made two versions, the first version were realeased on the Razor 1911/IMP 666 party in Arendal, Norway in 1993. I also won a Useless Utility compo with a program that made the user decide wether the monitor was color or b/w. Wow! My first group was the Mad Skull Crew; founded by me and the friend spoken of above. He used to call himself Raven. (RIP, he is now gone from this world) We had C64's with Action Replay and the Final Cartridge. We made some silly demos with these. I was member of Euroswap for a short time before I joined a bunch of Archimedes coders that knew Some people in Violence i teamed up with  ('You can't feel the beating!'). Then later I co-founded Avalon together with 3 friends. Avalon had as many as 10 members at the most. If you're an old scener who remembers the Crusaders and Cryptoburners and still like text based BBS's, we'we probably met, since I was on virtually every party in Scandinavia in the late 80's and early 90's.

DEMO RESULTS FROM THE GATHERING 1995! (AMIGA DEMO)
1. Parallax+CNCD   11 136
2. Avalon          2  133 
3. The Black Lotus 10 110 





I'll post more pictures as i find them.