home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / graphics / fdesi313 / read.me < prev    next >
Encoding:
Text File  |  1995-05-19  |  15.2 KB  |  367 lines

  1. From Doug Nelson (compuserve 70431,3374)
  2.  
  3. This is the source code to FDESIGN 3.13, not released to the public domain
  4. until now (July 6, 1990).  This program started as a quick basic program that
  5. BYTE listed in January 1988.  I got tired of re-scaling the display for each
  6. IFS code, and thus, added an "auto-scaling" feature.  While not perfect, it
  7. worked quite well for most IFS codes.
  8.  
  9. The first time I tried to generate an IFS fractal was in January 1988 on an
  10. EGA (wow!) graphics interface.  I didn't do much with this until the summer
  11. of 1989, when I began seriously learning the C programming language.  Then I
  12. needed a program, so IFS fractals came to mind, along with the lack of PD
  13. programs in the area.
  14.  
  15. I developed this program mainly for my own interest in seeing what IFS codes
  16. could do, and what they couldn't do.  I got excited when I saw all the neat
  17. designs I could make with so little effort, and decided to make the program 
  18. more "public domain" by including printers that I don't have, and displays
  19. that I don't have (Version 2 had 256 color mode for Paradise and Genoa/
  20. Orchid cards).
  21.  
  22. This was my first attempt at a nice mouse-driven user interface.  Be nice, 
  23. it's not a Macintosh.  
  24.  
  25. Then I got turned on to Compuserve, found COMART, and, boy, did my eyes open
  26. to the league of programmers in the Stone Soup Group (makers of FRACTINT).
  27. These guys work their buns off to provide a compatible user interface for 
  28. mice, printers, and graphics displays.  This is much more of a job than I at
  29. first realized.  Thus, FDESIGN (as provided) supports fully only a Microsoft
  30. mouse, and VGA graphics (EGA too, but the aspect ratio is wrong).
  31.  
  32. Everyone in the Stone Soup Group to whom I've sent a message has been helpful 
  33. and courteous, providing helpful advice and information, as well as source
  34. code for a .GIF encoder.  Thanks guys.
  35.  
  36. Numerous suggestions have been made.  The inputting of three dimensional
  37. tetrahedrons (is that the minimal description of a three dimensional shape?),
  38. support of narrow-width carriages on Epson-compatible printers, and better
  39. graphics displays.  I'll be available on Compuserve (70431,3374) if you need
  40. assistance modifying this code.  I'm also active in the COMART forum.
  41.  
  42. Version 3.08 was the public domain version that I've tried to distribute from
  43. here to the other side of Earth.  Version 3.13 has some speed improvements,
  44. but I haven't tried it with any machine besides a 386 with coprocessor.
  45.  
  46. The source code is not pretty.  Remember, I learned C with this.  There are
  47. several places where code has been commented out, and you may have to compile
  48. this under tc++ with "nested comments enabled".  In particular the FDESHRES.C
  49. module is no longer used, but is provided, completely commented.  I haven't 
  50. messed with it for about 8 months.  
  51.  
  52. Version 3.08 will compile fine under TC 2.0.  Version 3.13 may require TC++.
  53.  
  54. Since the advent of a cheap object oriented programming language (TC++) this 
  55. code and way of coding will soon be outdated in my opinion.
  56.  
  57. I'll now go through the code (v3.13) and try to explain things (by module):
  58.  
  59. Module fdesign.c:
  60.         This is the top level module.  It contains a history of the program.
  61.  
  62.         The 'palate' array was for an EGA equivalent display on a VGA.
  63.         
  64.         The 'triangles' array stores the x-y coordinates of a triangle input
  65.         from the Edit Transformations display.
  66.         
  67.         Ok, here's a tricky one.  The IFS array holds the IFS codes, with the
  68.         first integer being the number of IFS codes in the array.  
  69.         
  70.         'revs' just compiles a string indicating the revision number.
  71.         
  72.         'topmenu' is a structure used to build the graphics menus.
  73.                 The first integer says how many items are in the menu.
  74.                 Following are the strings (or string addresses) for each menu
  75.                 item.
  76.         
  77.         'virtmenu' is for the "virtual screen print" menu.
  78.         
  79.         break_func displays my glorious name and then quits.
  80.         
  81.         '_matherr' is a Turbo C hook that I thought might be necessary after
  82.         floating point problems with rev 2.
  83.         
  84.         'default_fractal' sets up the opening screen display by initializing
  85.         the necessary components to completely describe an IFS fractal in this
  86.         program.
  87.         
  88.         'main' is main.
  89.                 If there is a command line argument, it must be the filename
  90.                 of a '.trn' file.
  91.  
  92.         (I changed editors from Qedit to Brief during this, so indentations
  93.         may be                    skewed.)
  94.  
  95.         'popup' is how you input a selection using the mouse.
  96.  
  97.         commented out:
  98.                 "case 6" was an MCGA display (256 colors at 320x200).
  99.                 "case 7" was a super VGA mode (256 colors at 640x480).
  100.  
  101.         ******** doIFSrand(); ******************
  102.                 This does everything for you if you have set up the Triangles
  103.                 properly (check default_fractal).
  104.  
  105.         'IFS_rescale' is used to zoom.
  106.  
  107.         'ifs_menu' shows the IFS codes used to create the current display.  No
  108.                 additional scaling or offset is required.
  109.  
  110.         'gscanf' is a simple graphics 'scanf'.
  111.  
  112. Module fdesequa.c:
  113.         'det' returns a determinant of a 2x2 matrix.
  114.  
  115.         'solve3' solves 3 equations with 3 unknowns.
  116.  
  117.         'IFS_compute' computes the transformation from the reference triangle
  118.         "t0" to the transform triangle "t1".  Results are the IFS codes and 
  119.         they are stored in the IFS[] array.
  120.  
  121.         'IFS_compute_all' computes the IFS transformation for all triangles
  122.         and builds the IFS[] array to completion.
  123.  
  124.         The IFS array contains:
  125.                 number_of_IFS_codes,
  126.                 a,b,c,d,e,f,p
  127.                         p is the probability for the IFS code plus the
  128.                         probabilities of all preceding codes (the BYTE program
  129.                         was like this).
  130.                 a,b,c,d,e,f,p
  131.                 a,b,c,d,e,f,p
  132.                 ...
  133.  
  134. Module fdesfile.c:
  135.         Three file formats have been used with this program.  All three can
  136.         be read with this module.
  137.  
  138.         'trnfile_save' creates a .TRN file for the current IFS fractal.
  139.  
  140.         'trnfile_load' reads a .TRN file in a format specified by the version
  141.         number, which is the first two bytes of the file.
  142.  
  143.         The revision number is an integer where the hundreds specifies the
  144.         main revision (3) and the 2 LSDs specify the minor version number (.08).
  145.  
  146. Module fdesgif.c:
  147.         This .GIF encoder was provided by Bert Tyler and Lee Daniel Crocker.
  148.         It has been slightly modified since its incorporation into this 
  149.         program.
  150.  
  151. Module fdeshres.c:
  152.         These were the routines for 256 color modes.
  153.  
  154.         'set_palette' wrote to the display adapter my rendition of full-color
  155.         (don't use this as an example).
  156.  
  157.         'init256' placed the adapter into 256 color mode.
  158.  
  159.         'putpixel256' called the adapter BIOS.
  160.  
  161.         'getpixel256' called the adapter BIOS.
  162.  
  163. Module fdesifs.c:
  164.         This module is used to port files from/to FRACTINT.
  165.  
  166.         'ifs_menu' is pretty complex.  Let me just say that it can write a
  167.         FRACTINT .IFS file and can also read one.  Writing one is easy, it's
  168.         a matter of re-scaling the triangles (IFS codes) to the FRACTINT 
  169.         virtual display.  Reading one is more difficult.  There are a 
  170.         buzillion possible triangle transformations, given a set of IFS codes.
  171.         The program finds 'fixed points' and scales the triangles so the fixed
  172.         points would be on the screen (or in a portion of the screen).
  173.  
  174. Module fdesmenu.c:
  175.         'popup' displays the pop-up menu and waits for a mouse click within
  176.         that menu.
  177.  
  178.         'putmsg' displays some text in a box.  (It supports a stack of 10
  179.         displays).
  180.  
  181.         'clrmsg' clears the most recent 'putmsg' display.
  182.  
  183.         'putmsg_d' is destructive, it does not preserve the background graphics.
  184.                 This is necessary when you are in danger of running out of
  185.                 memory.
  186.  
  187.         'gscanf' is a 'scanf' for graphics mode.  Carriage return ends the
  188.         input, and escape exits with a zero return code.
  189.  
  190.         'trn_directory' is used to select a filename from the filename 
  191.         display.
  192.  
  193.         'line_ovly' is my attempt at a nice non-destructive line drawer.  It 
  194.         has a stack 10 deep.
  195.  
  196.         'line_clear' erases from the display the latest line.
  197.  
  198.         'box_new' inputs a box, allowing re-sizing of the box.
  199.  
  200.         'zoom_in' and 'zoom_out' belong in some other module.  They update the
  201.         value of 'area_scaled' which determines the needed iterations in the
  202.         virtual plot menu.
  203.  
  204.         'zoom_out' is really a 'zoom_reset'.
  205.  
  206. Module fdesmodi.c:
  207.         'grat_on' turns on the graticule dots.
  208.  
  209.         'grat_off' turns off the graticule dots (not used).
  210.  
  211.         'recrop' will re-scale the triangles in the "Edit Transformations" 
  212.         screen (formery the "Modify" menu).
  213.  
  214.         'triangles_use_temp' means that the "zoomed" or un-"zoomed" triangles
  215.         now become the permanent reference/tranformation triangles.
  216.  
  217.         'modify_scr' lays the basic "edit tranformations" screen.
  218.  
  219.         'modify_input' accepts mouse commands to modify the triangles.
  220.         Some calls are made to determine where the mouse is pointing, such as
  221.         "pt_closest_triangle".  Some considerable effort was made to determine
  222.         the "closest" triangle.
  223.  
  224.         "grat is off" and "grat is on" reflect whether mouse_click or 
  225.         mouse_click_grat is used.
  226.  
  227.         "mouse_idle_job" is a function pointer to which routine gets executed
  228.         when polling for a mouse button.
  229.  
  230. Module fdesmous.c
  231.         'm_cursor' is my wonderful mouse cursor.
  232.  
  233.         'mouse_reset' executes the Microsoft reset mouse command.
  234.  
  235.         'mouse_on' turns on the mouse cursor.
  236.  
  237.         'mouse_off' turns off the mouse cursor.
  238.         The mouse cursor is turned on in this program only when waiting for
  239.         input from the mouse.
  240.  
  241.         'mouse_get' returns the mouse row, column, and button status.
  242.  
  243.         'mouse_put' (not used) places the mouse at row and column.
  244.  
  245.         'mouse_press' checks for either of two buttons pressed (this is 
  246.         probably very kludgy).
  247.  
  248.         'mouse_idle' exists because I didn't know about NULLFUNC.
  249.  
  250.         'mouse_idle_job' points to a function that is executed whenever waiting
  251.         for a "mouse_click".
  252.  
  253.         'mouse_click' waits for a mouse button (or escape).  It returns the 
  254.         mouse position (via mouse_state *m).
  255.  
  256.         'mouse_click_grat' is the same as mouse_click except it picks the 
  257.         nearest graticule point and returns it instead.
  258.  
  259. Module fdesplot.c:
  260.         This module performs the plotting of pixels to the screen using the
  261.         global IFS codes.
  262.  
  263.         'randmap' is used to quickly determine which IFS code should be plotted
  264.         given a rand()om number.
  265.  
  266.         'plotabunch' plots X points using the IFS codes.
  267.         I have replaced a few lines (commented out) with assembly code after
  268.         looking at execution times with TPROF.
  269.  
  270.         'var[k].' was a concoction designed to speed up access to the variables
  271.         a,b,c,d,e and f.  'fv' is used to point to 'a' then 'b' then 'e' then
  272.         'c' then 'd' then 'f'.
  273.  
  274.         'putpixel' still consumes the most time.
  275.  
  276.         'plotabunch16' reads the current pixel color and the increments the
  277.         pixel color.
  278.  
  279.         'plotabunchs' plots the small fractal picture in the upper right corner.
  280.  
  281.         'plotabunch_inc' was used to increment the 256 color pixel value.
  282.  
  283.         'vplotabunch' plots points to a 'virtual screen' of 1504x1200 pixels.
  284.  
  285.         'IFS_rescale' re-scales the triangles relative to 'ttriangles', if 
  286.         rel=1, or 'triangles' if rel=0.
  287.  
  288.         'triangles_use_temp' copies from ttriangles (temporary triangle positions
  289.         used in zooming or other re-scaling such as virtual plot re-scaling)
  290.         to 'triangles', the permanent (displayable) copies of the triangles.
  291.  
  292.         'plotlimits' does several iterations of the IFS codes to be sure that
  293.         the current point 'x' and 'y' are on the fractal.  It then re-scales 
  294.         the 'triangles' and places them in 'ttriangles', so that re-scaling 
  295.         is not necessary when ploting to the screen.  The various plot sizes
  296.         are taken into account in this routine.
  297.  
  298.         'doIFSrand' performs 'plotabunch' until a mouse button is pressed.
  299.                 There is also code (commented out) that performs an auto-scaling
  300.                 of the color wheel after some pixel reaches the maximum color.
  301.  
  302. Module fdesprin.c:
  303.         This is my quick-and-dirty set of routines for printing the display
  304.         screen or virtual screen.
  305.  
  306. Module fdestria.c:
  307.         'triangle_new' is used to input triangle coordinates using the mouse.
  308.  
  309.         'triangle_show' displays a triangle.
  310.  
  311.         'pt_pt_distance' is the distance formula between two points.
  312.  
  313.         'triangle_corner' returns the corner of a triangle closest to the mouse.
  314.  
  315.         'pt_line_distance' is a math formula, point-to-line-distance.
  316.  
  317.         'pt_lines_distance' is smarter because it returns the distance to a 
  318.         line segment.
  319.  
  320.         'pt_triangle_distance' returns smallest distance to a triangle.
  321.  
  322.         'pt_closest_triangle' returns the number of the triangle that is
  323.         closest to the mouse pointer.
  324.  
  325.         'triangle_area' returns the area of a triangle (used to estimate
  326.         probability).
  327.  
  328.         'transform_affine' determines if the transformation is contractive 
  329.         affine.
  330.  
  331.         'triangle_limits' determines the minimum box that would contain all 
  332.         of the triangles.
  333.  
  334. Module fdesvirt.c:
  335.         Originally, I intended to display a portion of the 'virtual screen'
  336.         and allow scrolling within it while the virtual screen was being 
  337.         plotted.  This never came to be, but the beginnings of the code to do
  338.         so are contained here.
  339.  
  340.         'vscreen_open' allocates memory for the virtual screen.
  341.  
  342.         'vscreen_close' de-allocates memory for the virtual screen.
  343.  
  344.         'vputpixel' and 'vgetpixel' are used to 'put' and 'get' pixels from
  345.         the virtual screen, respectively.
  346.  
  347.         'vscreen_clear' is the most in-efficient way I could think of to zero
  348.         a large memory area.
  349.  
  350.  
  351. The .h files contain references to their respective .c modules that other 
  352. modules may need to know.
  353.  
  354. The remaining file is fdesglob.h, which contains the revision number.
  355.  
  356. As with most PD software (as I've noticed), the comments lag the state of the 
  357. code.  I haven't violated that truism.
  358.  
  359. In the ZIP file you've extracted are two copies of FDESIGN.  One is Rev 3.08,
  360. the last distributed version.  The other is 3.13, which has speed improvement
  361. but has not been tested, except on my machine.
  362.  
  363. So what does all this do for me, Al (Doug Nelson) Franken?  Well, it gives me
  364. time to pursue my latest interest, genetic algorithms.  It's pretty neat stuff
  365. and I want to see it can do.  Y'know, it seems that genetic mutations may have
  366. a fractal nature....
  367.