 @@@@@@@@@@@@@@@
@ Hugi Compo 19 @
 @@@@@@@@@@@@@@@

Last update 11/09/2002:
  -Interactivity section updated
  -Assumptions section updated

Introduction


  The goal of this compo: draw a 128x128 cellular texture and make it tile
  all over your nice 320x200 screen!
	
The Task


1. The Input

  A file name is passed to the program thanks to the command line. This file
  contains a set of 2D point plus a 256 colours palette. There isn't any 
  empty line.
  Your entry must work when called like that:
    entry.com points.txt

  When the user quit, the file doesn't have to be closed.

  Now let's go for some file geography! First comes the palette:
  -It has this format:
		
    R G B<cr><lf>
    R, G and B are in base 10 and 64>R>=0 64>G>=0 64>B>=0
	
  There are 256 lines like that. Again, there is only one space between 
  each value and no spaces between B and <cr><lf>.

  -The set of points has this format:
	
    X Y<cr><lf>
    X and Y are in base 10 and 128>X>=0 128>Y>=0
	
  There is only one space between the X and the Y and no spaces between Y 
  and <cr><lf>.
	
  The file ends with the EOF character 1ah on his own line.
  Incorrect file format can lead to random behavior:
    A file with 0 points is considered as a badly formatted file.
    A file with 128*128 points is considered as a badly formatted file.
    An unexisting file is considered as a badly formatted file.

2. Drawing

  To display your 128x128 texture, you will use mode 13h.
	
  To generate your texture you will use this algorithm:
  First generate a 128x128 distance^2 buffer like that:
	
    for y=0 to 127
      for x=0 to 127
        distBuffer(x,y) = FindNearest(x,y)
        if distBuffer(x,y) > maxdist then maxdist = distBuffer(x,y)

  Here is the FindNearest function:
	
    FindNearest(x,y)
      mindist=infinity
      for i=0 to num_of_points
        dist2 = Distance^2(x,y,points[i].x,points[i].y) 
        if dist2 < mindist
          mindist = dist2
      return mindist

  The Distance^2 function is a "warped" distance and is computed like that:
	
    Distance^2(x1,y1,x2,y2)   with 0<=x1<128  0<=x2<128
      dx=abs(x1-x2)                0<=y1<128  0<=y2<128
      dy=abs(y1-y2)
      if(dx>64) dx=128-dx
      if(dy>64) dy=128-dy
    return dx*dx+dy*dy

  Then use your 128x128 Distance^2 buffer to draw the texture:
	
  for x=0 to 319  Version1
    for y=0 to 199
    color(x,y) = ( 255*distBuffer(x%128,y%128) )/maxdist
		
  You must also draw a 255-color version of the texture:

  for x=0 to 319  Version2
    for y=0 to 199
    color(x,y) = 255 - ( 255*distBuffer(x%128,y%128) )/maxdist
  
  maxdist is never zero because files with 0 or 128*128 points are not 
  considered as correct input. So you don't have to check for this case.
  
  If you can get the same result with less bytes by palette-tweaking, do it.
  Your pixels just have to point to a correct RGB triplet.
	
3. Interactivity

  Pressing the <space> key will allow the user to switch between version 1 
  and version 2 of the texture. Version 1 must be the displayed first.
  Special keys(like CTRL, SHIFT, ALT+number...) can generate random behavior.
  Pressing any other key will exit the program and return to screen mode 3.
  You will use ah=0 int 16h to grab keys.

Testing


  As usual, put your entry.com into the "test" directory and run test.bat.
  
  The "ptgen" directory contains a utility to create an input file, there are
  also 4 (ugly) palettes and a POV gradient file (created by The GIMP) to TXT
  palette perl script. In the "test" dir, you will find 8 input files.
	
	Feel free to submit better palettes and funny points.
        Don't forget: if you use a lot of points only a few colors will be
        visible.
	
Assumptions


  You can assume that there is only one space between your entry.com and the
  input file name. Likewise, the input file name is immediatly followed by
  the 0x0D character.
  You can assume that the number of points is between 1 and 500.
  For all other assumptions check general.txt.

Rules are stupid and I want to burn the author


  Send all your questions/comments about rules to the Hugi compo mailing
  list at:
                hugi-compo@yahoogroups.com

Submissions


  Send your entries only to THIS address:

                  ------->>    cdvolko@gmx.net    <<-------

  You may submit updates to your entries at any time until the deadline.

Time table


  2002-08-30 : Compo starts
  2002-10-12 : Entry submission deadline
  2002-10-13 : Sourcepack will be released, public judgment starts
  2002-10-20 : End of public judgment, final results will be released

References


  The cellular texture algorithm has been taken from this page:
    http://www.blackpawn.com/texts/cellular/default.html
  So thanks to its author.
  
Greetings


  Thanks to Ruud, Beeblebrox, tnx, Adok and all other people who have 
  contribued to this rules.
  
  Have fun!
  
  Choli/Ben
  <lud.ben@wanadoo.fr>
