home *** CD-ROM | disk | FTP | other *** search
- From Doug Nelson (compuserve 70431,3374)
-
- This is the source code to FDESIGN 3.13, not released to the public domain
- until now (July 6, 1990). This program started as a quick basic program that
- BYTE listed in January 1988. I got tired of re-scaling the display for each
- IFS code, and thus, added an "auto-scaling" feature. While not perfect, it
- worked quite well for most IFS codes.
-
- The first time I tried to generate an IFS fractal was in January 1988 on an
- EGA (wow!) graphics interface. I didn't do much with this until the summer
- of 1989, when I began seriously learning the C programming language. Then I
- needed a program, so IFS fractals came to mind, along with the lack of PD
- programs in the area.
-
- I developed this program mainly for my own interest in seeing what IFS codes
- could do, and what they couldn't do. I got excited when I saw all the neat
- designs I could make with so little effort, and decided to make the program
- more "public domain" by including printers that I don't have, and displays
- that I don't have (Version 2 had 256 color mode for Paradise and Genoa/
- Orchid cards).
-
- This was my first attempt at a nice mouse-driven user interface. Be nice,
- it's not a Macintosh.
-
- Then I got turned on to Compuserve, found COMART, and, boy, did my eyes open
- to the league of programmers in the Stone Soup Group (makers of FRACTINT).
- These guys work their buns off to provide a compatible user interface for
- mice, printers, and graphics displays. This is much more of a job than I at
- first realized. Thus, FDESIGN (as provided) supports fully only a Microsoft
- mouse, and VGA graphics (EGA too, but the aspect ratio is wrong).
-
- Everyone in the Stone Soup Group to whom I've sent a message has been helpful
- and courteous, providing helpful advice and information, as well as source
- code for a .GIF encoder. Thanks guys.
-
- Numerous suggestions have been made. The inputting of three dimensional
- tetrahedrons (is that the minimal description of a three dimensional shape?),
- support of narrow-width carriages on Epson-compatible printers, and better
- graphics displays. I'll be available on Compuserve (70431,3374) if you need
- assistance modifying this code. I'm also active in the COMART forum.
-
- Version 3.08 was the public domain version that I've tried to distribute from
- here to the other side of Earth. Version 3.13 has some speed improvements,
- but I haven't tried it with any machine besides a 386 with coprocessor.
-
- The source code is not pretty. Remember, I learned C with this. There are
- several places where code has been commented out, and you may have to compile
- this under tc++ with "nested comments enabled". In particular the FDESHRES.C
- module is no longer used, but is provided, completely commented. I haven't
- messed with it for about 8 months.
-
- Version 3.08 will compile fine under TC 2.0. Version 3.13 may require TC++.
-
- Since the advent of a cheap object oriented programming language (TC++) this
- code and way of coding will soon be outdated in my opinion.
-
- I'll now go through the code (v3.13) and try to explain things (by module):
-
- Module fdesign.c:
- This is the top level module. It contains a history of the program.
-
- The 'palate' array was for an EGA equivalent display on a VGA.
-
- The 'triangles' array stores the x-y coordinates of a triangle input
- from the Edit Transformations display.
-
- Ok, here's a tricky one. The IFS array holds the IFS codes, with the
- first integer being the number of IFS codes in the array.
-
- 'revs' just compiles a string indicating the revision number.
-
- 'topmenu' is a structure used to build the graphics menus.
- The first integer says how many items are in the menu.
- Following are the strings (or string addresses) for each menu
- item.
-
- 'virtmenu' is for the "virtual screen print" menu.
-
- break_func displays my glorious name and then quits.
-
- '_matherr' is a Turbo C hook that I thought might be necessary after
- floating point problems with rev 2.
-
- 'default_fractal' sets up the opening screen display by initializing
- the necessary components to completely describe an IFS fractal in this
- program.
-
- 'main' is main.
- If there is a command line argument, it must be the filename
- of a '.trn' file.
-
- (I changed editors from Qedit to Brief during this, so indentations
- may be skewed.)
-
- 'popup' is how you input a selection using the mouse.
-
- commented out:
- "case 6" was an MCGA display (256 colors at 320x200).
- "case 7" was a super VGA mode (256 colors at 640x480).
-
- ******** doIFSrand(); ******************
- This does everything for you if you have set up the Triangles
- properly (check default_fractal).
-
- 'IFS_rescale' is used to zoom.
-
- 'ifs_menu' shows the IFS codes used to create the current display. No
- additional scaling or offset is required.
-
- 'gscanf' is a simple graphics 'scanf'.
-
- Module fdesequa.c:
- 'det' returns a determinant of a 2x2 matrix.
-
- 'solve3' solves 3 equations with 3 unknowns.
-
- 'IFS_compute' computes the transformation from the reference triangle
- "t0" to the transform triangle "t1". Results are the IFS codes and
- they are stored in the IFS[] array.
-
- 'IFS_compute_all' computes the IFS transformation for all triangles
- and builds the IFS[] array to completion.
-
- The IFS array contains:
- number_of_IFS_codes,
- a,b,c,d,e,f,p
- p is the probability for the IFS code plus the
- probabilities of all preceding codes (the BYTE program
- was like this).
- a,b,c,d,e,f,p
- a,b,c,d,e,f,p
- ...
-
- Module fdesfile.c:
- Three file formats have been used with this program. All three can
- be read with this module.
-
- 'trnfile_save' creates a .TRN file for the current IFS fractal.
-
- 'trnfile_load' reads a .TRN file in a format specified by the version
- number, which is the first two bytes of the file.
-
- The revision number is an integer where the hundreds specifies the
- main revision (3) and the 2 LSDs specify the minor version number (.08).
-
- Module fdesgif.c:
- This .GIF encoder was provided by Bert Tyler and Lee Daniel Crocker.
- It has been slightly modified since its incorporation into this
- program.
-
- Module fdeshres.c:
- These were the routines for 256 color modes.
-
- 'set_palette' wrote to the display adapter my rendition of full-color
- (don't use this as an example).
-
- 'init256' placed the adapter into 256 color mode.
-
- 'putpixel256' called the adapter BIOS.
-
- 'getpixel256' called the adapter BIOS.
-
- Module fdesifs.c:
- This module is used to port files from/to FRACTINT.
-
- 'ifs_menu' is pretty complex. Let me just say that it can write a
- FRACTINT .IFS file and can also read one. Writing one is easy, it's
- a matter of re-scaling the triangles (IFS codes) to the FRACTINT
- virtual display. Reading one is more difficult. There are a
- buzillion possible triangle transformations, given a set of IFS codes.
- The program finds 'fixed points' and scales the triangles so the fixed
- points would be on the screen (or in a portion of the screen).
-
- Module fdesmenu.c:
- 'popup' displays the pop-up menu and waits for a mouse click within
- that menu.
-
- 'putmsg' displays some text in a box. (It supports a stack of 10
- displays).
-
- 'clrmsg' clears the most recent 'putmsg' display.
-
- 'putmsg_d' is destructive, it does not preserve the background graphics.
- This is necessary when you are in danger of running out of
- memory.
-
- 'gscanf' is a 'scanf' for graphics mode. Carriage return ends the
- input, and escape exits with a zero return code.
-
- 'trn_directory' is used to select a filename from the filename
- display.
-
- 'line_ovly' is my attempt at a nice non-destructive line drawer. It
- has a stack 10 deep.
-
- 'line_clear' erases from the display the latest line.
-
- 'box_new' inputs a box, allowing re-sizing of the box.
-
- 'zoom_in' and 'zoom_out' belong in some other module. They update the
- value of 'area_scaled' which determines the needed iterations in the
- virtual plot menu.
-
- 'zoom_out' is really a 'zoom_reset'.
-
- Module fdesmodi.c:
- 'grat_on' turns on the graticule dots.
-
- 'grat_off' turns off the graticule dots (not used).
-
- 'recrop' will re-scale the triangles in the "Edit Transformations"
- screen (formery the "Modify" menu).
-
- 'triangles_use_temp' means that the "zoomed" or un-"zoomed" triangles
- now become the permanent reference/tranformation triangles.
-
- 'modify_scr' lays the basic "edit tranformations" screen.
-
- 'modify_input' accepts mouse commands to modify the triangles.
- Some calls are made to determine where the mouse is pointing, such as
- "pt_closest_triangle". Some considerable effort was made to determine
- the "closest" triangle.
-
- "grat is off" and "grat is on" reflect whether mouse_click or
- mouse_click_grat is used.
-
- "mouse_idle_job" is a function pointer to which routine gets executed
- when polling for a mouse button.
-
- Module fdesmous.c
- 'm_cursor' is my wonderful mouse cursor.
-
- 'mouse_reset' executes the Microsoft reset mouse command.
-
- 'mouse_on' turns on the mouse cursor.
-
- 'mouse_off' turns off the mouse cursor.
- The mouse cursor is turned on in this program only when waiting for
- input from the mouse.
-
- 'mouse_get' returns the mouse row, column, and button status.
-
- 'mouse_put' (not used) places the mouse at row and column.
-
- 'mouse_press' checks for either of two buttons pressed (this is
- probably very kludgy).
-
- 'mouse_idle' exists because I didn't know about NULLFUNC.
-
- 'mouse_idle_job' points to a function that is executed whenever waiting
- for a "mouse_click".
-
- 'mouse_click' waits for a mouse button (or escape). It returns the
- mouse position (via mouse_state *m).
-
- 'mouse_click_grat' is the same as mouse_click except it picks the
- nearest graticule point and returns it instead.
-
- Module fdesplot.c:
- This module performs the plotting of pixels to the screen using the
- global IFS codes.
-
- 'randmap' is used to quickly determine which IFS code should be plotted
- given a rand()om number.
-
- 'plotabunch' plots X points using the IFS codes.
- I have replaced a few lines (commented out) with assembly code after
- looking at execution times with TPROF.
-
- 'var[k].' was a concoction designed to speed up access to the variables
- a,b,c,d,e and f. 'fv' is used to point to 'a' then 'b' then 'e' then
- 'c' then 'd' then 'f'.
-
- 'putpixel' still consumes the most time.
-
- 'plotabunch16' reads the current pixel color and the increments the
- pixel color.
-
- 'plotabunchs' plots the small fractal picture in the upper right corner.
-
- 'plotabunch_inc' was used to increment the 256 color pixel value.
-
- 'vplotabunch' plots points to a 'virtual screen' of 1504x1200 pixels.
-
- 'IFS_rescale' re-scales the triangles relative to 'ttriangles', if
- rel=1, or 'triangles' if rel=0.
-
- 'triangles_use_temp' copies from ttriangles (temporary triangle positions
- used in zooming or other re-scaling such as virtual plot re-scaling)
- to 'triangles', the permanent (displayable) copies of the triangles.
-
- 'plotlimits' does several iterations of the IFS codes to be sure that
- the current point 'x' and 'y' are on the fractal. It then re-scales
- the 'triangles' and places them in 'ttriangles', so that re-scaling
- is not necessary when ploting to the screen. The various plot sizes
- are taken into account in this routine.
-
- 'doIFSrand' performs 'plotabunch' until a mouse button is pressed.
- There is also code (commented out) that performs an auto-scaling
- of the color wheel after some pixel reaches the maximum color.
-
- Module fdesprin.c:
- This is my quick-and-dirty set of routines for printing the display
- screen or virtual screen.
-
- Module fdestria.c:
- 'triangle_new' is used to input triangle coordinates using the mouse.
-
- 'triangle_show' displays a triangle.
-
- 'pt_pt_distance' is the distance formula between two points.
-
- 'triangle_corner' returns the corner of a triangle closest to the mouse.
-
- 'pt_line_distance' is a math formula, point-to-line-distance.
-
- 'pt_lines_distance' is smarter because it returns the distance to a
- line segment.
-
- 'pt_triangle_distance' returns smallest distance to a triangle.
-
- 'pt_closest_triangle' returns the number of the triangle that is
- closest to the mouse pointer.
-
- 'triangle_area' returns the area of a triangle (used to estimate
- probability).
-
- 'transform_affine' determines if the transformation is contractive
- affine.
-
- 'triangle_limits' determines the minimum box that would contain all
- of the triangles.
-
- Module fdesvirt.c:
- Originally, I intended to display a portion of the 'virtual screen'
- and allow scrolling within it while the virtual screen was being
- plotted. This never came to be, but the beginnings of the code to do
- so are contained here.
-
- 'vscreen_open' allocates memory for the virtual screen.
-
- 'vscreen_close' de-allocates memory for the virtual screen.
-
- 'vputpixel' and 'vgetpixel' are used to 'put' and 'get' pixels from
- the virtual screen, respectively.
-
- 'vscreen_clear' is the most in-efficient way I could think of to zero
- a large memory area.
-
-
- The .h files contain references to their respective .c modules that other
- modules may need to know.
-
- The remaining file is fdesglob.h, which contains the revision number.
-
- As with most PD software (as I've noticed), the comments lag the state of the
- code. I haven't violated that truism.
-
- In the ZIP file you've extracted are two copies of FDESIGN. One is Rev 3.08,
- the last distributed version. The other is 3.13, which has speed improvement
- but has not been tested, except on my machine.
-
- So what does all this do for me, Al (Doug Nelson) Franken? Well, it gives me
- time to pursue my latest interest, genetic algorithms. It's pretty neat stuff
- and I want to see it can do. Y'know, it seems that genetic mutations may have
- a fractal nature....
-