// // time: Mon Jan 9 10:47:18 1995 // // version: 2.0.2 (format), 2.1.0 (DX) // // MODULE main // CATEGORY Macros // // comment: This program shows how you can use Compute to make a parametric surface from the 2D positions of a field. The Mark module is used to mark the "positions" component as "data" so that Compute can operate on the positions. The Compute module produces a 3-vector of positions. After the 2D positions are mapped to 3D, the positions are returned to the "positions" component using the Unmark module. Normals are added for shading, and the result is displayed. // workspace: width = 1000, height = 1000 // layout: snap = 0, width = 50, height = 50, align = CC // macro main( ) -> ( ) { // // node Compute[3]: x = 224, y = 33, inputs = 1, label = Compute--pi // input[1]: defaulting = 0, visible = 0, type = 32, value = "3.14159" // // expression: value = 3.14159 main_Compute_3_out_1 = Compute( main_Compute_3_in_1 ) [instance: 3, cache: 1]; // // node Construct[1]: x = 23, y = 33, inputs = 4, label = Make a 21x21 grid centered at (0,0) and spanning (-1,-1) to (1,1) // input[1]: defaulting = 0, visible = 1, type = 16777224, value = {[0 0]} // input[2]: defaulting = 0, visible = 1, type = 16777224, value = {[.05 .05]} // input[3]: defaulting = 0, visible = 1, type = 8, value = [21 21] // main_Construct_1_out_1 = Construct( main_Construct_1_in_1, main_Construct_1_in_2, main_Construct_1_in_3, main_Construct_1_in_4 ) [instance: 1, cache: 1]; // // node Color[1]: x = 31, y = 102, inputs = 5, label = Color given as a R,G,B vector // input[2]: defaulting = 0, visible = 1, type = 8, value = [0.8, 0.7, 0.2] // main_Color_1_out_1 = Color( main_Construct_1_out_1, main_Color_1_in_2, main_Color_1_in_3, main_Color_1_in_4, main_Color_1_in_5 ) [instance: 1, cache: 1]; // // node Transmitter[18]: x = 246, y = 113, inputs = 1, label = pi // pi = main_Compute_3_out_1; // // node Mark[1]: x = 44, y = 188, inputs = 2, label = Indicate to the "Compute" module that you want to manipulate positions // input[2]: defaulting = 0, visible = 1, type = 32, value = "positions" // main_Mark_1_out_1 = Mark( main_Color_1_out_1, main_Mark_1_in_2 ) [instance: 1, cache: 1]; // // node Receiver[43]: x = 311, y = 224, inputs = 1, label = pi // main_Receiver_43_out_1 = pi; // // node Compute[4]: x = 16, y = 284, inputs = 2, label = extract x component of position // input[1]: defaulting = 0, visible = 0, type = 32, value = "$0.x" // // expression: value = a.x // name[2]: value = a main_Compute_4_out_1 = Compute( main_Compute_4_in_1, main_Mark_1_out_1 ) [instance: 4, cache: 1]; // // node Compute[5]: x = 103, y = 288, inputs = 2, label = extract y component of position // input[1]: defaulting = 0, visible = 0, type = 32, value = "$0.y" // // expression: value = a.y // name[2]: value = a main_Compute_5_out_1 = Compute( main_Compute_5_in_1, main_Mark_1_out_1 ) [instance: 5, cache: 1]; // // node Transmitter[19]: x = 44, y = 364, inputs = 1, label = v // v = main_Compute_4_out_1; // // node Transmitter[20]: x = 121, y = 361, inputs = 1, label = w // w = main_Compute_5_out_1; // // node Receiver[44]: x = 246, y = 223, inputs = 1, label = v // main_Receiver_44_out_1 = v; // // node Receiver[45]: x = 279, y = 224, inputs = 1, label = w // main_Receiver_45_out_1 = w; // // node Compute[1]: x = 251, y = 312, inputs = 4, label = Make a 3-vector [x,y,z] for a torus from a 2-vector [v,w] // input[1]: defaulting = 0, visible = 0, type = 32, value = "[ .5*cos(2*$2*$0) , (1+.5*sin(2*$2*$0))*cos(2*$2*$1) , (1+.5*sin(2*$2*$0))*sin(2*$2*$1) ]" // // expression: value = [ .5*cos(2*pi*v) , (1+.5*sin(2*pi*v))*cos(2*pi*w) , (1+.5*sin(2*pi*v))*sin(2*pi*w) ] // name[2]: value = v // name[3]: value = w // name[4]: value = pi main_Compute_1_out_1 = Compute( main_Compute_1_in_1, main_Receiver_44_out_1, main_Receiver_45_out_1, main_Receiver_43_out_1 ) [instance: 1, cache: 1]; // // node Unmark[1]: x = 268, y = 394, inputs = 2, label = Substitute new positions for old // input[2]: defaulting = 0, visible = 1, type = 32, value = "positions" // main_Unmark_1_out_1 = Unmark( main_Compute_1_out_1, main_Unmark_1_in_2 ) [instance: 1, cache: 1]; // // node Normals[1]: x = 264, y = 482, inputs = 2, label = calculate surface normals for lighting // main_Normals_1_out_1 = Normals( main_Unmark_1_out_1, main_Normals_1_in_2 ) [instance: 1, cache: 1]; // // node Image[1]: x = 274, y = 574, inputs = 35, label = Image // input[1]: defaulting = 0, visible = 0, type = 1, value = 2 // input[4]: defaulting = 0, visible = 0, type = 8, value = [0 0 -2.98023e-08] // input[5]: defaulting = 0, visible = 0, type = 8, value = [6.7203 -2.00995 3.76358] // input[6]: defaulting = 1, visible = 0, type = 5, value = 4.26593 // input[7]: defaulting = 0, visible = 0, type = 1, value = 378 // input[8]: defaulting = 0, visible = 0, type = 5, value = 0.866 // input[9]: defaulting = 0, visible = 0, type = 8, value = [-0.374816 0.352437 0.857497] // input[11]: defaulting = 0, visible = 0, type = 3, value = 2 // input[12]: defaulting = 0, visible = 0, type = 16777248, value = {"x","y","z"} // input[13]: defaulting = 0, visible = 0, type = 1, value = 5 // input[14]: defaulting = 0, visible = 0, type = 16777224, value = {[-1, -1, -1], [1, 1, 1]} // input[19]: defaulting = 0, visible = 0, type = 32, value = "prettypicture" // input[21]: defaulting = 0, visible = 0, type = 32, value = "rgb" // input[22]: defaulting = 0, visible = 0, type = 1, value = 1 // input[23]: defaulting = 0, visible = 0, type = 5, value = 30.0 // input[24]: defaulting = 0, visible = 0, type = 1, value = 1 // input[25]: defaulting = 0, visible = 0, type = 32, value = "none" // input[26]: defaulting = 0, visible = 0, type = 32, value = "none" // input[27]: defaulting = 0, visible = 0, type = 1, value = 1 // input[28]: defaulting = 0, visible = 0, type = 1, value = 1 // input[29]: defaulting = 0, visible = 0, type = 3, value = 1 // // title: value = Warped surface // depth: value = 8 main_Image_1_out_1, main_Image_1_out_2 = Image( main_Image_1_in_1, main_Normals_1_out_1, main_Image_1_in_3, main_Image_1_in_4, main_Image_1_in_5, main_Image_1_in_6, main_Image_1_in_7, main_Image_1_in_8, main_Image_1_in_9, main_Image_1_in_10, main_Image_1_in_11, main_Image_1_in_12, main_Image_1_in_13, main_Image_1_in_14, main_Image_1_in_15, main_Image_1_in_16, main_Image_1_in_17, main_Image_1_in_18, main_Image_1_in_19, main_Image_1_in_20, main_Image_1_in_21, main_Image_1_in_22, main_Image_1_in_23, main_Image_1_in_24, main_Image_1_in_25, main_Image_1_in_26, main_Image_1_in_27, main_Image_1_in_28, main_Image_1_in_29, main_Image_1_in_30, main_Image_1_in_31, main_Image_1_in_32, main_Image_1_in_33, main_Image_1_in_34, main_Image_1_in_35 ) [instance: 1, cache: 1]; // network: end of macro body } main_Compute_3_in_1 = "3.14159"; main_Compute_3_out_1 = NULL; main_Construct_1_in_1 = {[0 0]}; main_Construct_1_in_2 = {[.05 .05]}; main_Construct_1_in_3 = [21 21]; main_Construct_1_in_4 = NULL; main_Construct_1_out_1 = NULL; main_Color_1_in_2 = [0.8, 0.7, 0.2]; main_Color_1_in_3 = NULL; main_Color_1_in_4 = NULL; main_Color_1_in_5 = NULL; main_Color_1_out_1 = NULL; main_Transmitter_18_out_1 = NULL; main_Mark_1_in_2 = "positions"; main_Mark_1_out_1 = NULL; main_Receiver_43_out_1 = NULL; main_Compute_4_in_1 = "$0.x"; main_Compute_4_out_1 = NULL; main_Compute_5_in_1 = "$0.y"; main_Compute_5_out_1 = NULL; main_Transmitter_19_out_1 = NULL; main_Transmitter_20_out_1 = NULL; main_Receiver_44_out_1 = NULL; main_Receiver_45_out_1 = NULL; main_Compute_1_in_1 = "[ .5*cos(2*$2*$0) , (1+.5*sin(2*$2*$0))*cos(2*$2*$1) , (1+.5*sin(2*$2*$0))*sin(2*$2*$1) ]"; main_Compute_1_out_1 = NULL; main_Unmark_1_in_2 = "positions"; main_Unmark_1_out_1 = NULL; main_Normals_1_in_2 = NULL; main_Normals_1_out_1 = NULL; macro Image( useVector, object, where, to, from, width, resolution, aspect, up, options, AAenable = 1, AAlabels, AAticks, AAcorners, AAframe, AAadjust, AAcursor, RECenable = 1, RECfile, throttle, RECformat, perspective, viewAngle, buttonState = 1, buttonUpApprox = "none", buttonDownApprox = "none", buttonUpDensity = 1, buttonDownDensity = 1, renderMode = 1, backgroundColor, AAgrid, AAcolors, AAannotation, AAlabelscale, AAfont) -> ( object, camera) { autoCamera = AutoCamera( object, "front", object, resolution, aspect, [0,1,0], perspective, viewAngle, backgroundColor) [instance: 1]; realCamera = Camera( to, from, width, resolution, aspect, up, perspective, viewAngle, backgroundColor) [instance: 1]; camera = Switch(useVector, autoCamera, realCamera)[instance:1]; AAobject = AutoAxes( object, camera, AAlabels, AAticks, AAcorners, AAframe, AAadjust, AAcursor, AAgrid, AAcolors, AAannotation, AAlabelscale, AAfont) [instance: 1]; object = Switch(AAenable, object, AAobject)[instance:2]; SWapproximation_options = Switch( buttonState, buttonUpApprox, buttonDownApprox) [instance: 3]; SWdensity_options = Switch( buttonState, buttonUpDensity, buttonDownDensity) [instance: 4]; HWapproximation_options = Format( "%s,%s", buttonDownApprox, buttonUpApprox) [instance: 1]; HWdensity_options = Format( "%d,%d", buttonDownDensity, buttonUpDensity) [instance: 1]; approximation_options = Switch(renderMode, SWapproximation_options, HWapproximation_options)[instance: 5]; density_options = Switch(renderMode, SWdensity_options, HWdensity_options)[instance: 6]; renderModeString = Switch(renderMode, "software", "hardware")[instance: 7]; annoted_object = Options( object, "send boxes", 0, "rendering approximation", approximation_options, "render every", density_options, "rendering mode", renderModeString) [instance: 1]; NoRECobject, RECobject = Route(RECenable, annoted_object); Display( NoRECobject, camera, where, throttle) [instance: 1]; image = Render( RECobject, camera) [instance: 1]; Display( image, NULL, where, throttle) [instance: 2]; WriteImage( image, RECfile, RECformat) [instance: 1]; } main_Image_1_in_1 = 2; main_Image_1_in_4 = [0 0 -2.98023e-08]; main_Image_1_in_5 = [6.7203 -2.00995 3.76358]; main_Image_1_in_6 = NULL; main_Image_1_in_7 = 378; main_Image_1_in_8 = 0.866; main_Image_1_in_9 = [-0.374816 0.352437 0.857497]; main_Image_1_in_10 = NULL; main_Image_1_in_11 = 2; main_Image_1_in_12 = {"x","y","z"}; main_Image_1_in_13 = 5; main_Image_1_in_14 = {[-1, -1, -1], [1, 1, 1]}; main_Image_1_in_15 = NULL; main_Image_1_in_16 = NULL; main_Image_1_in_17 = NULL; main_Image_1_in_19 = "prettypicture"; main_Image_1_in_20 = NULL; main_Image_1_in_21 = "rgb"; main_Image_1_in_22 = 1; main_Image_1_in_23 = 30.0; main_Image_1_in_24 = 1; main_Image_1_in_25 = "none"; main_Image_1_in_26 = "none"; main_Image_1_in_27 = 1; main_Image_1_in_28 = 1; main_Image_1_in_29 = 1; main_Image_1_in_30 = NULL; main_Image_1_in_31 = NULL; main_Image_1_in_32 = NULL; main_Image_1_in_33 = NULL; main_Image_1_in_34 = NULL; main_Image_1_in_35 = NULL; Executive("product version 2 1 0"); $sync; main();