Brush that uses 3D perlin noise to create "cloudy" patterns.
Inheritance: IBrush, IBrushInstance
示例#1
0
 public CloudyBrush(CloudyBrush other)
 {
     Blocks      = other.Blocks;
     BlockRatios = other.BlockRatios;
     Seed        = other.Seed;
     Frequency   = other.Frequency;
     Octaves     = other.Octaves;
     Persistence = other.Persistence;
 }
示例#2
0
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            bool scaleSpecified = false,
                 turbulenceSpecified = false,
                 seedSpecified = false;
            int scale = 100,
                turbulence = 100;
            UInt16 seed = CloudyBrush.NextSeed();

            while( true ) {
                int offset = cmd.Offset;
                string rawNextParam = cmd.Next();
                if( rawNextParam == null ) break;

                if( rawNextParam.EndsWith( "%" ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    int tempScale;
                    if( !Int32.TryParse( numPart, out tempScale ) ) {
                        player.Message( "Cloudy brush: To specify scale, write a number followed by a percentage (e.g. 100%)." );
                        return null;
                    }
                    if( scaleSpecified ) {
                        player.Message( "Cloudy brush: Scale has been specified twice." );
                        return null;
                    }
                    if( scale < 1 || tempScale > CloudyBrush.MaxScale ) {
                        player.Message( "Cloudy brush: Invalid scale ({0}). Must be between 1 and {1}",
                                        scale, CloudyBrush.MaxScale );
                        return null;
                    }
                    scale = tempScale;
                    scaleSpecified = true;
                    continue;

                } else if( rawNextParam.EndsWith( "T", StringComparison.OrdinalIgnoreCase ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    int tempTurbulence;
                    if( Int32.TryParse( numPart, out tempTurbulence ) ) {
                        if( turbulenceSpecified ) {
                            player.Message( "Cloudy brush: Turbulence has been specified twice." );
                            return null;
                        }
                        if( turbulence < 1 || tempTurbulence > CloudyBrush.MaxScale ) {
                            player.Message( "Cloudy brush: Invalid turbulence ({0}). Must be between 1 and {1}",
                                            turbulence, CloudyBrush.MaxScale );
                            return null;
                        }
                        turbulence = tempTurbulence;
                        turbulenceSpecified = true;
                        continue;
                    }

                } else if( rawNextParam.EndsWith( "S", StringComparison.OrdinalIgnoreCase ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    try {
                        seed = UInt16.Parse( numPart, System.Globalization.NumberStyles.HexNumber );
                        if( seedSpecified ) {
                            player.Message( "Cloudy brush: Seed has been specified twice." );
                            return null;
                        }
                        seedSpecified = true;
                        continue;
                    } catch {
                        seed = CloudyBrush.NextSeed();
                    }
                }

                cmd.Offset = offset;
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( ratio < 1 || ratio > CloudyBrush.MaxRatio ) {
                    player.Message( "Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                    ratio, CloudyBrush.MaxRatio );
                    return null;
                }
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            CloudyBrush madeBrush;
            if( blocks.Count == 0 ) {
                madeBrush = new CloudyBrush();
            } else if( blocks.Count == 1 ) {
                madeBrush = new CloudyBrush( blocks[0], blockRatios[0] );
            } else {
                madeBrush = new CloudyBrush( blocks.ToArray(), blockRatios.ToArray() );
            }

            madeBrush.Frequency /= ( scale / 100f );
            madeBrush.Persistence *= ( turbulence / 100f );
            madeBrush.Seed = seed;

            return madeBrush;
        }
示例#3
0
 public CloudyBrush( CloudyBrush other ) {
     Blocks = other.Blocks;
     BlockRatios = other.BlockRatios;
     Seed = other.Seed;
     Frequency = other.Frequency;
     Octaves = other.Octaves;
     Persistence = other.Persistence;
 }
示例#4
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            List <Block> blocks              = new List <Block>();
            List <int>   blockRatios         = new List <int>();
            bool         scaleSpecified      = false,
                         turbulenceSpecified = false,
                         seedSpecified       = false;
            int scale      = 100,
                turbulence = 100;
            UInt16 seed    = CloudyBrush.NextSeed();

            while (true)
            {
                int    offset       = cmd.Offset;
                string rawNextParam = cmd.Next();
                if (rawNextParam == null)
                {
                    break;
                }

                if (rawNextParam.EndsWith("%"))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    int    tempScale;
                    if (!Int32.TryParse(numPart, out tempScale))
                    {
                        player.Message("Cloudy brush: To specify scale, write a number followed by a percentage (e.g. 100%).");
                        return(null);
                    }
                    if (scaleSpecified)
                    {
                        player.Message("Cloudy brush: Scale has been specified twice.");
                        return(null);
                    }
                    if (scale < 1 || tempScale > CloudyBrush.MaxScale)
                    {
                        player.Message("Cloudy brush: Invalid scale ({0}). Must be between 1 and {1}",
                                       scale, CloudyBrush.MaxScale);
                        return(null);
                    }
                    scale          = tempScale;
                    scaleSpecified = true;
                    continue;
                }
                else if (rawNextParam.EndsWith("T", StringComparison.OrdinalIgnoreCase))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    int    tempTurbulence;
                    if (Int32.TryParse(numPart, out tempTurbulence))
                    {
                        if (turbulenceSpecified)
                        {
                            player.Message("Cloudy brush: Turbulence has been specified twice.");
                            return(null);
                        }
                        if (turbulence < 1 || tempTurbulence > CloudyBrush.MaxScale)
                        {
                            player.Message("Cloudy brush: Invalid turbulence ({0}). Must be between 1 and {1}",
                                           turbulence, CloudyBrush.MaxScale);
                            return(null);
                        }
                        turbulence          = tempTurbulence;
                        turbulenceSpecified = true;
                        continue;
                    }
                }
                else if (rawNextParam.EndsWith("S", StringComparison.OrdinalIgnoreCase))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    try {
                        seed = UInt16.Parse(numPart, System.Globalization.NumberStyles.HexNumber);
                        if (seedSpecified)
                        {
                            player.Message("Cloudy brush: Seed has been specified twice.");
                            return(null);
                        }
                        seedSpecified = true;
                        continue;
                    } catch {
                        seed = CloudyBrush.NextSeed();
                    }
                }

                cmd.Offset = offset;
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 1 || ratio > CloudyBrush.MaxRatio)
                {
                    player.Message("Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio, CloudyBrush.MaxRatio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            CloudyBrush madeBrush;

            if (blocks.Count == 0)
            {
                madeBrush = new CloudyBrush();
            }
            else if (blocks.Count == 1)
            {
                madeBrush = new CloudyBrush(blocks[0], blockRatios[0]);
            }
            else
            {
                madeBrush = new CloudyBrush(blocks.ToArray(), blockRatios.ToArray());
            }

            madeBrush.Frequency   /= (scale / 100f);
            madeBrush.Persistence *= (turbulence / 100f);
            madeBrush.Seed         = seed;

            return(madeBrush);
        }