(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; fontset = title, nohscroll, bold, L12, 24, "Arial"; fontset = subtitle, nohscroll, bold, L12, 18, "Arial"; fontset = subsubtitle, nohscroll, L12, 14, "Arial"; fontset = section, nohscroll, blackBox, bold, L12, 14, "Arial"; fontset = subsection, nohscroll, grayBox, bold, L12, 12, "Arial"; fontset = subsubsection, nohscroll, whiteBox, bold, L12, 12, "Arial"; fontset = text, nohscroll, L0, 10, "Times New Roman"; fontset = smalltext, nohscroll, L0, 9, "Times New Roman"; fontset = input, nowordwrap, bold, L0, 10, "Courier New"; fontset = output, nowordwrap, L0, 10, "Courier New"; fontset = message, nowordwrap, L0, 10, "Courier New"; fontset = print, nowordwrap, L0, 10, "Courier New"; fontset = info, nowordwrap, B32768, L0, 10, "Courier New"; fontset = postscript, nowordwrap, L0, 12, "Courier New"; fontset = name, nohscroll, italic, L0, 10, "Arial"; fontset = header, L0, 10, "Times New Roman"; fontset = leftheader, L0, 10, "Times New Roman"; fontset = footer, center, L0, 10, "Times New Roman"; fontset = leftfooter, L0, 10, "Times New Roman"; fontset = help, nohscroll, L0, 10, "Times New Roman"; fontset = clipboard, nohscroll, L0, 10, "Times New Roman"; fontset = completions, nohscroll, L0, 10, "Times New Roman"; fontset = special1, nohscroll, L0, 10, "Times New Roman"; fontset = special2, nohscroll, L0, 10, "Times New Roman"; fontset = special3, nohscroll, L0, 10, "Times New Roman"; fontset = special4, nohscroll, L0, 10, "Times New Roman"; fontset = special5, nohscroll, L0, 10, "Times New Roman"; currentKernel; ] :[font = title; inactive; preserveAspect; backColorRed = 32768; backColorGreen = 32768; backColorBlue = 32768; fontName = "Times New Roman"; startGroup] Notebook to Convert Mathematica Density Plot into Live Texture File. :[font = text; inactive; preserveAspect] Prepared by Oxford System Solutions. Copyright 1994-1996 Milo Hedge Ltd. :[font = text; inactive; preserveAspect] First we need to write down some standard header information. This is to be given as 8 32-bit integers. In Mathematica, we can give a list of 32 hexadecimal numbers. Each group of 4 comprises one 32 bit integer. The important entries are those related to the number of frames in the texture map. Slot 3 (entries 9-12 in the list) should give 128 times the number of frames, while slot five should give 128x128xno. of frames. In our first example these are just 128, or 16^^80 in hex in the last of the four byt e slots, and 16384 = 64*256, or 16^^40 in the third of the four byte slots in slots 17-20. :[font = input; preserveAspect] headerdata = {16^^59,16^^a6,16^^6a,16^^95,0,0,0,16^^80,0,0,0, 16^^80,0,0,0,16^^8,0,0,16^^40,0,0,0,0, 1,0,0,0,1,0,0,3,0}; :[font = input; preserveAspect; startGroup] Length[headerdata] :[font = output; output; inactive; preserveAspect; endGroup] 32 ;[o] 32 :[font = text; inactive; preserveAspect] Next we make up a convenient colour map: :[font = input; preserveAspect] huefunc[x_] := 255*Which[x<1,x,x<3,1,x<4,4-x,True,0]; rgb[x_] := Floor[{huefunc[Mod[x+2,6]],huefunc[x], huefunc[Mod[x-2,6]]}]; colormap = Flatten[Transpose[Table[rgb[x],{x,0,6,6/255.0}]]]; :[font = text; inactive; preserveAspect] If you want to see what this color map looks like, use the following (not necessary to create output). :[font = input; preserveAspect] RenderMap[x_List] := Module[{matrix}, matrix = Transpose[Partition[x,256]]/256; matrix = Partition[Map[Apply[RGBColor,#]&,matrix],16]; Show[Graphics[RasterArray[matrix]], AspectRatio -> 1]; ] :[font = input; preserveAspect] RenderMap[colormap] :[font = text; inactive; preserveAspect] Now we need some data. :[font = section; inactive; preserveAspect; startGroup] Random Stuff :[font = input; preserveAspect] randomdata = Flatten[Table[2*Ceiling[100*Random[]], {128}, {128}]]; :[font = text; inactive; preserveAspect] Let's make a function to help us take a look: :[font = input; preserveAspect] RenderImage[image_,colormap_] := Module[{bettermap,raster}, bettermap = Transpose[Partition[colormap,256]]/256; bettermap = Map[Apply[RGBColor,#]&,bettermap]; raster = Partition[bettermap[[image]],128]; Show[Graphics[RasterArray[raster]]]; ] :[font = input; preserveAspect] Dimensions[randomdata] :[font = input; preserveAspect] RenderImage[randomdata,colormap] :[font = text; inactive; preserveAspect] Now we can write the data: :[font = input; preserveAspect] outline = OpenWrite["random.ras"]; WriteString[outline,FromCharacterCode[headerdata]]; WriteString[outline,FromCharacterCode[colormap]]; WriteString[outline,FromCharacterCode[randomdata]]; Close[outline] :[font = input; preserveAspect; endGroup] "random.ras" :[font = section; inactive; preserveAspect; startGroup] Glowing Fractals :[font = input; preserveAspect] IterationsToLeave = Compile[{zr,zi,cr,ci}, Module[ {cnt, nzr, temp, nzi}, nzr = zr; nzi = zi; For[cnt = 0, (nzr^2 + nzi^2 < 10000) && (cnt < 100), cnt++, temp = nzr^2 - nzi^2 + cr; nzi = 2*nzr*nzi + ci; nzr = temp ]; cnt ]]; :[font = input; preserveAspect] FractalM[z0r_, z0i_, {{ReMin_, ReMax_}, {ImMin_, ImMax_}}, steps_] := Table[ IterationsToLeave[z0r, z0i, x, y], {y, ImMin, ImMax, (ImMax - ImMin)/steps}, {x, ReMin, ReMax, (ReMax - ReMin)/steps} ] :[font = input; preserveAspect] fractaldata = FractalM[0.0, 0.0, {{-3.0, 1.0}, {-1.0, 1.0}}, 127]; :[font = input; preserveAspect] picdata = 2*Flatten[fractaldata]; :[font = input; preserveAspect] RenderImage[picdata,colormap] :[font = text; inactive; preserveAspect] Before outputting, we adjust the header data to treat an image with 17 frames: :[font = input; preserveAspect] headerdata = {16^^59,16^^a6,16^^6a,16^^95,0,0,0,16^^80,0,0,8, 16^^80,0,0,0,16^^8,0,16^^4,16^^40,0,0,0,0, 1,0,0,0,1,0,0,3,0}; :[font = input; preserveAspect; endGroup; endGroup] outline = OpenWrite["glowfrac.ras"]; WriteString[outline,FromCharacterCode[headerdata]]; WriteString[outline,FromCharacterCode[colormap]]; WriteString[outline,FromCharacterCode[picdata]]; For[i = 16, i < 260, i += 16, WriteString[outline,FromCharacterCode[Mod[picdata+i,256]]];] Close[outline] :[font = section; startGroup] For further information, advice or suggestions please contact :[font = text; cellOutline; endGroup] Email: support@milohedge.com Post: Milo Hedge Limited, 6 The Isis Business Centre, Pony Road, Oxford, OX4 2RD WWW: http://www.milohedge.com/mathlive/ ^*)