mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
GraphicsDemo: Add new demo showing blur and transparency effects
This commit is contained in:
parent
c3e8b6bff3
commit
da45497a3d
1 changed files with 77 additions and 0 deletions
|
|
@ -516,6 +516,82 @@ public:
|
||||||
std::unique_ptr<Drawable> svgDrawable;
|
std::unique_ptr<Drawable> svgDrawable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BlurDemo final : public GraphicsDemoBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BlurDemo (ControllersComponent& cc)
|
||||||
|
: GraphicsDemoBase (cc, "Blur")
|
||||||
|
{
|
||||||
|
image.setBackupEnabled (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawDemo (Graphics& g) override
|
||||||
|
{
|
||||||
|
const auto a = lopassA.next (jmap (frequencyA.getValue(), 0.09f, 0.12f));
|
||||||
|
const auto b = lopassB.next (jmap (frequencyB.getValue(), 0.09f, 0.12f));
|
||||||
|
|
||||||
|
initialPhase += 0.01f;
|
||||||
|
initialPhase -= (float) (int) initialPhase;
|
||||||
|
const auto startAngle = initialPhase * MathConstants<float>::twoPi;
|
||||||
|
const auto centreSquare = image.getBounds().reduced (100);
|
||||||
|
|
||||||
|
{
|
||||||
|
Graphics g2 { image };
|
||||||
|
g2.setColour (Colours::transparentBlack);
|
||||||
|
g2.excludeClipRegion (centreSquare);
|
||||||
|
g2.getInternalContext().fillRect (image.getBounds(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto ptr = image.getClippedImage (centreSquare).getPixelData())
|
||||||
|
{
|
||||||
|
ptr->applyGaussianBlurEffect (7.0f);
|
||||||
|
ptr->multiplyAllAlphas (0.98f);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Graphics g2 { image };
|
||||||
|
const auto baseColour = Colours::cyan;
|
||||||
|
const auto destColour = Colours::magenta;
|
||||||
|
const auto offset = image.getBounds().getCentre().toFloat();
|
||||||
|
const auto numSegments = 200;
|
||||||
|
|
||||||
|
for (auto i = 0; i < numSegments; ++i)
|
||||||
|
{
|
||||||
|
g2.setColour (baseColour.interpolatedWith (destColour, (float) i / numSegments));
|
||||||
|
|
||||||
|
const auto getPoint = [&] (auto ind)
|
||||||
|
{
|
||||||
|
return offset + Point { 200 * std::sin (startAngle + a * (float) ind),
|
||||||
|
200 * std::cos (startAngle + b * (float) ind) };
|
||||||
|
};
|
||||||
|
|
||||||
|
g2.drawLine ({ getPoint (i), getPoint (i + 1) }, 2.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AffineTransform transform (AffineTransform::translation ((float) (-image.getWidth() / 2),
|
||||||
|
(float) (-image.getHeight() / 2))
|
||||||
|
.followedBy (getTransform()));
|
||||||
|
|
||||||
|
g.setOpacity (getAlpha());
|
||||||
|
g.drawImageTransformed (image, transform, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Lopass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float next (float f) { return value += (f - value) * 0.05f; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
float value{};
|
||||||
|
};
|
||||||
|
|
||||||
|
Image image { Image::ARGB, 512, 512, true };
|
||||||
|
SlowerBouncingNumber frequencyA, frequencyB;
|
||||||
|
Lopass lopassA, lopassB;
|
||||||
|
float initialPhase = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
class LinesDemo final : public GraphicsDemoBase
|
class LinesDemo final : public GraphicsDemoBase
|
||||||
{
|
{
|
||||||
|
|
@ -687,6 +763,7 @@ public:
|
||||||
demos.add (new ImagesRenderingDemo (controls, false, true));
|
demos.add (new ImagesRenderingDemo (controls, false, true));
|
||||||
demos.add (new ImagesRenderingDemo (controls, true, false));
|
demos.add (new ImagesRenderingDemo (controls, true, false));
|
||||||
demos.add (new ImagesRenderingDemo (controls, true, true));
|
demos.add (new ImagesRenderingDemo (controls, true, true));
|
||||||
|
demos.add (new BlurDemo (controls));
|
||||||
demos.add (new GlyphsDemo (controls));
|
demos.add (new GlyphsDemo (controls));
|
||||||
demos.add (new SVGDemo (controls));
|
demos.add (new SVGDemo (controls));
|
||||||
demos.add (new LinesDemo (controls));
|
demos.add (new LinesDemo (controls));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue