<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Sprites;
using osuTK;

namespace osu.Framework.Graphics.UserInterface
{
    public class CircularBlob : Sprite
    {
        [BackgroundDependencyLoader]
        private void load(ShaderManager shaders, IRenderer renderer)
        {
            Texture ??= renderer.WhitePixel;
            TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "CircularBlob");
            RoundedTextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "CircularBlobRounded");
        }

        protected override DrawNode CreateDrawNode() => new CircularBlobDrawNode(this);

        private float innerRadius = 0.2f;

        /// <summary>
        /// The inner fill radius, relative to the <see cref="Drawable.DrawSize"/> of the <see cref="CircularBlob"/>.
        /// The value range is 0 to 1 where 0 is invisible and 1 is completely filled.
        /// The entire texture still fills the disk without cropping it.
        /// </summary>
        public float InnerRadius
        {
            get => innerRadius;
            set
            {
                if (!float.IsFinite(value))
                    throw new ArgumentException($"{nameof(InnerRadius)} must be finite, but is {value}.");

                innerRadius = Math.Clamp(value, 0, 1);
                Invalidate(Invalidation.DrawNode);
            }
        }

        private float amplitude = 0.3f;

        public float Amplitude
        {
            get => amplitude;
            set
            {
                if (!float.IsFinite(value))
                    throw new ArgumentException($"{nameof(Amplitude)} must be finite, but is {value}.");

                amplitude = Math.Clamp(value, 0, 1);
                Invalidate(Invalidation.DrawNode);
            }
        }

        private float frequency = 1.5f;

        public float Frequency
        {
            get => frequency;
            set
            {
                if (!float.IsFinite(value))
                    throw new ArgumentException($"{nameof(Frequency)} must be finite, but is {value}.");

                frequency = value;
                Invalidate(Invalidation.DrawNode);
            }
        }

        private int seed = 1;

        public int Seed
        {
            get => seed;
            set
            {
                seed = value;
                Invalidate(Invalidation.DrawNode);
            }
        }

        private class CircularBlobDrawNode : SpriteDrawNode
        {
            public new CircularBlob Source => (CircularBlob)base.Source;

            public CircularBlobDrawNode(CircularBlob source)
                : base(source)
            {
            }

            private float innerRadius;
            private float texelSize;
            private float frequency;
            private float amplitude;
            private Vector2 noisePosition;
            private int seed = -1;

            public override void ApplyState()
            {
                base.ApplyState();

                innerRadius = Source.innerRadius;
                frequency = Source.frequency;
                amplitude = Source.amplitude;

                int newSeed = Source.seed;

                if (seed != newSeed)
                {
                    Random rand = new Random(newSeed);
                    noisePosition = new Vector2((float)(rand.NextDouble() * 100000), (float)(rand.NextDouble() * 100000));
                    seed = newSeed;
                }

                // smoothstep looks too sharp with 1px, let's give it a bit more<commit_msg>Reduce magnitude of noise position uniform<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Sprites;
using osuTK;

namespace osu.Framework.Graphics.UserInterface
{
    public class CircularBlob : Sprite
    {
        [BackgroundDependencyLoader]
        private void load(ShaderManager shaders, IRenderer renderer)
        {
            Texture ??= renderer.WhitePixel;
            TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "CircularBlob");
            RoundedTextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "CircularBlobRounded");
        }

        protected override DrawNode CreateDrawNode() => new CircularBlobDrawNode(this);

        private float innerRadius = 0.2f;

        /// <summary>
        /// The inner fill radius, relative to the <see cref="Drawable.DrawSize"/> of the <see cref="CircularBlob"/>.
        /// The value range is 0 to 1 where 0 is invisible and 1 is completely filled.
        /// The entire texture still fills the disk without cropping it.
        /// </summary>
        public float InnerRadius
        {
            get => innerRadius;
            set
            {
                if (!float.IsFinite(value))
                    throw new ArgumentException($"{nameof(InnerRadius)} must be finite, but is {value}.");

                innerRadius = Math.Clamp(value, 0, 1);
                Invalidate(Invalidation.DrawNode);
            }
        }

        private float amplitude = 0.3f;

        public float Amplitude
        {
            get => amplitude;
            set
            {
                if (!float.IsFinite(value))
                    throw new ArgumentException($"{nameof(Amplitude)} must be finite, but is {value}.");

                amplitude = Math.Clamp(value, 0, 1);
                Invalidate(Invalidation.DrawNode);
            }
        }

        private float frequency = 1.5f;

        public float Frequency
        {
            get => frequency;
            set
            {
                if (!float.IsFinite(value))
                    throw new ArgumentException($"{nameof(Frequency)} must be finite, but is {value}.");

                frequency = value;
                Invalidate(Invalidation.DrawNode);
            }
        }

        private int seed = 1;

        public int Seed
        {
            get => seed;
            set
            {
                seed = value;
                Invalidate(Invalidation.DrawNode);
            }
        }

        private class CircularBlobDrawNode : SpriteDrawNode
        {
            public new CircularBlob Source => (CircularBlob)base.Source;

            public CircularBlobDrawNode(CircularBlob source)
                : base(source)
            {
            }

            private float innerRadius;
            private float texelSize;
            private float frequency;
            private float amplitude;
            private Vector2 noisePosition;
            private int seed = -1;

            public override void ApplyState()
            {
                base.ApplyState();

                innerRadius = Source.innerRadius;
                frequency = Source.frequency;
                amplitude = Source.amplitude;

                int newSeed = Source.seed;

                if (seed != newSeed)
                {
                    Random rand = new Random(newSeed);
                    noisePosition = new Vector2((float)(rand.NextDouble() * 1000), (float)(rand.NextDouble() * 1000));
                    seed = newSeed;
                }

                // smoothstep looks too sharp with 1px, let's give it a bit more
{'fraction_non_alphanumeric': 0.08442315162501618, 'fraction_numerical': 0.008027968406059821, 'mean_word_length': 1.5954301075268817, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5039394', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1840, 'n_words': 536}