Re: How to roll up multiple Line calls into a loop
- To: mathgroup at smc.vnet.net
- Subject: [mg118346] Re: How to roll up multiple Line calls into a loop
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Sat, 23 Apr 2011 07:50:55 -0400 (EDT)
- References: <iorih5$o6t$1@smc.vnet.net>
Am 22.04.2011 11:41, schrieb Sol Lederman: > Hi, > > I'm new to Mathematica. > > I have the following bit of graphics: > > Graphics[{ > Line[{{0, 10}, {1, 0}}], > Line[{{0, 9}, {2, 0}}], > Line[{{0, 8}, {3, 0}}], > Line[{{0, 7}, {4, 0}}], > Line[{{0, 6}, {5, 0}}], > Line[{{0, 5}, {6, 0}}], > Line[{{0, 4}, {7, 0}}], > Line[{{0, 3}, {8, 0}}], > Line[{{0, 2}, {9, 0}}], > Line[{{0, 1}, {10, 0}}], > }] > > > I want to simplify it to do some sort of iteration to compute the end points > of the lines. I can do this easily in a variety of procedural languages but > I haven't yet grokked how Mathematica would do this. Well, you need to tell Mathematica how to do this... > Would someone please show me the short way, I imagine using Table somehow? ... this is one way, as you imagined, Table seems to be an adequat starting point: Graphics[Table[Line[{{0, 11 - i}, {i, 0}}], {i, 10}]] Here is something somewhat more elaborated: Manipulate[ Graphics[ Line[Table[{{0, n - i + 1}, {i, 0}}, {i, n}]], ImageSize -> {300,300} ], {n, 5, 100} ] note that Line will accept a list of line definitions as the argument, which is somewhat more efficient when showing many lines. For graphics within a manipulate you almost always want to set an explict ImageSize or PlotRange. hth, albert