Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMALL BASIC - More methods for further geometric forms ... #192

Open
boa2145 opened this issue Sep 17, 2022 · 28 comments
Open

SMALL BASIC - More methods for further geometric forms ... #192

boa2145 opened this issue Sep 17, 2022 · 28 comments

Comments

@boa2145
Copy link

boa2145 commented Sep 17, 2022

In SMALL BASIC I can draw various geometric figures, e.g. square, rectangle, circle, ellipse and triangle and fill them in with color. However, it is not possible to draw a n-star or a n-gon, for example. I can only create stars and n-gons with the turtle graphics, but then I have the problem of not being able to fill the figure with color. That's only possible with turtle-tricks, but the filled area is not 100% because of the free corners by the turtle drawing method. It would be very nice if SMALL BASIC provided more methods with which one could draw stars, any n-gons or even free figures and fill them in with colors.

@boa2145 boa2145 changed the title Include more methods for other geometric forms ... SMALL BASIC - More methods for further geometric forms ... Sep 17, 2022
@VBAndCs
Copy link

VBAndCs commented Oct 9, 2022

You can use VB .NET or C# to create a lib for small basic to do what you want:
https://social.technet.microsoft.com/wiki/contents/articles/53826.small-basic-extensions.aspx
And there are many extension libs that may offer you what you want.
The graphics window is a wpf window, and you can create complex graphics in wpf by using the System.Windows.Shapes.Path class.

But, on the other hand, SB shouldn't be used beyond what it is created for, as it should be a step up towards learning VB.NET. And to make this even easier, I created the Small Visual Basic language on top of Small Basic, with more compiler features and a windows forms designer and library. You can crate any shape you want as a Xaml file, and add it to the toolbox folder, so you can drag it on the form and use it as a control, and fill it with any back color you want!
I just released sVB 2.0, which can crate a multi form project with a common Global.sb file to hold global variables and functions to be used from any form in the project. Try it:
https://github.com/VBAndCs/sVB-Small-Visual-Basic/releases/tag/v2.0

@VBAndCs
Copy link

VBAndCs commented Oct 9, 2022

Also, you can do what you want with SB directly by drawing overlapping triangles and rectangles and fill them!
for example:

GraphicsWindow.FillTriangle(150, 50, 50, 150, 200, 200)
GraphicsWindow.FillTriangle(50, 50, 100, 150, 150, 100)

image

@boa2145
Copy link
Author

boa2145 commented Oct 10, 2022

Hi Mohammad, thanks for your replies. I am a hobby programmer and only use MS BASIC-Dialects like Small Basic, QBasic, QuickBasic, GW-Basic. I also love Scratch and a bit Python, too. So I'm interested in programming in different fields of education and not in professional development. I am not able to use other languages (e.g. C++, C#) to solve my problems in Small Basic.

My problem in Small Basic is, for example: I try to program the flags of the world. Sometimes there are special geometric figures like a pentagram (Fünfstern -> USA) or hexagram (Sechsstern -> Israel) or seven-star (Siebenstern -> Australia). With the turtle I can program these figures and fill them out with color while creating further turtles inside. On the other hand I could divide a five-star, six-star and seven-star in triangles. I then have to find an algorithm to create any five- or six- or seven-star in different sizes, colors, borders and locations on the graphics window. That is my current challenge. Maybe you can help me. That would be great.

Regards ... Gregor

@VBAndCs
Copy link

VBAndCs commented Oct 10, 2022

@boa2145
Use images for flags.
Also, you may take a look at small visual basic, as it is meant for education to be more powerful yet easier that small basic.

@boa2145
Copy link
Author

boa2145 commented Oct 11, 2022

I included images for special flags (e.g. Argentina), but I want to program colored n-stars, too. How can I install Small Visual Basic?

@VBAndCs
Copy link

VBAndCs commented Oct 11, 2022

It doesn't require installation. Download the zip file from the assets at the bottom of this page:
https://github.com/VBAndCs/sVB-Small-Visual-Basic/releases/tag/v2.0
It only reqyires .NET framework 4.8. If you don't have it on your PC, install it from:
https://go.microsoft.com/fwlink/?LinkId=2085155

@boa2145
Copy link
Author

boa2145 commented Oct 11, 2022

Well, Small Visual Basic works. Now I have to find an introduction to program with your app. Do you know a Small Visual Basic tutorial?

@VBAndCs
Copy link

VBAndCs commented Oct 11, 2022

See the readme
https://github.com/VBAndCs/sVB-Small-Visual-Basic/blob/master/Readme.md
and try the samples in the sVB folder.
Note: I fixed a fatal bug (due to recent updates) that crashes the cars demo sample. I just updated the zip file without changing the version, so, if you downloaded it before 35 minutes, please redownload it.
https://github.com/VBAndCs/sVB-Small-Visual-Basic/releases/download/v2.0/sVB.2.1.zip

@VBAndCs
Copy link

VBAndCs commented Oct 12, 2022

@boa2145
I've added a GeometricPath object to sVB to allow you to draw complex shapes, and add them to the Shapes collection to be able to rotate and animate them.
You can crate a figure in the GeometricPath like this:

GraphicsWindow.BrushColor = Colors.AliceBlue
GraphicsWindow.PenColor = Colors.Red
GraphicsWindow.PenWidth = 3

GeometricPath.CreateFigure(100, 100)
GeometricPath.AddLineSegment(50, 150, True)
GeometricPath.AddLineSegment(100, 200, True)
GeometricPath.AddLineSegment(200, 200, True)
GeometricPath.AddLineSegment(250, 150, True)
GeometricPath.AddLineSegment(200, 100, True)
GeometricPath.AddLineSegment(100, 100, True)

Sh = Shapes.AddGeometricPath()
Shapes.Rotate(Sh, 45)

This is the result:
image

I will add more Add..Segment methods to allow you to draw arcs and Bezier arcs, and this will be available in sVB v2.2 very soon.

@VBAndCs
Copy link

VBAndCs commented Oct 12, 2022

Note that you can send False when adding anysegent to hide its line. Like this:

'....
GeometricPath.AddLineSegment(200, 200, False)
'....

image

@VBAndCs
Copy link

VBAndCs commented Oct 12, 2022

sVB v2.2 is released:
https://github.com/VBAndCs/sVB-Small-Visual-Basic/releases/tag/v2.2
You can use it to draw complex shapes like this:
image
See the Geometric Path app in the samples folder.

@boa2145
Copy link
Author

boa2145 commented Oct 13, 2022

Hi Mohammad, thanks for your effort and help. I'll try it next time when I want to program a flag. The first two parameters of the method "AddLineSegement" are the x/y-coordinates, aren't they? Could you explain "GeometricPath.CreateFigure(100, 100)", please?

@VBAndCs
Copy link

VBAndCs commented Oct 13, 2022

You can look at the methopd and params info definition here:
https://github.com/VBAndCs/sVB-Small-Visual-Basic/blob/master/SmallBasicLibrary/Library/GeometricPath.vb
or in the SmallVisualBasicLibrary.xml file in the bin directory in the sVB folder, or simply move the caret to the name of the method in sVB editor, and the popup help will show you all the info you need:
image

image

The idea of dewing a figure is to start with a point, then supply another point with each Add...Segment method to draw a line, an arc or a curve between them. If you want to have a closed shape, then you should end up with the start point at the last segment you draw.
By the way, you can have in depth detailed about this from WPF docs. SB and sVB are created with wpf and they emit MSIL code in the exe, so they are .NET languages. I am maitaining the same concepts in the sVB library like WinForms, so sVB can be an easy a step up towards VB.NET.
So, you may read these docs:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.pathfigure.startpoint?view=windowsdesktop-6.0#system-windows-media-pathfigure-startpoint
https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.linesegment.-ctor?view=windowsdesktop-6.0#system-windows-media-linesegment-ctor(system-windows-point-system-boolean)
https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.arcsegment.-ctor?view=windowsdesktop-6.0#system-windows-media-arcsegment-ctor(system-windows-point-system-windows-size-system-double-system-boolean-system-windows-media-sweepdirection-system-boolean)
https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.beziersegment.-ctor?view=windowsdesktop-6.0#system-windows-media-beziersegment-ctor(system-windows-point-system-windows-point-system-windows-point-system-boolean)
https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.quadraticbeziersegment.-ctor?view=windowsdesktop-6.0#system-windows-media-quadraticbeziersegment-ctor(system-windows-point-system-windows-point-system-boolean)

@VBAndCs
Copy link

VBAndCs commented Oct 13, 2022

@boa2145
sVB 2.2.5 now allows to add the GeometricPath to the Label control too, so, it is possible to draw complex shapes on the form. In fact this was possibe by adding a new figure in the Toolbox folder, so, it can be dragged on the form, but doing this required a good knowledge of XAML, which is not something to expect from kids and beginners. Now, thanks to you, anyone can write sVB code to create what ever shapes he wants.
You can create the geometric path as usual, then add it to the to a label, by calling the AddGeometricPath() method of this label:

Label1.AddGeometricPath(
    Colors.Red, ' Pen color
    2, ' Pen width
    Colors.Yellow ' Brush color
)

Label1.Rotate(45)

The advatage of adding shapes to the label, is that you can handle their events.
See the Geometric Path2 in the samples folder. It adds the same shapes of the previous sample to the form, and allows you to drag them by the mouse.
Untitled

I think it is a valuable addition to sVB. Thanks.

@VBAndCs
Copy link

VBAndCs commented Oct 23, 2022

@boa2145
This is more like what you need:

GraphicsWindow.PenColor = Colors.Black
GraphicsWindow.PenWidth = 3
GraphicsWindow.BrushColor = Colors.Red
X = Shapes.AddPolygon(
   {
      {0, 100},
      {76.5, 100},
      {100, 25},
      {123.5, 100},
      {200, 100},
      {140, 142.5},
      {160, 200},
      {100, 145},
      {40, 200},
      {62, 142.5}
   }
)

image

This will be available in the upcoming sVB 2.4.5

I think SB didn't add the Polygon because it will be verbose to add the points to the array in the traditional way. sVB allows to use array initializer {}, so, as you can see, you can supply any number of points to create any n-polygon you want.

@boa2145
Copy link
Author

boa2145 commented Oct 24, 2022

Hello Mohammad, thanks for your help. Unfortunately I have the problem that I don't have enough instructions to get your code snippets to work. This makes me a little confused as to how to program on your Small Visual Basic IDE. Best regards... Gregory

@VBAndCs
Copy link

VBAndCs commented Oct 24, 2022

@boa2145
The readme file contains all instructions, but it is an accumulation of what's new in sVB versions over the bast two years. Also the samples folder contains many small samples that covers all the new features of sVB. Add these to the fact that sVB is in fact SB raised to the power of 2, so, you can use all you know about SB to code in sVB.
I will provide a wll organized book about sVB after releasing v2.5, which will a major stop for the language for a while as it reached a mature and productive state. This version will come with an sVB notepad app, that shows its ability to create useful desktop apps with standard interface and functionality.

@VBAndCs
Copy link

VBAndCs commented May 14, 2023

@boa2145
As promised, sVB full reference book

1111

@boa2145
Copy link
Author

boa2145 commented May 16, 2023 via email

@VBAndCs
Copy link

VBAndCs commented May 16, 2023

@boa2145
You can increase the turtle speed:
Turtle.Speed = 10
But the turtle will always be relatively slow. It is meant to be fun for kids, not a very practical drawing tool.

@boa2145
Copy link
Author

boa2145 commented May 16, 2023 via email

@boa2145
Copy link
Author

boa2145 commented May 17, 2023 via email

@boa2145
Copy link
Author

boa2145 commented May 17, 2023 via email

@VBAndCs
Copy link

VBAndCs commented May 17, 2023

@boa2145
Thanks Gregor for your great suggestion. I think it may be possible to fill the shape drawn by the turtle, by defining a geometric path for the segments it draws, the same way used to draw the pentagon.
I've posted this in the sVB issues section as a proposal, and I will consider it in next releases.
And you are welcome to post any other issues or proposals there, not to disturb this repo admins.
Thanks.

@VBAndCs
Copy link

VBAndCs commented May 21, 2023

@boa2145
It's done. You can install sVB v2.8.4, where you can use the turtle can fill an area, by calling the CreateFigure and FillFigure methods.

X = Turtle.X
Y = Turtle.Y

Turtle.CreateFigure()
Turtle.Move(200)
Turtle.TurnRight()
Turtle.Move(200)
Turtle.TurnRight()
Turtle.Move(200)
Turtle.TurnRight()
Turtle.Move(200)
Turtle.FillFigure()

Turtle.CreateFigure()
Turtle.TurnLeft()
Turtle.Move(200)
Turtle.MoveTo(200, 200)
Turtle.MoveTo(350, 200)
Turtle.MoveTo(X, Y)
GraphicsWindow.BrushColor = Colors.Red
Turtle.FillFigure()

image

@boa2145
Copy link
Author

boa2145 commented May 21, 2023 via email

@VBAndCs
Copy link

VBAndCs commented May 21, 2023

@boa2145
Note that you are replaying to GitHub no to my email, so, nothing is attached. You need to open this issue in GitHub and post any code and images you want.

@boa2145
Copy link
Author

boa2145 commented May 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants