Re: ciphers and programming style
- To: mathgroup at smc.vnet.net
- Subject: [mg13349] Re: [mg13274] ciphers and programming style
- From: Carl Woll <carlw at fermi.phys.washington.edu>
- Date: Mon, 20 Jul 1998 02:50:04 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Hi Tom, One simple thing you could do is to use := instead of = in your definitions of the letters, e.g., f:=Graphics[{Circle[{0,0},1], Line[{pts[[3]], pts[[5]]}], Line[{pts[[4]], pts[[2]]}]},AspectRatio->Automatic]; Now, when you change rotate pts, f will use the latest value of pts. You may want to turn this into a function. f[pts_] := Graphics[{Circle[{0,0},1], Line[{pts[[3]], pts[[5]]}], Line[{pts[[4]], pts[[2]]}]},AspectRatio->Automatic]; Then, if you rotate your original pts with rpts=Transpose[{{0,1},{-1,0}}.Transpose[pts]] and try f[rpts] you should get a graphic of the rotated f. Carl Woll Dept of Physics U of Washington On Fri, 17 Jul 1998, Tom wrote: > Hello Mathematica users. > > I recently worked on a simple set of definitions to produce a cipher. A > cipher uses pictures to represent the letters of the alphabet. This > cipher was used in one of the books about "The Shadow". Once the basic > pictures were created, in order to disguise the code, they could be > rotated by 90 degrees or 180 degrees, and so on. This would provide > practice in the application of transformations to geometric figures, a > topic in high school geometry. I would give the basic cipher, then > give the students a code to decipher where all the letters in the basic > cipher were rotated by 90 degrees or 180 degrees or something like > that. > > I managed to get this all to work, but I learned some things that I > didn't know before, and I wondered if someone could help me "clean up" > my efforts somewhat? > > All the letters in the cipher are based on circles with various lines > from the center of the circle to points on the circle. For example, > here is what the letter "k" looks like. > > > k=Graphics[{Circle[{0,0},1], Line[{{0,1},{0,0},{1,0}}]}, > AspectRatio->Automatic]; > > > Show[k]; > > I wanted to be able to put all the letters into a graphics array at the > end, so that is why I used AspectRatio->Automatic > > Since I would be using the same points on the circle for all the letters > (in various forms) and I also thought it would make it easier to rotate > the letter forms, I created a list of points. Here is part of the > list. > > > pts={{0,0},{1,0},{0,1},{-1,0},{0,-1}}; > > So now, I can create letters based on these points. Below are my > definitions of f,g,k and l > > > f=Graphics[{Circle[{0,0},1], > Line[{pts[[3]], pts[[5]]}], > Line[{pts[[4]], pts[[2]]}]},AspectRatio->Automatic]; > > > g=Graphics[{Circle[{0,0},1], > Line[{pts[[3]], pts[[5]]}]},AspectRatio->Automatic]; > > > k=Graphics[{Circle[{0,0},1], > Line[{pts[[3]],pts[[1]], pts[[2]] }]},AspectRatio->Automatic]; > > l=Graphics[{Circle[{0,0},1], > Line[{pts[[3]],pts[[1]], pts[[4]] }]},AspectRatio->Automatic]; > > > Show[GraphicsArray[{f,g,k,l}]]; > > So far, so good..... > > I then found I could rotate all my "letters" 90 degrees by rotating my > list of points by 90 degrees. I used the rotation matrix > {{0,1},{-1,0}} Here is my original list of points again > > pts={{0,0},{1,0},{0,1},{-1,0},{0,-1}}; > > Using dot product..... > > pts=Transpose[{{0,1},{-1,0}}.Transpose[pts]] > > {{0,0},{0,-1},{1,0},{0,1},{-1,0}} > > So I did get a list of points, rotated through 90 degrees. (Clockwise) > Here is where things got messy. > > First of all, I realized I now messed up my original list of points. > And secondly, I found, to my astonishment, that Mathematica still used > the OLD VALUE of pts when drawing the letters. I probably read this > somewhere and "knew" it but I had not experienced it before. > > > Show[GraphicsArray[{f,g,k,l}]]; > > The letters are not rotated. So, I needed to redefine the letters and > then redraw them. SO I redefined the letters and then > > > Show[GraphicsArray[{f,g,k,l}]]; > > There they are..... After I redefined the definitions of f,g,k and l. > Things work fine. The question is, how might I have done this more > elegantly? Not having any programming background I would appreciate > any pointers on how I might have implemeted this more nicely. Thanks > for any assistance you might provide. > > Sincerely, > > Tom >