![]() |
|
Navigation |
Synopsis Drawing a box in many variations.
Examples Drawing a red Rascal:box is as simple as this:
import vis::Figure; import vis::Render; b = box(fillColor("red")); render(b);and it will look like this: ![]() ![]() Wow, the box fills the whole window! So lets give our box a Rascal:size: import vis::Figure; import vis::Render; b = box(fillColor("red"), size(200,100)); render(b);and it will look like this: ![]() On screen however, it still fills the whole window as shown above. The lesson here is that size is to be taken as minimum size (and probably we should rename size to minSize to emphasize this).
So how can we produce a box that does not fill the whole window? The answer is to define the size of the box relative to its surroundings by using Rascal:shrink: import vis::Figure; import vis::Render; b = box(fillColor("red"), shrink(0.5)); render(b);which says: I am a red box and I want to occupy 50% of the available space. The result is: ![]() Shrinking can also be limited to one dimension using Rascal:hshrink or Rascal:vshrink: import vis::Figure; import vis::Render; b = box(fillColor("red"), hshrink(0.5)); render(b);which says: I am a red box and I want to occupy 50% of the available space in the horizontal direction and 100% of the available space in the vertical direction. The result is: ![]() Relative sizes can also be used when figures are nested. import vis::Figure; import vis::Render; b1 = box(fillColor("red"), hshrink(0.5)); b2 = box(b1, fillColor("yellow"), size(200,100)); render(b2); ![]()
Pitfalls In the above examples we have consistently added the two imports:
import vis::Figure; import vis::Render;In other recipes and the Rascal documentation we omit these two imports to avoid cluttering our examples with irrelevant details. Be aware that you will always need them when creating a visualisation. ![]() |