How can I draw an half or a third filled rectangle? I want to make one rectangle frame with a unity width and then filled it according to a value between 0 and 1.
2 Answers
$\begingroup$
$\endgroup$
1
Graphics[{EdgeForm[Thick], White, Rectangle[], Black, Rectangle[{0, 0}, {1, 0.5}]}]
Or indeed, if you want to be able to change the filling dynamically, you can wrap a manipulate around it.
Manipulate[
Graphics[{EdgeForm[Thick], White, Rectangle[], Black,
Rectangle[{0, 0}, {1, a}]}], {a, 0, 1, 0.05}]
-
$\begingroup$ Thanks! That's exactly what I need. $\endgroup$– MiguelCommented Jul 15, 2016 at 10:35
$\begingroup$
$\endgroup$
1
For fun
Example
DynamicModule[
{fill},
fill = .5;
Panel @ Column[{
Slider[Dynamic @ fill, {0, 1}],
Graphics[{
{FaceForm @ White, EdgeForm @ {Thick, Black}, Rectangle[{0, 0}]},
{FaceForm @ Black, Rectangle[{0, 0}, {1, Dynamic @ fill}]}
}]
},
Alignment -> Center]
]
Output
-
$\begingroup$ +1 because it is a less taxing dynamic routine, and I agree that Mathematica is fun. $\endgroup$– FeyreCommented Jul 15, 2016 at 10:44
EdgeForm
andFaceForm
and draw two rectangles. $\endgroup$VertexColors
for aPolygon
. $\endgroup$