Woopec - Introduction to C# Graphics and Woopec
In my opinion, C# is a great programming language. But for novice programmers, getting started is not that easy. It’s very easy to write console programs, but this gets boring quickly. Programs that allow you to draw something on screen are much more fun. In python and many other languages, beginners can use turtle graphics. For C# there isn’t that much yet. My current free time project is therefore the Woopec library. This is a C# library that makes it easy (hopefully) for novice software developers to get started with C# and (turtle) graphics.
How to start?
Where do you start if you want to learn programming?
The first thing you need to do is decide on a programming language. From my point of view, C# is a very good choice:
- C# is relatively new and well designed compared to other programming languages like Java, JavaScript or Python.
- C# is free, open-source and designed to work not only with Windows, but also with Linux or MacOS.
- C# has a large range of functions and is therefore also used for large professional programs.
- C# is used for game programming with Unity.
How do you learn to program with C#?
From my point of view it’s not a good idea to start with Unity right away. It’s a bit like trying to drive a truck before you’ve learned to ride a bike. If you’re new to programming, start with something simple.
The simplest are so-called console programs. But they quickly become a bit boring because you can only output texts with them. Learning to program becomes a little more exciting when you can also draw something on the screen. And that’s where Turtle Graphics come in. Turtle graphics have been around for a long time (e.g. for python), and they are so easy to learn that even novice programmers can start with them.
This quote from the documentation of the pyhton-Turtle-Graphics describes the advantages of turtle graphics:
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. […] give it the command turtle.Forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.Right(25), and it rotates in-place 25 degrees clockwise.
Turtle can draw intricate shapes using programs that repeat simple moves. By combining together these and similar commands, intricate shapes and pictures can easily be drawn
Woopec library, first turtle steps
With Woopec you can program turtle graphics with C#. Here you can see a small sample program:
public static void TurtleMain()
{
var turtle = Turtle.Seymour();
turtle.Right(45);
turtle.Forward(50);
turtle.Left(90);
turtle.Forward(100);
turtle.Right(45);
turtle.Forward(20);
}
This program produces the following result:
Woopec is free, you only have to install Visual Studio, which is also free, and download the Woopec package. Getting started describes this in more detail.
The next program is a bit bigger:
public static void TurtleMain()
{
var woopec = new Turtle() { Shape = Shapes.Bird, FillColor = Colors.DarkBlue, PenColor = Colors.LightBlue, Speed = Speeds.Fastest, IsVisible = false };
woopec.BeginFill();
do
{
woopec.Forward(200);
woopec.Right(170);
} while (woopec.Position.AbsoluteValue > 1);
woopec.EndFill();
woopec.PenUp();
woopec.Speed = Speeds.Slowest;
woopec.IsVisible = true;
woopec.Heading = 30;
woopec.Forward(200);
}
This is the result:
You can also draw more complicated things.
Woopec library, beyound turtles
Woopec can do more than just Turtle commands. In the example below, a spirograph curve was first drawn using Woopec commands. Then many objects were created that have the shape of this spirograph curve. And finally, these were drawn on the screen with different rainbow colors.
You can create multiple objects that move simultaneously on the screen. You can also coordinate the movements of objects. The example at the top of this page was created this way. You can find the animated version of this example here.
There are also commands to ask the user for input.
And can use Woopec without animations to draw things quickly. The following example calls the C# version of the pyhton ByteDesignDemo
public static void TurtleMain()
{
Woopec.Examples.TurtleDemoByteDesign.Run();
}
This example generates the following picture in just a few seconds:
I’m still developing Woopec and there will be more.
Give it a try and have fun.
Links
You can find more information here
- Getting started
- Features of turtle graphics
- Documentation of Woopec
- My blog posts about turtle graphics