Example #1
0
        private void buttonMatrix_Click(object sender, EventArgs e)
        {
            int       dim = 16;
            Primitive mat = LDMatrix.Create(dim, dim);

            for (int i = 0; i < dim; i++)
            {
                for (int j = 0; j < dim; j++)
                {
                    //LDMatrix.SetValue(mat, i + 1, j + 1, -SBMath.GetRandomNumber(100) + SBMath.Pi);
                    LDMatrix.SetValue(mat, i + 1, j + 1, SBMath.GetRandomNumber(100));
                }
            }
            //LDMatrix.SetValue(mat, 1, 1, 2);
            //LDMatrix.SetValue(mat, 1, 2, -1);
            //LDMatrix.SetValue(mat, 1, 3, 0);
            //LDMatrix.SetValue(mat, 2, 1, -1);
            //LDMatrix.SetValue(mat, 2, 2, 2);
            //LDMatrix.SetValue(mat, 2, 3, -1);
            //LDMatrix.SetValue(mat, 3, 1, 0);
            //LDMatrix.SetValue(mat, 3, 2, -1);
            //LDMatrix.SetValue(mat, 3, 3, 2);
            Primitive inv = LDMatrix.Create(dim, dim);

            LDMatrix.Inverse(mat, inv);
            Primitive mult = LDMatrix.Create(dim, dim);

            LDMatrix.Multiply(mat, inv, mult);
            LDMatrix.View(mat, "False");
            LDMatrix.Delete(mat);
            LDMatrix.View(inv, "False");
            TextWindow.WriteLine(LDUtilities.KeyDown("Space"));
            TextWindow.WriteLine(LDUtilities.KeyDown("LeftShift"));
        }
Example #2
0
        private void buttonDialogs_Click(object sender, EventArgs e)
        {
            int i;

            GraphicsWindow.Show();
            Primitive items  = "";
            Primitive images = "";

            for (i = 1; i <= 5; i++)
            {
                items[i]  = "Item " + i;
                images[i] = "C:\temp\test.jpg";
            }
            LDDialogs.AddRightClickMenu(items, images);

            TextWindow.WriteLine(System.Windows.Media.RenderCapability.Tier >> 16);
            Primitive a1 = LDArray.Create(1000);

            Shapes.AddEllipse(50, 50);
            FormPropertyGrid grid = new FormPropertyGrid();

            grid.Display("_mainCanvas");
            Primitive properties = grid.GetProperties("_mainCanvas");

            for (i = 1; i <= SBArray.GetItemCount(properties); i++)
            {
                TextWindow.WriteLine(properties[i]);
            }

            grid.SetProperty("_mainCanvas.Children.Ellipse1.Opacity", 0.5);

            Primitive font     = LDDialogs.Font("");
            Primitive font2    = LDDialogs.Font(font);
            Primitive fileName = LDDialogs.OpenFile("Small Basic File (*.sb) |*.sb", "");

            LDUtilities.Version();
            GraphicsWindow.Show();
            TextWindow.WriteLine(LDDialogs.Calendar(LDDateTime.Add(LDDateTime.Now(), 7))); //Now + 7 days
            //LDUtilities.PauseUpdates();
            LDDialogs.Wait("Please wait for a few seconds while I draw something...", LDColours.SetOpacity(LDColours.Violet, 200));
            double start = Clock.ElapsedMilliseconds;

            i = 1;
            while (Clock.ElapsedMilliseconds < start + 5000)
            {
                Primitive ball = Shapes.AddEllipse(20, 20);
                Shapes.Move(ball, SBMath.GetRandomNumber(GraphicsWindow.Width) - 10, SBMath.GetRandomNumber(GraphicsWindow.Height) - 10);
                LDDialogs.ToolTip(ball, "Ball " + i++);
                SBProgram.Delay(100);
            }
            //LDUtilities.ResumeUpdates();
            LDDialogs.EndWait();
        }
Example #3
0
        private void buttonShapes_Click(object sender, EventArgs e)
        {
            GraphicsWindow.Show();
            LDScrollBars.Rasterize    = "True";
            GraphicsWindow.MouseDown += OnMouseDown;
            LDScrollBars.Add(GraphicsWindow.Width, 10000);
            int       cogRadius    = 100;
            int       cogNumTeeth  = 10;
            int       cogToothSize = 10;
            Primitive cog          = Shapes.AddEllipse(2 * cogRadius, 2 * cogRadius);
            Primitive points       = "";
            Primitive point        = "";

            LDPhysics.AddMovingShape(cog, 0.5, 0.8, 1);
            for (int i = 1; i <= 1; i++)
            {
                double angle       = (i - 1) / cogNumTeeth * 2 * SBMath.Pi;
                double innerSector = 0.7 / cogNumTeeth * 2 * SBMath.Pi;
                double outerSector = 0.5 / cogNumTeeth * 2 * SBMath.Pi;
                point["X"] = cogRadius + cogRadius * SBMath.Cos(angle);
                point["Y"] = cogRadius + cogRadius * SBMath.Sin(angle);
                points[1]  = point;
                point["X"] = cogRadius + cogRadius * SBMath.Cos(angle + innerSector);
                point["Y"] = cogRadius + cogRadius * SBMath.Sin(angle + innerSector);
                points[2]  = point;
                point["X"] = cogRadius + (cogRadius + cogToothSize) * SBMath.Cos(angle + outerSector);
                point["Y"] = cogRadius + (cogRadius + cogToothSize) * SBMath.Sin(angle + outerSector);
                points[3]  = point;
                point["X"] = cogRadius + (cogRadius + cogToothSize) * SBMath.Cos(angle + innerSector - outerSector);
                point["Y"] = cogRadius + (cogRadius + cogToothSize) * SBMath.Sin(angle + innerSector - outerSector);
                points[4]  = point;
                Primitive tooth = LDShapes.AddPolygon(points);
                LDPhysics.AddMovingShape(tooth, 0.5, 0.8, 1);
                //LDPhysics.GroupShapes(cog, tooth);
            }

            LDPhysics.DoTimestep();

            Primitive ball = Shapes.AddEllipse(100, 50);

            //Shapes.Move(ball, 112, 112);
            //Shapes.Zoom(ball, 1, 1);
            //Shapes.Rotate(ball, -60);
            Shapes.Move(ball, 100, 112);
            //Shapes.Zoom(ball, 1.2, 1);
            //Shapes.Rotate(ball, -60);

            Primitive gradient = "";

            gradient[1] = "Red";
            gradient[2] = "Yellow";
            gradient[3] = "Blue";
            Primitive brush = LDShapes.BrushGradient(gradient, "H");

            LDShapes.BrushShape(ball, brush);

            LDUtilities.GWCapture("C:\\temp\\test.jpg", "False");

            Primitive rect = Shapes.AddRectangle(60, 60);

            Shapes.Move(rect, 25, 95);
            Shapes.Zoom(rect, 1.5, 1);
            Shapes.Rotate(rect, 45);
            //Shapes.Move(rect, 75, 75);
            //Shapes.Zoom(rect, 1.5, 1);
            //Shapes.Rotate(rect, 45);

            TextWindow.WriteLine(LDShapes.Overlap(ball, rect));
            //TextWindow.WriteLine(LDShapes.Overlap(rect, ball));

            Primitive image1 = Shapes.AddImage("C:\\temp\\test2.jpg");

            Shapes.Move(image1, 100, 100);
            TextWindow.WriteLine(LDShapes.Overlap(ball, image1));

            //LDShapes.AnimatedGifInterval = 0;
            Primitive gifShape = LDShapes.AddAnimatedGif("http://www.animatedgif.net//animals//birds//batana1_e0.gif", "True");

            Shapes.Move(gifShape, 100, 300);
            Primitive rectangle = Shapes.AddRectangle(100, 100);

            LDShapes.BrushColour(rectangle, "Red");
            Primitive img    = SBImageList.LoadImage("C:\\temp\\test.jpg");
            Primitive img2   = "C:\\temp\\test2.jpg";
            Primitive button = SBControls.AddButton("TEST", 100, 100);

            SBControls.SetSize(button, 50, 50);
            Primitive image = Shapes.AddImage(img);

            LDShapes.ReSize(image, 50, 50);
            LDShapes.Centre(image, 400, 25);
            SBProgram.Delay(1000);
            LDShapes.SetImage(image, img2);
            LDShapes.SetImage(button, img);
            SBProgram.Delay(1000);
            LDShapes.AnimationInterval = 0;
            LDShapes.AnimationSet(gifShape, LDShapes.AnimationCount(gifShape) / 3);
            SBProgram.Delay(1000);
            LDShapes.AnimationInterval = 50;
            LDShapes.AnimationPause(gifShape);
            SBProgram.Delay(2000);
            Shapes.HideShape(gifShape);
            LDShapes.AnimationResume(gifShape);
            SBProgram.Delay(2000);
            Shapes.ShowShape(gifShape);
        }
Example #4
0
        private void buttonSortStatistics_Click(object sender, EventArgs e)
        {
            Primitive array = "";

            for (int i = 1; i <= 100; i++)
            {
                array[i] = SBMath.GetRandomNumber(100);
            }
            LDSort.CaseSensitive = "False";
            array[1]             = "FB";
            array[2]             = "fb";
            array[4]             = "c";
            array[3]             = "C";
            Primitive result = LDSort.ByValue(array);

            for (int i = 1; i <= SBArray.GetItemCount(result); i++)
            {
                TextWindow.WriteLine(i + " : " + result[i]);
            }

            TextWindow.WriteLine("");
            result = LDStatistics.SetArray(array);
            for (int i = 1; i <= SBArray.GetItemCount(result); i++)
            {
                TextWindow.WriteLine(i + " : " + result[i]);
            }
            TextWindow.WriteLine("");
            TextWindow.WriteLine(LDStatistics.Count);
            TextWindow.WriteLine(LDStatistics.Mean);
            TextWindow.WriteLine(LDStatistics.Median);
            TextWindow.WriteLine(LDStatistics.Mode);
            TextWindow.WriteLine(LDStatistics.SDev);
            TextWindow.WriteLine(LDStatistics.PDev);
            TextWindow.WriteLine(LDStatistics.HarmonicMean);
            TextWindow.WriteLine(LDStatistics.GeometricMean);
            TextWindow.WriteLine(LDStatistics.Min);
            TextWindow.WriteLine(LDStatistics.Max);

            Primitive graph = LDGraph.AddGraph(0, 0, GraphicsWindow.Width, GraphicsWindow.Height, "Probability Distribution", "Value", "Probability");
            //Primitive data = LDStatistics.DistNormal(4, 0.5, 101);
            //Primitive data = LDStatistics.DistUniform(3, 6, 101);
            //Primitive data = LDStatistics.DistTriangular(3, 6, 101);
            Primitive data = LDStatistics.DistBinomial(20, 0.5);

            LDGraph.AddSeriesLine(graph, "PDF", data, "Red");
            LDGraph.AddSeriesLine(graph, "CDF", LDStatistics.Integrate(data), "Blue");
            LDGraph.AddSeriesLine(graph, "Derivative", LDStatistics.Differentiate(data), "Green");
            LDUtilities.Icon = "C:\\Users\\Public\\Pictures\\fractal-1.jpg";

            array = "";
            for (int i = 1; i <= 1000; i++)
            {
                array[i] = SBMath.GetRandomNumber(999) / 1000.0;
            }
            Primitive dist = LDStatistics.InterpolateX(LDStatistics.Integrate(data), array);
            Primitive freq = LDStatistics.Frequency(dist, 50, "True");

            LDGraph.AddSeriesHistogram(graph, "Generated", freq, "Black");
            LDStatistics.SetArray(dist);
            TextWindow.WriteLine(LDStatistics.Mean);
            TextWindow.WriteLine(LDStatistics.SDev);

            Primitive A     = LDArray.Create(3);
            Primitive index = LDArray.Create(3);

            LDArray.SetValue(A, 1, 5);
            LDArray.SetValue(A, 2, 3);
            LDArray.SetValue(A, 3, 1);
            LDArray.SortIndex(A, index);
        }