(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



(* :Name: PwM`Chap11Dynamic` *)


(* :Book: Programming with Mathematica: An Introduction *)


(* :Author: Paul Wellin *)


(* :Summary: This package contains the functions defined in Chapter 11, Dynamic expressions. *)


(* :Context: PwM`Chap11Dynamic` *)


(* :Package Version: 1.0 *)


(* :Copyright: Copyright 2012, Cambridge University Press *)


(* :History: Version 1.0 by Paul Wellin, Dec 2012 *)


(* :Keywords: Amino acid plot, epicycloid, hypocycloid *)


(* :Source: Chap11Dynamic.nb *)


(* :Mathematica Version: 8.0.4 *)


Remove[AminoAcidPlot,HypocycloidPlot]


BeginPackage["PwM`Chap11Dynamic`"]


AminoAcidPlot::usage="AminoAcidPlot[\!\(\*
StyleBox[\"aa\", \"TI\"]\)] plots the amino acid \!\(\*
StyleBox[\"aa\", \"TI\"]\) as a colored structure diagram. A second argument can be given to specify a different visualization, including \"StructureDiagram\", \"CHColorStructureDiagram\", \"CHStructureDiagram\", \"ColorStructureDiagram\", \"MoleculePlot\", \"SpaceFillingMoleculePlot\".";


EpicycloidPlot::usage="EpicycloidPlot[\!\(\*
StyleBox[\"R\", \"TI\"]\)\!\(\*
StyleBox[\",\", \"TI\"]\)\!\(\*
StyleBox[\" \", \"TI\"]\)\!\(\*
StyleBox[\"r\", \"TI\"]\)\!\(\*
StyleBox[\",\", \"TI\"]\)\!\(\*
StyleBox[\" \", \"TI\"]\)\!\(\*
StyleBox[\"\[Theta]\", \"TI\"]\)] displays a plot of a epicycloid generated by rolling a circle of radius \!\(\*
StyleBox[\"r\", \"TI\"]\) outside of a fixed circle of radius \!\(\*
StyleBox[\"R\", \"TI\"]\). The angle \[Theta] is the parameter that determines how far along the curve to sketch.";


HypocycloidPlot::usage="HypocycloidPlot[\!\(\*
StyleBox[\"R\", \"TI\"]\)\!\(\*
StyleBox[\",\", \"TI\"]\)\!\(\*
StyleBox[\" \", \"TI\"]\)\!\(\*
StyleBox[\"r\", \"TI\"]\)\!\(\*
StyleBox[\",\", \"TI\"]\)\!\(\*
StyleBox[\" \", \"TI\"]\)\!\(\*
StyleBox[\"\[Theta]\", \"TI\"]\)] displays a plot of a hypocycloid generated by rolling a circle of radius \!\(\*
StyleBox[\"r\", \"TI\"]\) inside of a fixed circle of radius \!\(\*
StyleBox[\"R\", \"TI\"]\). The angle \[Theta] is the parameter that determines how far along the curve to sketch.";


Begin["`Private`"]


AminoAcidPlot[aa_String,diagram_:"ColorStructureDiagram"]:=Labeled[Framed[ChemicalData[aa,diagram],ImageSize->All],ChemicalData[aa,"Name"],LabelStyle->Directive["Menu",9]]


EpicycloidPlot[R_,r_,\[Theta]_]:=Module[{epicycloid,center},
epicycloid[{a_,b_},t_]:={(a+b)Cos[t]-b Cos[t (a+b)/b],(a+b)Sin[t]+b Sin[t (a+b)/b]};center[th_,R1_,r2_]:=(R1+r2){Cos[th],Sin[th]};
Show[{
ParametricPlot[epicycloid[{R,r},t],{t,0,\[Theta]},PlotStyle->Red,Axes->None],
Graphics[{
{Blue,Thick,Circle[{0,0},R]},
{Circle[center[\[Theta],R,r],r]},
{PointSize[.015],Point[center[\[Theta],R,r]]},
{Thick,Line[{center[\[Theta],R,r],epicycloid[{R,r},\[Theta]]}]},
{Red,PointSize[.015],Point[epicycloid[{R,r},\[Theta]]]}
}]},PlotRange->1.5(R+r),GridLines->Automatic]]


HypocycloidPlot[R_,r_,\[Theta]_]:=Module[{hypocycloid,center},hypocycloid[{a_,b_},t_]:={(a-b) Cos[t]+b Cos[(t (a-b))/b],(a-b) Sin[t]-b Sin[(t (a-b))/b]};

center[th_,R1_,r2_]:=(R1-r2) {Cos[th],Sin[th]};

Show[{ParametricPlot[hypocycloid[{R,r},t],{t,0,\[Theta]},PlotStyle->Red,Axes->None],

Graphics[{{Blue,Thick,Circle[{0,0},R]},{Circle[center[\[Theta],R,r],r]},{PointSize[.02],Point[center[\[Theta],R,r]]},{Thick,Line[{center[\[Theta],R,r],hypocycloid[{R,r},\[Theta]]}]},{Red,PointSize[.02],Point[hypocycloid[{R,r},\[Theta]]]}}]},

PlotRange->All,GridLines->Automatic]
]


End[]


EndPackage[]



