Esempio n. 1
0
    public static void DrawPoints(ArrayList rlist, MersenneDebugWindow.MersenneWindowOptionsType op, int width, int height)
    {
        int counter = 0;

        foreach (object obj in rlist)
        {
            counter++;

            // 1. make a Cross around zero
            Vector2 pointA = new Vector2(0.0f, -1.0f);
            Vector2 pointB = new Vector2(0.0f, 1.0f);

            Vector2 pointC = new Vector2(1.0f, 0.0f);
            Vector2 pointD = new Vector2(-1.0f, 0.0f);

            // 2. move the cross into place

            // Y: value
            // X: Position

            float myy = 0;             // for data representation I use Convert to Single

            switch (op)
            {
            case MersenneDebugWindow.MersenneWindowOptionsType.INT:
                // scale on Int32 MAX VALUE (again is 0 - 1 range)
                myy = (Convert.ToSingle(obj) / Int32.MaxValue);
                break;

            case MersenneDebugWindow.MersenneWindowOptionsType.FLOAT:
                myy = Convert.ToSingle(obj);
                break;

            case MersenneDebugWindow.MersenneWindowOptionsType.DOUBLE:
                myy = Convert.ToSingle(obj);
                break;
            }

            float myposy = myy * height;
            float myposx = counter * (Convert.ToSingle(width) / rlist.Count);

            Vector2 myScalingFactor = new Vector2(myposx, myposy);

            Vector2 pointAs = pointA + myScalingFactor;
            Vector2 pointBs = pointB + myScalingFactor;

            Vector2 pointCs = pointC + myScalingFactor;
            Vector2 pointDs = pointD + myScalingFactor;

            MersenneDebugDrawing.DrawLine(pointAs, pointBs, Color.blue, 1.0f, true);
            MersenneDebugDrawing.DrawLine(pointCs, pointDs, Color.blue, 1.0f, true);
        }
    }
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(10, 10, 400, 400));
        GUILayout.Box("RANDOM NUMBER DISTRIBUTION", GUILayout.Width(400), GUILayout.Height(400));
        if (randomList != null && randomList.Count > 0)
        {
            MersenneDebugDrawing.DrawPoints(randomList, op, 400, 400);
        }
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(10, 420, 400, 200));
        seed            = EditorGUILayout.IntSlider("Seed:", seed, Int32.MinValue, Int32.MaxValue);
        op              = (MersenneWindowOptionsType)EditorGUILayout.EnumPopup("Type:", op);
        samplig_size    = EditorGUILayout.IntSlider("#N", samplig_size, 1, 1000);
        normalizeToggle = EditorGUILayout.Toggle("Normalize", normalizeToggle);

        if (normalizeToggle)
        {
            temperature = EditorGUILayout.Slider("Temp", temperature, 0.0f, 10.0f);
        }

        if (GUILayout.Button("Generate Random Numbers"))
        {
            this.Sample();
        }

        if (randomList != null && randomList.Count > 0)
        {
            filename = EditorGUILayout.TextField("filename:", filename);
            if (GUILayout.Button("Save To File and Open it"))
            {
                this.Save();
            }
        }

        if (GUILayout.Button("Close Window"))
        {
            this.Close();
        }

        GUILayout.EndArea();
    }