private void Validate(string pattern, string expectedPattern, PatternType expectedType)
        {
            var result = resolver.Resolve(pattern);

            result.Pattern.Should().Be(expectedPattern);
            result.Type.Should().Be(expectedType);
        }
Example #2
0
        public DistanceObjectPatternGenerator(FastRandom random, HitObject hitObject, ManiaBeatmap beatmap, Pattern previousPattern, IBeatmap originalBeatmap)
            : base(random, hitObject, beatmap, previousPattern, originalBeatmap)
        {
            convertType = PatternType.None;
            if (!Beatmap.ControlPointInfo.EffectPointAt(hitObject.StartTime).KiaiMode)
            {
                convertType = PatternType.LowProbability;
            }

            var distanceData = hitObject as IHasDistance;
            var repeatsData  = hitObject as IHasRepeats;

            spanCount = repeatsData?.SpanCount() ?? 1;

            TimingControlPoint     timingPoint     = beatmap.ControlPointInfo.TimingPointAt(hitObject.StartTime);
            DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(hitObject.StartTime);

            // The true distance, accounting for any repeats
            double distance = (distanceData?.Distance ?? 0) * spanCount;
            // The velocity of the osu! hit object - calculated as the velocity of a slider
            double osuVelocity = osu_base_scoring_distance * beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier / timingPoint.BeatLength;
            // The duration of the osu! hit object
            double osuDuration = distance / osuVelocity;

            EndTime         = hitObject.StartTime + osuDuration;
            SegmentDuration = (EndTime - HitObject.StartTime) / spanCount;
        }
 /// ------------------------------------------------------------------------------------
 public static CVPatternInfo Create(string phone, PatternType type)
 {
     return(string.IsNullOrEmpty(phone) ? null :
            new CVPatternInfo {
         Phone = phone, Type = type
     });
 }
Example #4
0
        private void CreatePattern(PatternType type)
        {
            Point[] coordinates = new Point[0];

            int density        = (int)_mainWindow.PatternDensitySlider.Value;
            var gridRectangles = GenerateRecursiveRectangles(density);

            switch (type)
            {
            case PatternType.Grid:
                coordinates = GetCenterPoints(gridRectangles);
                break;

            case PatternType.Hex:
                coordinates = GetHexPoints(gridRectangles);
                break;
            }

            for (int i = 0; i < _workspace.Layers.Count; i++)
            {
                var layer      = _workspace.Layers[i];
                var coordinate = GetCoordinate(coordinates, i);
                layer.SetCenterToPoint(coordinate, true);

                if (layer.Selected)
                {
                    layer.DrawOutline();
                }
            }

            _workspace.SnapPoints = coordinates;
            _workspace.DrawSnapPoints();
        }
Example #5
0
 private void btnDoIt_Click(object sender, EventArgs e)
 {
     sw.Reset();
     sw.Start();
     PatCount = 0;
     if (timerPattern.Enabled)
     {
         timerPattern.Enabled = false;
         sw.Stop();
         lblInfo.Text = "Number of Patterns : " + PatCount.ToString() + " , Elapsed Time = " + sw.ElapsedMilliseconds.ToString() + " (ms)";
         btnDoIt.Text = "Do It!";
     }
     else
     {
         btnDoIt.Text          = "Stop";
         lblInfo.Text          = "In Progress...";
         frmPtrnOnDspl.Visible = true;
         fposbmp = new Bitmap(frmPtrnOnDspl.Width, frmPtrnOnDspl.Height);
         pType   = PatternType.Strip;
         PatSize = (frmPtrnOnDspl.Height / 3) * 2;
         dir     = Orientation.Horizontal;
         frmPtrnOnDspl.SetPattern(pType, (PatSize + 1) / 2, dir, PatSize % 2 == 1);
         timerPattern.Enabled = true;
     }
 }
Example #6
0
            public void AddPattern(string patternKey, int windowStart, int windowEnd, int compareWindowStart,
                                   int compareWindowEnd, PatternType patternType)
            {
                var windowKey        = $"{windowStart},{windowEnd}";
                var compareWindowKey = $"{compareWindowStart},{compareWindowEnd}";

                if (!ContainsKey(patternKey))
                {
                    Add(patternKey, new Pattern()
                    {
                        PatternType = patternType
                    });
                }

                var pattern = this[patternKey];

                if (!pattern.ContainsKey(windowKey))
                {
                    pattern.Add(windowKey, new Window(windowStart, windowEnd));
                }

                if (!pattern.ContainsKey(compareWindowKey))
                {
                    pattern.Add(compareWindowKey, new Window(compareWindowStart, compareWindowEnd));
                }
            }
Example #7
0
 // Start is called before the first frame update
 void Start()
 {
     m_patternType = GameData.Instance.GetPatternType();
     m_patternDetail.gameObject.SetActive(false);
     hideAllPatternDetail();
     m_escapeTips.gameObject.SetActive(false);
 }
Example #8
0
 protected void SetData(int id, string name, PatternType type, string pattern)
 {
     m_id = id;
     m_name = name;
     m_type = type;
     m_pattern = pattern;
 }
        /// <summary>
        /// Creates pattern of points for a specified PatternType.
        /// Default is a Lorenz system
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Pattern CreatePattern(PatternType type, int size)
        {
            switch (type)
            {
            case PatternType.Circle:
            {
                return(new Circle(size));
            }

            case PatternType.Lorenz:
                goto default;     //can't fall through cases in Mono/Unity C#

            default:
            {
                //see https://en.wikipedia.org/wiki/Lorenz_system
                Lorenz lorenz = new Lorenz(size);
                //don't encapsulate below in the constructor as you wouldn't be able
                //to customize the Lorenz object
                lorenz.SetState(1f, 1f, 1f);                //x, y, z
                lorenz.SetParameters(10, 28, 8 / 3, 0.01f); //sigma, rho, beta, dTime
                lorenz.AddPoints();
                return(lorenz);
            }
            }
        }
Example #10
0
    void InitPrefabSelector()
    {
        pattern = (PatternType)Random.Range(0, (int)PatternType.Last + 1);
        switch (pattern)
        {
        case PatternType.Uniform:
            selectedPrefabs = SelectRandom(prefabs, 1);
            break;

        case PatternType.Alternating:
            selectedPrefabs       = SelectRandom(prefabs, 2);
            alternatingFrequency1 = Random.Range(1, 4);
            alternatingFrequency2 = Random.Range(1, 4);
            alternate             = false;
            alternateCount        = 0;
            break;

        case PatternType.Random:
            selectedPrefabs = prefabs;
            break;

        default:
            break;
        }
    }
 protected void SetData(int id, string name, PatternType type, string pattern)
 {
     this.m_id      = id;
     this.m_name    = name;
     this.m_type    = type;
     this.m_pattern = pattern;
 }
Example #12
0
        public static void Erase(string path, List <PatternType> patterns, int scale, MagickColor color)
        {
            if (patterns.Count < 1)
            {
                return;
            }
            MagickImage img = IOUtils.ReadImage(path);

            if (img == null)
            {
                return;
            }
            PatternType chosenPattern = GetRandomPatternType(patterns);

            PreProcessing(path, "- Pattern: " + chosenPattern.ToString());
            Random      rand       = new Random();
            MagickImage patternImg = new MagickImage(GetInpaintImage(chosenPattern));

            patternImg.FilterType = FilterType.Point;
            patternImg.Colorize(color, new Percentage(100));
            patternImg.BackgroundColor = MagickColors.Transparent;
            patternImg.Rotate(RandRange(0, 360));
            double geomW = img.Width * RandRange(1.0f, 2.0f) * GetScaleMultiplier(scale);
            double geomH = img.Height * RandRange(1.0f, 2.0f) * GetScaleMultiplier(scale);
            //Logger.Log("geomW: " + geomW + " - geomH: " + geomW);
            MagickGeometry upscaleGeom = new MagickGeometry(Math.Round(geomW) + "x" + Math.Round(geomH) + "!");

            patternImg.Resize(upscaleGeom);
            patternImg.BitDepth(Channels.Alpha, 1);
            img.Composite(patternImg, Gravity.Center, CompositeOperator.Over);
            img.Write(path);
            PostProcessing(img, path, path);
        }
 public UnKnownPattern(A11yElement e, int id, string name) : base(e, id, name)
 {
     if (!PatternType.GetInstance().Exists(id))
     {
         // be silent since Unknown pattern was created since pattern interface couldn't be retrieved by unknown reason.
     }
 }
 public void UpdatePattern(PatternType pattern, Vector3 targetPosition, Vector3 targetScale)
 {
     currentPattern      = pattern;
     this.targetPosition = targetPosition;
     this.targetScale    = targetScale;
     startTime           = Time.time;
 }
Example #15
0
    private void SpawnPattern(PatternType type)
    {
        GameObject  pattern    = Instantiate(PFB_PATTERN);
        SCR_Pattern scrPattern = pattern.GetComponent <SCR_Pattern>();

        scrPattern.Spawn(type);
    }
Example #16
0
        protected override void ComputeToken(int id, string name, PatternType type, string pattern, ExpressionContext context)
        {
            var options = context.ParserOptions;

            pattern = pattern.Replace('"', options.StringQuote);
            this.SetData(id, name, type, pattern);
        }
Example #17
0
 public void SetData(int id, string name, PatternType type, string pattern)
 {
     Id      = id;
     Name    = name;
     Type    = type;
     Pattern = pattern;
 }
Example #18
0
        private uint GetFill(PatternType patternType, string backgroundColor)
        {
            PatternValues patternValue = GetFillStyle(patternType);

            //Check font type exists and return index
            uint fillIndex = 0;

            foreach (var fill in ActualFills.ChildElements.OfType <Fill>())
            {
                if (fill.PatternFill.PatternType == patternValue &&
                    (
                        string.IsNullOrEmpty(backgroundColor) ||
                        fill.PatternFill.ForegroundColor == null ||
                        fill.PatternFill.ForegroundColor.Rgb == backgroundColor
                    ))
                {
                    return(fillIndex);
                }
                fillIndex++;
            }

            //if not exists create new fill and append to actual fills
            SetFill(patternValue, backgroundColor);
            return(fillIndex);
        }
Example #19
0
        public static Pattern Lookup(IntPtr pattern, bool owner)
        {
            if (pattern == IntPtr.Zero)
            {
                return(null);
            }

            PatternType pt = NativeMethods.cairo_pattern_get_type(pattern);

            switch (pt)
            {
            case PatternType.Solid:
                return(new SolidPattern(pattern, owner));

            case PatternType.Surface:
                return(new SurfacePattern(pattern, owner));

            case PatternType.Linear:
                return(new LinearGradient(pattern, owner));

            case PatternType.Radial:
                return(new RadialGradient(pattern, owner));

            default:
                return(new Pattern(pattern, owner));
            }
        }
Example #20
0
    // 更新模式名称
    public void UpdatePatternInfo(string name, PatternType type)
    {
        if (m_patternType != type)
        {
            // 播放音效
            AudioClip clip = Resources.Load <AudioClip>("Sounds/Switch");
            AudioSource.PlayClipAtPoint(clip, Vector3.zero);
        }
        // 更新模式信息
        Text nameText = m_patternName.Find("NameText").GetComponent <Text>();

        nameText.text = string.Format("- <color=yellow>{0}模式</color> -", name);
        m_patternType = type;
        GameData.Instance.SetPatternType(type); // 保存数据
        // 校验模式场景
        Text enterText = m_enterBtn.Find("Text").GetComponent <Text>();

        if (m_patternSceneMap.ContainsKey(m_patternType))
        {
            m_enterBtn.GetComponent <Button>().interactable = true;
            enterText.DOFade(1, 0.1f);
        }
        else
        {
            m_enterBtn.GetComponent <Button>().interactable = false;
            enterText.DOFade(0.2f, 0.1f);
        }
    }
        public void DoPatternExample(PatternType patternType)
        {
            string          patternTypeName = patternType.ToString();
            IPatternExample patternExample  = (IPatternExample)Assembly.Load("designPatterns").CreateInstance($"designPatterns.{patternTypeName}.{patternTypeName}Example");

            patternExample.DoWork();
        }
Example #22
0
        private void SetType(PatternType type)
        {
            _patternType = type;
            IPattern result = null;

            switch (type)
            {
            case PatternType.Gradient:
                result = new GradientPattern();
                break;

            case PatternType.Line:
                break;

            case PatternType.Marker:
                break;

            case PatternType.Picture:
                result = new PicturePattern();
                break;

            case PatternType.Simple:
                result = new SimplePattern();
                break;
            }
            if (result != null)
            {
                result.Outline = _innerPattern.Outline;
            }
            _innerPattern = result;
        }
 public void CopyFrom(FileAssociation other)
 {
     Pattern = other.Pattern;
       PatternType = other.PatternType;
       DocType = other.DocType;
       Enabled = other.Enabled;
 }
Example #24
0
        void SetupEngine(PatternType ptyp)
        {
            switch (ptyp)
            {
            case PatternType.barrel:
                _pathEngine = new OffsetPathEngine();
                break;

            case PatternType.bazley:
                _pathEngine = new BazelyEngine();
                break;

            case PatternType.ross:
                _pathEngine = new RossEngine();
                break;

            case PatternType.wheels:
                _pathEngine = new WheelsEngine();
                break;

            case PatternType.latticeRim:
                _pathEngine = new LatticeRimEngine();
                break;

            case PatternType.latticeFace:
                _pathEngine = new LatticeFaceEngine();
                break;

            case PatternType.braid:
                _pathEngine = new BraidEngine();
                break;
            }
        }
Example #25
0
 public PatternEvent(PatternType _eventtype, IPair Candle, CandlesSeries _candlescopy)
 {
     this.EventType    = _eventtype;
     this.ComingCandle = Candle;
     this.Collected    = Candle.CollectedDate;
     this.Candlescopy  = _candlescopy;
 }
        internal static Pattern Lookup(IntPtr pattern)
        {
            if (pattern == IntPtr.Zero)
            {
                return(null);
            }

            object x = patterns [pattern];

            if (x != null)
            {
                return((Pattern)x);
            }

            PatternType pt = NativeMethods.cairo_pattern_get_type(pattern);

            switch (pt)
            {
            case PatternType.Solid:
                return(new SolidPattern(pattern));

            case PatternType.Surface:
                return(new SurfacePattern(pattern));

            case PatternType.Linear:
                return(new LinearGradient(pattern));

            case PatternType.Radial:
                return(new RadialGradient(pattern));

            default:
                return(new Pattern(pattern));
            }
        }
Example #27
0
        internal static Exception ValidatePattern(PatternType type, string pattern, string argumentName)
        {
            switch (type)
            {
            case PatternType.All:
            case PatternType.Exact:
                // No validation needed for these cases, also not going to be hit
                break;

            case PatternType.Prefix:
                string prefix = pattern.Substring(0, pattern.Length - 1);
                if (prefix.Contains("*"))
                {
                    return(new ArgumentException(String.Format(CultureInfo.CurrentCulture, OptimizationResources.InvalidPattern, pattern), argumentName));
                }
                break;

            case PatternType.Suffix:
                string suffix = pattern.Substring(1);
                if (suffix.Contains("*"))
                {
                    return(new ArgumentException(String.Format(CultureInfo.CurrentCulture, OptimizationResources.InvalidPattern, pattern), argumentName));
                }
                break;

            case PatternType.Version:
                if (pattern.Contains("*"))
                {
                    return(new ArgumentException(String.Format(CultureInfo.CurrentCulture, OptimizationResources.InvalidPattern, pattern), argumentName));
                }
                break;
            }
            return(null);
        }
Example #28
0
        /// <summary>
        /// Returns a pattern size that is ensured to not have rotational symmetry (if not PatternType.CircleGrid).
        /// The tile size is rounded down. Smallest acceptable pattern is 3x4. It will not allow square sizes.
        /// </summary>
        /// <returns>The corrected pattern size</returns>
        public static Vector2Int GetClosestValidPatternSize(Vector2Int patternSize, PatternType patternType)
        {
            int patternSizeMin = patternType == PatternType.Chessboard ? 3 : 2;

            if (patternSize.x < 3)
            {
                patternSize.x = patternSizeMin;
            }
            if (patternSize.y < 3)
            {
                patternSize.y = patternSizeMin;
            }

            switch (patternType)
            {
            case PatternType.CircleGrid:
                if (patternSize.x == patternSize.y)
                {
                    if (patternSize.y == patternSizeMin)
                    {
                        patternSize.y++;
                    }
                    else
                    {
                        patternSize.y--;
                    }
                }
                break;

            case PatternType.Chessboard:
                if (patternSize.x % 2 == 0 && patternSize.y % 2 == 0)
                {
                    if (patternSize.y == patternSizeMin)
                    {
                        patternSize.y++;
                    }
                    else
                    {
                        patternSize.y--;
                    }
                }
                break;

            case PatternType.AsymmetricCircleGrid:
                if (patternSize.y % 2 == 0)
                {
                    if (patternSize.y == patternSizeMin)
                    {
                        patternSize.y++;
                    }
                    else
                    {
                        patternSize.y--;
                    }
                }
                break;
            }

            return(patternSize);
        }
Example #29
0
        public void Draw()
        {
            patternType = (PatternType)EditorGUILayout.EnumPopup("Type", patternType);

            color1 = EditorGUILayout.ColorField("Color 1", color1);
            color2 = EditorGUILayout.ColorField("Color 2", color2);

            count = EditorGUILayout.Vector2IntField("Count", count);


            if (GUI.changed)
            {
                if (count.x <= 0)
                {
                    count.x = 1;
                }

                if (count.y <= 0)
                {
                    count.y = 1;
                }
            }

            if (patternType == PatternType.TILE)
            {
                padding = EditorGUILayout.Vector2Field("Padding", padding);
            }
            else if (patternType == PatternType.CIRCLES)
            {
                scale = EditorGUILayout.Slider("Scale", scale, 1, 100);
            }

            flip = EditorGUILayout.Toggle("Flip", flip);
        }
 // Assumed to always exist (do validation before constructor)
 public BundleDirectoryItem(string path, string searchPattern, PatternType patternType, bool searchSubdirectories, IList <IItemTransform> transforms)
     : base(path, transforms)
 {
     SearchPattern        = searchPattern;
     PatternType          = patternType;
     SearchSubdirectories = searchSubdirectories;
 }
    private float Calculate(PatternType pattern, float time)
    {
        var t = MathUtils.Clamp01(time % 4 / 4);

        switch (pattern)
        {
        case PatternType.Triangle: return(MathF.Abs(MathF.Abs(t * 2 - 1.5f) - 1));

        case PatternType.Sine: return(-MathF.Sin(t * MathF.PI * 2) / 2 + 0.5f);

        case PatternType.DoubleBounce:
        {
            var x = t * MathF.PI * 2 - MathF.PI / 4;
            return(-(MathF.Pow(MathF.Sin(x), 5) + MathF.Pow(MathF.Cos(x), 5)) / 2 + 0.5f);
        }

        case PatternType.SharpBounce:
        {
            var x = (t + 0.41957f) * MathF.PI / 2;
            var s = MathF.Sin(x) * MathF.Sin(x);
            var c = MathF.Cos(x) * MathF.Cos(x);
            return(MathF.Sqrt(MathF.Max(c - s, s - c)));
        }

        case PatternType.Saw: return(t);

        case PatternType.Square: return(t < 0.5f ? 1 : 0);

        default: return(0);
        }
    }
Example #32
0
// поиск нового паттернов

        /// <summary>
        /// взять  временный паттерн по типу
        /// </summary>
        public IPattern GetTempPattern(PatternType type)
        {
            _curTempPatternType = type;

            for (int i = 0; i < _tempPatterns.Count; i++)
            {
                if (_tempPatterns[i].Type == type)
                {
                    _tempPatterns[i].Weigth = WeigthToTempPattern;
                    _tempPatterns[i].Expand = ExpandToTempPattern;
                    return(_tempPatterns[i]);
                }
            }

            if (type == PatternType.Indicators)
            {
                _tempPatterns.Add(new PatternIndicators());
            }
            else if (type == PatternType.Time)
            {
                _tempPatterns.Add(new PatternTime());
            }
            else if (type == PatternType.Volume)
            {
                _tempPatterns.Add(new PatternVolume());
            }
            else if (type == PatternType.Candle)
            {
                _tempPatterns.Add(new PatternCandle());
            }

            return(GetTempPattern(type));
        }
        private Selection.Builder BuildPattern(string matcher, PatternType tpe)
        {
            Selection.Builder builder = Selection.CreateBuilder().SetType(tpe);
            if (matcher != null)
                builder.SetMatcher(matcher);

            return builder;
        }
Example #34
0
   public ShapeCollection()
     : base()
 {
     _patternName = string.Empty;
     _patternType = PatternType.NONE;
     _items = new ObservableCollection<Shape>();
     _items.CollectionChanged += _items_CollectionChanged;
     _extent = new Extent2D();
 }
Example #35
0
 public void SetPatternFill(string name)
 {
     switch (name)
     { 
         case "solid":
             {
                 m_patternFill = PatternType.Solid;
                 break;
             }
         default://just for the moment lets assume we only care if it is solid
             {
                 m_patternFill = PatternType.None;
                 break;
             }
     }
 }
        static int[,] fillMatrix(PatternType pattern, int size)
        {
            int[,] matrix = new int[size, size];

            if(pattern == PatternType.PatternA)
            {
                int offset = 0;

                for(int x = 0; x < size; x++)
                {
                    for(int y = 0; y < size; y++)
                    {
                        matrix[y, x] = y + 1 + offset;
                    }

                    offset += 4;
                }
            }
            else
            {
                int offset = 0;

                for (int x = 0; x < size; x++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        if(x % 2 == 0)
                        {
                            matrix[y, x] = y + 1 + offset;

                        }
                        else
                        {
                            matrix[y, x] = offset - y + 4;
                        }
                    }
                        offset += 4;

                }
            }

            return matrix;
        }
Example #37
0
        public async void ImportPattern(PatternType typ)
        {
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            if (typ == PatternType.wheels)
                openPicker.FileTypeFilter.Add(".wheel");
            else if (typ == PatternType.ross)
                openPicker.FileTypeFilter.Add(".ross");
            else if (typ == PatternType.bazley)
                openPicker.FileTypeFilter.Add(".baz");
            else if (typ == PatternType.barrel)
                openPicker.FileTypeFilter.Add(".bar");
            else if (typ == PatternType.latticeRim)
                openPicker.FileTypeFilter.Add(".lattice");
            else if (typ == PatternType.braid)
                openPicker.FileTypeFilter.Add(".braid");
            openPicker.FileTypeFilter.Add(".xml");
            StorageFile file = await openPicker.PickSingleFileAsync();
            XmlSerializer ser;
            if (file != null)
            {
                var stream = await file.OpenStreamForReadAsync();
                if (typ == PatternType.wheels)
                {
                    ser = new XmlSerializer(typeof(WheelsData));                
                    WheelsData wd = (WheelsData)ser.Deserialize(stream);
                    wd.PatternIndex = WheelsPatterns.Count;
                    wd.FixUp();
                    WheelsPatterns.Add(wd);
                    SelectedPathIndex = wd.PatternIndex;
                }
                else if (typ == PatternType.ross)
                {
                    ser = new XmlSerializer(typeof(RossData));
                    RossData rd = (RossData)ser.Deserialize(stream);
                    rd.PatternIndex = RossPatterns.Count;
                    RossPatterns.Add(rd);
                    SelectedPathIndex = rd.PatternIndex;

                }
                else if (typ == PatternType.bazley)
                {
                    ser = new XmlSerializer(typeof(BazelyChuck));
                    BazelyChuck bd = (BazelyChuck)ser.Deserialize(stream);
                    bd.PatternIndex = BazeleyPatterns.Count;
                    BazeleyPatterns.Add(bd);
                    SelectedPathIndex = bd.PatternIndex;
                }
                else if (typ == PatternType.barrel)
                {
                    ser = new XmlSerializer(typeof(Barrel));
                    Barrel bd = (Barrel)ser.Deserialize(stream);
                    bd.PatternIndex = BarrelPatterns.Count;
                    BarrelPatterns.Add(bd);
                    SelectedPathIndex = bd.PatternIndex;
                }
                else if (typ == PatternType.latticeRim)
                {
                    ser = new XmlSerializer(typeof(LatticeData));
                    LatticeData bd = (LatticeData)ser.Deserialize(stream);
                    if (LatticePatterns.Select(p => p.PatternIndex == bd.PatternIndex).Count() > 0)
                       bd.PatternIndex = LatticePatterns.Count + 1;

                    LatticePatterns.Add(bd);
                    SelectedPathIndex = bd.PatternIndex;
                }
                else if (typ == PatternType.braid)
                {
                    ser = new XmlSerializer(typeof(BraidData));
                    BraidData bd = (BraidData)ser.Deserialize(stream);
                    bd.PatternIndex = BraidPatterns.Count;
                    BraidPatterns.Add(bd);
                    SelectedPathIndex = bd.PatternIndex;
                }          
            }
            else
            {
                
            }
           
        }
 void Awake()
 {
     type = LevelManager.patternType;
     instance = this;
 }
Example #39
0
 void SetupEngine(PatternType ptyp)
 {
     switch (ptyp)
     {
         case PatternType.barrel:
             _pathEngine = new OffsetPathEngine();
             break;
         case PatternType.bazley:
             _pathEngine = new BazelyEngine();
             break;
         case PatternType.ross:
             _pathEngine = new RossEngine();
             break;
         case PatternType.wheels:
             _pathEngine = new WheelsEngine();
             break;
         case PatternType.latticeRim:
             _pathEngine = new LatticeRimEngine();
             break;
         case PatternType.latticeFace:
             _pathEngine = new LatticeFaceEngine();
             break;
         case PatternType.braid:
             _pathEngine = new BraidEngine();
             break;
     }
 }
Example #40
0
        public void SetupPattern(PatternType ptyp, PathData d, double inc)
        {
            if (d == null)
            {
                RestoreLastPathdata(ptyp);
            }
            else
            {
                CurrentPathData = d;
            }

            if (inc > 0)
                Increment = inc;
            SetupEngine(ptyp);
        }
Example #41
0
 /// <summary>
 /// Creates a new pattern with the specified type
 /// </summary>
 /// <param name="type">The subclass of pattern to use as the internal pattern</param>
 public Pattern(PatternType type)
 {
     SetType(type);
 }
 public PatternFill(PatternType pattern, ColorInfo bgColor, ColorInfo fgColor)
 {
     Pattern = pattern;
     BgColor = bgColor;
     FgColor = fgColor;
 }
Example #43
0
 public void Initialize(int id, string name, PatternType type, string pattern, ExpressionContext context)
 {
     this.ComputeToken(id, name, type, pattern, context);
 }
Example #44
0
 protected abstract void ComputeToken(int id, string name, PatternType type, string pattern, ExpressionContext context);
Example #45
0
 public PathGenData(PatternType typ, int indx, int turns)
 {
     PathType = typ;
     PatternIndex = indx;
     SuggestedMaxTurns = turns;
 }
Example #46
0
        /**
         * Creates a new token pattern.
         *
         * @param id             the token pattern id
         * @param name           the token pattern name
         * @param type           the token pattern type
         * @param pattern        the token pattern
         */
        public TokenPattern(int id,
                            string name,
                            PatternType type,
                            string pattern) {

            this.m_id = id;
            this.m_name = name;
            this.m_type = type;
            this.m_pattern = pattern;
        }
Example #47
0
 public Solid(Color c, PatternType t)
 {
     this.color = c;
     this.Type = t;
 }
Example #48
0
        private void LoadFromStream(Stream stream)
        {
            BinaryReader binaryReader = new BinaryReader(stream);
            NibbleReader nibbleReader = new NibbleReader(binaryReader);

            byte type = nibbleReader.ReadByte();
            if (type != 0x40)
                throw new NotImplementedException();

            int size = nibbleReader.ReadByte();
            size = (size << 4) | nibbleReader.ReadNibble();
            if (size != 0x26C)
                throw new InvalidDataException("Size is invalid.");

            Title = nibbleReader.ReadString(42);
            Author = new User(nibbleReader);

            ColorPalette = new Palette(nibbleReader);

            nibbleReader.ReadByte(); // Unknown
            nibbleReader.ReadByte(); // Unknown, 0x0A
            Type = (PatternType)nibbleReader.ReadByte();
            nibbleReader.ReadByte(); // Unknown, 0x00
            nibbleReader.ReadByte(); // Unknown, 0x00

            for (int j = 0; j < Data.GetLength(1); j++)
                for (int i = 0; i < Data.GetLength(0); i += 2)
                {
                    Data[i + 1, j] = nibbleReader.ReadNibble();
                    Data[i, j] = nibbleReader.ReadNibble();
                }
        }
Example #49
0
 private void SetType(PatternType type)
 {
     _patternType = type;
     IPattern result = null;
     switch (type)
     {
         case PatternType.Gradient:
             result = new GradientPattern();
             break;
         case PatternType.Line:
             break;
         case PatternType.Marker:
             break;
         case PatternType.Picture:
             result = new PicturePattern();
             break;
         case PatternType.Simple:
             result = new SimplePattern();
             break;
     }
     if (result != null) result.Outline = _innerPattern.Outline;
     _innerPattern = result;
 }
Example #50
0
 protected BasePattern(PatternType type, int minCharLength)
 {
     Type = type;
     MinCharLength = minCharLength;
 }
Example #51
0
 public Pattern(string name, PatternType patternType)
 {
     Name = name;
     PatternType = patternType;
     Children = new HashSet<PatternData>();
 }
Example #52
0
        private void LoadFromPixelData(byte[] data)
        {
            Title = "Untitled";
            Author = new User("Someone", "Nowhere", new byte[] { 0, 0, 0, 0, 0, 0 });
            Type = PatternType.Normal;

            Color[,] sourceImage = new Color[Width, Height];
            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    sourceImage[i, j] = new Color(data[(j * Height + i) * 3 + 2], data[(j * Height + i) * 3 + 1], data[(j * Height + i) * 3 + 0]);

            HashSet<Color> bestPalette = CreateBestPalette(sourceImage);
            ColorPalette = new Palette();
            int k = 0;
            foreach (Color c in bestPalette)
                ColorPalette.SetColor(k++, c);

            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    Data[i, j] = ColorPalette.GetNearestColorIndex(sourceImage[i, j]);
        }
Example #53
0
 void RestoreLastPathdata(PatternType typ)
 {
     if (typ == PatternType.bazley)
     {
         _currentPathData = (_lastBazleyPattern != null) ? _lastBazleyPattern : BazeleyPatterns[0];
         _increment = (_lastBazleyIncrement > 0) ? _lastBazleyIncrement : 0.001;
     }
     else if (typ == PatternType.ross)
     {
         _currentPathData = (_lastRossPattern != null) ? _lastRossPattern : RossPatterns[0];
         _increment = (_lastRossIncrement > 0) ? _lastRossIncrement : 0.0005;
     }
     else if (typ == PatternType.wheels)
     {
         _currentPathData = (_lastWheelsPattern != null) ? _lastWheelsPattern : null;
         _increment = (_lastWheelsIncrement > 0) ? _lastWheelsIncrement : 0.001;
     }
     else if (typ == PatternType.barrel)
     {
         _currentPathData = (_lastBarrelPattern != null) ? _lastBarrelPattern : null;
         _increment = (_lastBarrelIncrement > 0) ? _lastBarrelIncrement : 0.001;
     }
     else if ((typ == PatternType.latticeRim) || (typ == PatternType.latticeFace))
     {
         _currentPathData = (_lastLatticePattern != null) ? _lastLatticePattern : null;
         _increment = (_lastLatticeIncrement > 0) ? _lastLatticeIncrement : 0.01;
     }
     else if (typ == PatternType.braid)
     {
         _currentPathData = (_lastBraidPattern != null) ? _lastBraidPattern : null;
         _increment = (_lastBraidIncrement > 0) ? _lastBraidIncrement : 0.01;
     }
     else  // defaults to Bazley
     {
         _currentPathData = (_lastBazleyPattern != null) ? _lastBazleyPattern : BazeleyPatterns[0];
         _increment = (_lastBazleyIncrement > 0) ? _lastBazleyIncrement : 0.001;
     }
 }
Example #54
0
        private static bool isPatternTypeArg(string arg, out PatternType patternType)
        {
            patternType = 0;

            return Enum.TryParse(arg, true, out patternType)
                && Enum.IsDefined(typeof(PatternType), patternType);
        }
        /// <summary>
        /// Parsers weekly patterns such as "Mon, Fri every 2 weeks"
        /// </summary>
        private void ParseWeekly()
        {
            //In a weekly pattern only BYDAY is allowed (it is in fact required)
            if ((Rule.ByDay.Count == 0) ||
                (Rule.ByHour.Count > 0) || (Rule.ByMinute.Count > 0) || (Rule.BySecond.Count > 0) ||
                (Rule.ByMonth.Count > 0) || (Rule.ByMonthDay.Count > 0) ||
                (Rule.BySetPos.Count > 0) || (Rule.ByWeekNo.Count > 0) || (Rule.ByYearDay.Count > 0))
                return;

            string dayNames = "";
            foreach (ByDay byDay in Rule.ByDay)
            {
                //BYDAY=1MO or something like this is specified, complex pattern.
                if (!byDay.IsAllOccurrences)
                    return;

                if (dayNames.Length == 0)
                    dayNames = GetAbbreviatedDayName(byDay.DayOfWeek);
                else
                    dayNames += string.Format(", {0}", GetAbbreviatedDayName(byDay.DayOfWeek));
            }

            if (Rule.Interval == 1)
                mSchedule = string.Format("{0} every week", dayNames);
            else
                mSchedule = string.Format("{0} every {1} weeks", dayNames, Rule.Interval);

            mPatternType = PatternType.Weekly;
        }
        private void ParseYearly()
        {
            //Only one BYMONTH and one BYMONTHDAY is allowed
            if ((Rule.ByDay.Count > 0) ||
                (Rule.ByHour.Count > 0) || (Rule.ByMinute.Count > 0) || (Rule.BySecond.Count > 0) ||
                (Rule.ByMonthDay.Count != 1) || (Rule.ByMonth.Count != 1) ||
                (Rule.BySetPos.Count > 0) || (Rule.ByWeekNo.Count > 0) || (Rule.ByYearDay.Count > 0))
                return;

            int monthDay = Rule.ByMonthDay[0];
            if (monthDay < -1)	//From negative values only "last day of month" is allowed.
                return;

            string monthDayStr = (monthDay == -1) ? "Last" : FormatNth(monthDay);

            string monthName = GetMonthName(Rule.ByMonth[0]);

            if (Rule.Interval == 1)
                mSchedule = string.Format("{0} day of {1} every year", monthDayStr, monthName);
            else
                mSchedule = string.Format("{0} day of {1} every {2} years", monthDayStr, monthName, Rule.Interval);

            mPatternType = PatternType.YearlyDay;
        }
        /// <summary>
        /// Parses Nth day of week in a month or a year pattern such as "2nd Friday every 2 months" or
        /// "2nd Friday in March every 3 years".
        /// </summary>
        private void ParseMonthlyYearlyDayOfWeek()
        {
            //Only one BYDAY is allowed and one optional BYMONTHDAY is allowed.
            if ((Rule.ByDay.Count != 1) ||
                (Rule.ByHour.Count > 0) || (Rule.ByMinute.Count > 0) || (Rule.BySecond.Count > 0) ||
                (Rule.ByMonthDay.Count > 0) ||
                (Rule.BySetPos.Count > 0) || (Rule.ByWeekNo.Count > 0) || (Rule.ByYearDay.Count > 0))
                return;

            ByDay day = Rule.ByDay[0];
            //Only "2MO" etc are allowed, "MO" are not allowed. From negative values only "last" is allowed.
            if ((day.IsAllOccurrences) || (day.NthOccurrence < -1))
                return;

            string nthOccurrence = (day.NthOccurrence == -1) ? "Last" : FormatNth(day.NthOccurrence);
            string dayOfWeek = GetDayName(day.DayOfWeek);

            if (Rule.ByMonth.Count == 0)
            {
                //Monthly pattern.
                if (Rule.Interval == 1)
                    mSchedule = string.Format("{0} {1} every month", nthOccurrence, dayOfWeek);
                else
                    mSchedule = string.Format("{0} {1} every {2} months", nthOccurrence, dayOfWeek, Rule.Interval);

                mPatternType = PatternType.MonthlyDayOfWeek;
            }
            else if (Rule.ByMonth.Count == 1)
            {
                //Yearly pattern.
                string monthName = GetMonthName(Rule.ByMonth[0]);

                if (Rule.Interval == 1)
                {
                    mSchedule = string.Format("{0} {1} of {2} every year", nthOccurrence, dayOfWeek, monthName);
                }
                else
                {
                    //This is a nthYear situation so we expect the nthYear * 12 number of months.
                    if (Rule.Interval % 12 != 0)
                        return;

                    int nthYear = Rule.Interval / 12;
                    mSchedule = string.Format("{0} {1} of {2} every {3} years", nthOccurrence, dayOfWeek, monthName, nthYear);
                }

                mPatternType = PatternType.YearlyDayOfWeek;
            }
            else
            {
                //Complex pattern.
                return;
            }
        }
        /// <summary>
        /// Parsers monthly or yearly pattenrs like
        /// "Last weekday every 2nd month" or "First weekend day in January every 3rd year"
        /// </summary>
        private void ParseMonthlyYearlyWeekDay()
        {
            //Only BYDAY and BYSETPOS are allowed, one optional BYMONTH is allowed.
            if ((Rule.ByHour.Count > 0) || (Rule.ByMinute.Count > 0) || (Rule.BySecond.Count > 0) ||
                (Rule.ByMonthDay.Count > 0) ||
                (Rule.ByWeekNo.Count > 0) || (Rule.ByYearDay.Count > 0))
                return;

            //Only 5 or 2 BYDAY are allowed, this indidates weekday or weekend day.
            string dayType;
            switch (Rule.ByDay.Count)
            {
                case 5:
                    //Check all the days specified are weekdays.
                    for (int i = 0; i < Rule.ByDay.Count; i++)
                    {
                        ByDay byDay = Rule.ByDay[i];
                        if (!byDay.IsAllOccurrences || IsWeekEndDay(byDay.DayOfWeek))
                            return;
                    }
                    dayType = "weekday";
                    break;
                case 2:
                    //Check all the days that are specified are weekend days.
                    for (int i = 0; i < Rule.ByDay.Count; i++)
                    {
                        ByDay byDay = Rule.ByDay[i];
                        if (!byDay.IsAllOccurrences || !IsWeekEndDay(byDay.DayOfWeek))
                            return;
                    }
                    dayType = "weekend day";
                    break;
                default:
                    //Not a simple pattern for our case.
                    return;
            }

            //Onlly one BYSETPOS is allowed to indicate last or first weekday/weekend day.
            if (Rule.BySetPos.Count != 1)
                return;

            string dayPos;
            switch (Rule.BySetPos[0])
            {
                case 1:
                    dayPos = "First";
                    break;
                case -1:
                    dayPos = "Last";
                    break;
                default:
                    return;
            }

            if (Rule.ByMonth.Count == 0)
            {
                //Monthly pattern.
                if (Rule.Interval == 1)
                    mSchedule = string.Format("{0} {1} every month", dayPos, dayType);
                else
                    mSchedule = string.Format("{0} {1} every {2} months", dayPos, dayType, Rule.Interval);

                mPatternType = PatternType.MonthlyWeekDay;
            }
            else if (Rule.ByMonth.Count == 1)
            {
                string monthName = GetMonthName(Rule.ByMonth[0]);

                if (Rule.Interval == 1)
                {
                    mSchedule = string.Format("{0} {1} of {2} every year", dayPos, dayType, monthName);
                }
                else
                {
                    //This is a nthYear situation so we expect the nthYear * 12 number of months.
                    if (Rule.Interval % 12 != 0)
                        return;

                    int nthYear = Rule.Interval / 12;
                    mSchedule = string.Format("{0} {1} of {2} every {3} years", dayPos, dayType, monthName, nthYear);
                }

                mPatternType = PatternType.YearlyWeekDay;
            }
            else
            {
                //Complex pattern.
                return;
            }
        }
Example #59
0
 public Pattern(Color backcolor, PatternType style, Color forecolor)
 {
     this.backColor = backcolor;
     this.patternType = style;
     this.foreColor = forecolor;
 }
        /// <summary>
        /// Parses daily patterns such as "every 5 days"
        /// </summary>
        private void ParseDaily()
        {
            //For a daily pattern to be recognized no BYxxx parts should be specified.
            if ((Rule.ByDay.Count > 0) ||
                (Rule.ByHour.Count > 0) || (Rule.ByMinute.Count > 0) || (Rule.BySecond.Count > 0) ||
                (Rule.ByMonth.Count > 0) || (Rule.ByMonthDay.Count > 0) ||
                (Rule.BySetPos.Count > 0) || (Rule.ByWeekNo.Count > 0) || (Rule.ByYearDay.Count > 0))
                    return;

            if (Rule.Interval == 1)
                mSchedule = "Every day";
            else
                mSchedule = string.Format("Every {0} days", Rule.Interval);

            mPatternType = PatternType.Daily;
        }