This tutorial demonstrates how to use radial gradients, custom colors, transparency.
Requires ROOT built for OS X with –enable-cocoa.
#include <cassert>
#include <cstdlib>
namespace {
{
{1., 0., 0., 1.},
{1., 0.3, 0., 1.},
{0., 0., 1., 1.},
{1., 1., 0., 1.},
{1., 0., 1., 1.},
{0., 1., 1., 1.},
{0., 1., 0., 1.},
{0., 0.5, 0., 1.},
{1., 0., 0., 0.5},
{1., 0.3, 0., 0.5},
{0., 0., 1., 0.5},
{1., 1., 0., 0.5},
{1., 0., 1., 0.5},
{0., 1., 1., 0.5},
{0., 1., 0., 0.5},
{0., 0.5, 0., 0.5},
{1., 0., 0., 0.2},
{1., 0.3, 0., 0.2},
{0., 0., 1., 0.2},
{1., 1., 0., 0.2},
{1., 0., 1., 0.2},
{0., 1., 1., 0.2},
{0., 1., 0., 0.2},
{0., 0.5, 0., 0.2}
};
const unsigned nBasicColors = sizeof basicColors / sizeof basicColors[0];
{
return -1;
const Double_t *
const fromRGBA = basicColors[(std::rand() % (nBasicColors / 2))];
const Double_t *
const toRGBA = basicColors[nBasicColors / 2 + (std::rand() % (nBasicColors / 2))];
const Double_t rgbas[] = {fromRGBA[0], fromRGBA[1], fromRGBA[2], fromRGBA[3],
toRGBA[0], toRGBA[1], toRGBA[2], toRGBA[3]};
return idx[0];
}
{
assert(
gPad !=
nullptr &&
"add_ellipse, no pad to add ellipse");
const Color_t newColor = CreateRandomGradientFill();
if (newColor == -1) {
::Error(
"add_ellipse",
"failed to find a new color index for a gradient fill");
return false;
}
return true;
}
}
void radialgradients()
{
TCanvas *
const cnv =
new TCanvas(
"radial gradients",
"radial gradients", 800, 800);
"this demo requires OS X and ROOT built with --enable-cocoa");
delete cnv;
return;
}
for (unsigned i = 0; i < 100; ++i)
break;
}
void Error(const char *location, const char *msgfmt,...)
R__EXTERN TRandom * gRandom
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void Update()
Update canvas pad buffers.
virtual void Draw(Option_t *option="")
Draw this ellipse with its current attributes.
void Modified(Bool_t flag=1)
Define a radial color gradient.
void SetRadialGradient(const Point ¢er, Double_t radius)
Set radial gradient.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
virtual Double_t Rndm()
Machine independent random number generator.
unsigned FindFreeCustomColorIndices(Color_t(&indices)[N])
- Author
- Timur Pocheptsov
Definition in file radialgradients.C.