Re: Trouble Getting Graphic Primitives in a Module to Display with Show Command
- To: mathgroup at smc.vnet.net
- Subject: [mg125418] Re: Trouble Getting Graphic Primitives in a Module to Display with Show Command
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Tue, 13 Mar 2012 03:04:47 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Remove the last semi-colon after the sketchEarthOrbit[] call. You are suppressing the display. Bob Hanlon On Mon, Mar 12, 2012 at 5:08 AM, Kenneth Bures <kenbures at gmail.com> wrote: > I have been trying to display graphics primitives (lines, circles) > from inside a module, but I can't get it to work. If you have Nancy > Blachman's book, MATHEMATICA: A Practical Approach, 2nd Edition, she > gives an example on page 399 of a 4-line module that generates 3 > graphics objects and then has a Show command (inside the module) to > display them. I've listed the code below. The book illustrates that > when you call this module from the main program with the instruction > sketchEarthOrbit[] it displays the 3 graphics objects. When I copy > this program exactly, it does not work. I get no output. If I cut & > paste the exact four lines of code to outside of the module, they do > display the desired result, so there seems to be is something wrong > with her basic approach. > > Why doesn't this example work? Actually, what I would really like to > do is pass the graphics objects out of the module, and display them > from the main program, rather than having the Show inside the module. > But I decided that I should understand what is wrong with Blachman's > approach before I spend too much time on the other. Any help would be > appreciated, either with explaining Blachman's approach and/or how to > transfer graphics objects out of a module. > > Here is Blachman's code (I put the Clear command there): > > Clear[sketchEarthOrbit]; > sketchEarthOrbit[] :== > Module[{earth, sun, orbit}, > earth == > Graphics[{ Disk[{-.7, .35}, 0.05], Text["Earth", {-.7, .45}] }]; > sun == Graphics[{ Disk[{.3, 0}, 0.1], Text["Sun", {.3, .17}] }]; > orbit == Graphics[{ Circle[{0, 0}, {1., .5}] }]; > Show[orbit, sun, earth, AspectRatio -> Automatic] > ]; > sketchEarthOrbit[]; >