1
$\begingroup$
  1. How does one get TabView to specify the colour of the Polygon?

  2. How does one put a label on the slider: label => "number of sides = {}".

    DynamicModule[{p, colour},
     {
      Dynamic[Graphics[{colour, Polygon[CirclePoints[p]]}]],
    
      Slider[Dynamic[p], {3, 17, 1}, Appearance -> "Labeled"],
    
      Dynamic[TabView[{colour -> Green, colour -> Orange}]]
    
    }]
    

Note: Detailed Explanations welcome. Im a determined beginner. Does it have something to do with the way TabView interacts with Set?

$\endgroup$
0

3 Answers 3

3
$\begingroup$

TabView is for viewing. You can associate color changes with the second argument of TabView but it will be easier to just use what is designed for that, like SetterBar.

Moreover, the less inside Dynamic the better so instead of creating whole Graphics you can just tell the FrontEnd to take care of that colour and Polygon.

DynamicModule[{p = 3, colour = Green}
 ,
 Column @ {
   Graphics[{
     Dynamic@colour,
     Dynamic@Polygon[CirclePoints[p]]
     }, PlotRange -> 1
   ],
   Row[{
     Slider[Dynamic[p], {3, 17, 1}],
     "number of sides = {", Dynamic@p, "}"
     }, Spacer[5]
   ],
   SetterBar[Dynamic@colour, {Red, Green, Orange}]
}]

enter image description here

$\endgroup$
3
$\begingroup$

I believe this is the natural and idiomatic way to do it:

Manipulate[Graphics[{colour, Polygon[CirclePoints[sides]]}], 
           {sides, 3, 17, 1},
           {{colour, Orange}, {Green -> "Green", Orange -> "Orange"}} ]

Mathematica graphics

$\endgroup$
3
  • 1
    $\begingroup$ The guy is trying to use DynamicModule, don't put him off the right path! :) $\endgroup$
    – Kuba
    Jan 21, 2016 at 8:43
  • 1
    $\begingroup$ @Kuba Are you the same Kuba who posted that entangled solution above? :D $\endgroup$ Jan 21, 2016 at 8:45
  • 1
    $\begingroup$ Yep :) I think Manipulate is ok if you are not going to care about details and your apps are going to be relatively small. Otherwise habits from extensive use of Manipulate will drive you crazy :) And you know that! :) $\endgroup$
    – Kuba
    Jan 21, 2016 at 8:48
3
$\begingroup$

This is more or less directly cribbed from the help:

Manipulate[Graphics[{color, Polygon[CirclePoints[sides]]}],
{{sides, 3,"Number of Sides"}, 3, 17, 1}, {color, Green}]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.