3

是否可以使用TogglerBar 而不是 2 Check Box来显示或不显示不同的形状。

在 TogglerBar 的每个按钮中都写有绿色和红色?

Manipulate[
Graphics[{If[thePink, {Pink, Disk[{5, 5}, 3]}], 
If[theGreen, {Green, Disk[{15, 2}, 1]}]}, 
PlotRange -> {{0, 20}, {0, 10}}], {{thePink, True, 
Style["Pink", Black, Bold, 12]}, {True, False}}, {{theGreen, True, 
Style["Green", Black, Bold, 12]}, {True, False}}]

在此处输入图像描述

我正在尝试调整的实际 Manipulate 对象可以在此处找到:http ://www.laeh500.com/LAEH/COG.html 目的是用漂亮的 TogglerBar 替换 CheckBox。

4

3 回答 3

3

像这样?

Manipulate[
 Graphics[{
   {White, Circle[{5, 5}, r]},  (* For Mma 7 compatibility*) 
   If[MemberQ[color, "Red"],   {Pink, Disk[{5, 5}, r]}],
   If[MemberQ[color, "Green"], {Green, Disk[{4, 2}, r]}]},
 PlotRange -> {{0, 20}, {0, 10}}],
 {{r, 1, "Radius"}, 1, 5, 1, ControlType -> Setter},
 {{color, "Red", "Color"}, {"Red", "Green"}, ControlType -> TogglerBar}, 
LabelStyle -> Large]

在此处输入图像描述

编辑

回答您的评论,我认为您的笔记本可以从这样的模板中受益:

Manipulate[
 Graphics[
  {
   {White, Circle[{5, 5}, r]},(* For Mma 7 compatibility*) 
   If[MemberQ[whatToDisplay, "Circle"], {Red,   Circle   [{5, 5}, r]}],
   If[MemberQ[whatToDisplay, "Square"], {Blue,  Rectangle[{5, 5}, {r, r}]}],
   If[MemberQ[whatToDisplay, "Other"],  {Black, Line     [Tuples[{3, 4}, 2]]}],
  },
 PlotRange -> {{0, 20}, {0, 10}}
 ], 
  (* Controls follow *)
  {{r, 1,  Style["Radius", Black, Bold, 12]}, 1, 5, 1, ControlType     -> Slider
                                                     , ControlPlacement-> Top
  },  
  Control@{{whatToDisplay, True, Style["What", Black, Bold, 12]}, 
           {"Circle", "Square", "Other"}, 
           ControlType      -> TogglerBar,
           Appearance       -> "Vertical",
           ControlPlacement -> Left
  }
]

在此处输入图像描述

于 2011-06-09T21:19:01.187 回答
3

这个怎么样?

Manipulate[
 Show[Graphics[myObject], 
  PlotRange -> {{0, 20}, {0, 10}}], {{myObject, {},""}, {{Pink, 
     Disk[{5, 5}, 3]} -> 
    Style["Pink", Black, Bold, 12], {Green, Disk[{15, 2}, 1]} -> 
    Style["Green", Black, Bold, 12]}}, ControlType -> TogglerBar]
于 2011-06-09T21:34:01.690 回答
2

怎么样

Manipulate[
Graphics[{#} & /@ x,
    PlotRange -> {{0, 20}, {0, 10}}],
{{x, {}, "Colour"},
{{Pink, Disk[{5, 5}, 3]} \[Rule] "Pink",
{Green, Disk[{15, 2}, 1]} \[Rule] "Green"},
ControlType -> TogglerBar}]

不过,它又丑又不雅!动态操作不是我最喜欢的 Mathematica 用途,所以这对我来说也是一种反复试验......

编辑:现在稍微不那么难看了...... EDIT2:添加了一个标签

于 2011-06-09T21:21:32.107 回答