Writing code: experimentation is the best part

random_by_jmummeyI recently wrote a desktop application, a small piece required that I draw a simple rectangle to the screen. When I drew the rectangle I made an error, I put the x-coordinate in as the width and the width as the x-coordinate. The result was pretty but not what I wanted so I fixed it and moved on. But I came back to it later that night and started fiddling with the code to generate more unexpected graphics. In the end I had written a simple method in the C# language where I feed it random x and y coordinates as well as random height and width sizes and random shapes to draw on the screen. I liked the images so much (only because some remind me of Star Trek) that I picked out what I consider to be the coolest 60 images and published them in my first artistic coloring book called “Random”. The book size is 8 ½ x 11 and each image is on the right with a blank page on the back so the images can easily be colored, removed and framed without disrupting the other images. Check it out and color all of your boring processes away: https://www.amazon.com/Random-Coloring-computer-generated-coordinates/dp/1539987582

If you are interested in learning how to write code, the instructions below will help you get started, these are the steps I went through to create some of the artwork in the book Random that I mention above, enjoy and code on:

Language used:  C#
Type of application written:  console application running on my Windows desktop PC (no server needed)
Developer tools used:  Visual Studio, running on my Windows desktop PC (this is available to you for free): https://www.visualstudio.com/free-developer-offers/

Steps performed for drawing ellipses:

  1. Install Visual Studio from the link provided above
  2. Reboot
  3. Open Visual Studio
  4. Select File > New > Project > Templates > Visual C# > Windows > Classic Desktop > Console Application
  5. Name the application and choose a location to store it > select OK
  6. The “Program.cs” file should have opened by default for you. It will look something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
class Program
static void Main(string[] args)//main method begins

}//main method ends



  1. Look in the Solution Explorer (View > Solution Explorer) and add a reference to a library for drawing:
  2. Click once on “References”, right click and select “Add Reference” and find “System.Drawing”, place a checkmark beside “System.Drawing” and select OK
  3. Towards the top of “Program.cs” add this: usingDrawing; and also add using System.Drawing.Imaging;
  4. Inside the Main method, add the following for loop (the purpose of this for loop is make many images. If you set this for loop to run 40 times then that means 40 images will be created and stored in the Temp directory on your c drive.  If you set this for loop to run 10 times then only 10 images will be created and stored in the temp directory on your c drive:

for (int t = 0; t < 40; t++)

makeSweetImages3();   //call method repeatedly to create multiple images



  1. Under the Main method, add the following method, this method does all of the work (declares random coordinates, draws the image and stores the image):

static private void makeSweetImages3()

DateTime localDate = DateTime.Now; //we use the milliseconds to uniquely name each image
Random rnd = new Random();
Bitmap bitmap = new Bitmap(2552, 3302);//width, height
bitmap.SetResolution(300, 300);

// Draw graphic
int z = rnd.Next(1, 2550);//to represent width of item being drawn keep btw these values
int b = rnd.Next(1, 3300);//to represent height of item being drawn keep btw these values
int k = rnd.Next(0, 2550 – z);//to represent item on the x axis keep between these values
int m = rnd.Next(0, 3300 – b);//to represent item on the y axis

using (Graphics gr = Graphics.FromImage(bitmap))
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//type of line

for (int p = 0; p < 10; p++)//number of ellipses being drawn for this one image
System.Drawing.Rectangle rect5 = new System.Drawing.Rectangle(k, m, z, b);
// x, y, width, height, stage is set for graphic, when you draw an ellipse you
//have to define its outer rectangle first then draw the ellipse within or on
//said rectangle
using (System.Drawing.Pen thick_pen = new System.Drawing.Pen(System.Drawing.Color.Black, 2))
gr.DrawEllipse(thick_pen, rect5);//draw graphic
z = rnd.Next(1, 2550);//width
b = rnd.Next(1, 3300);//height
k = rnd.Next(0, 2550 – z);//x
m = rnd.Next(0, 3300 – b);//y


bitmap.Save(@”C:\Temp\” + localDate.ToString(“yyyyMMdd-HHmmssfff”) + “.png”, ImageFormat.Png);
//save image to Temp directory on c drive

  1. Run the console application by selecting Debug > Start without Debugging (you will notice a black console window will appear, once the console window displays “Press any key to continue…” you will know all drawings are complete, press any key to close the console window)
  2. Navigate to C:\Temp on your computer and view the beautiful images you just created

Want to learn how to write applications for computers and devices? Microsoft is opening up Visual Studio and .NET to individual developers for free!

Visual Studio is one of the tools I use to write some of the web and console applications my clients use each day.  Visual Studio offers a pretty stable and user-friendly environment for writing Windows, Android and iOS applications, this would be a good environment to learn in if you would like to start programming.

Here are a few steps to get started (perform these steps on your home computer):

  1. Make sure you have at least Internet Explorer Version 10 installed on your home computer (you don’t absolutely have to have IE 10 but having version 10 will be a little less problematic). If you would like to install IE 10, you may install it from here: (first close all running applications on your home computer) http://windows.microsoft.com/en-US/internet-explorer/download-ie and reboot after the installation.
  2. Install IIS on your home computer (first close all running applications on your home computer). Installing IIS on your home computer will allow you to easily view and test web applications from your home computer. If you do not install IIS, then you will not be able to easily test any web applications you create on your home computer, you will be forced to deploy your code to a web server somewhere to properly test it. Carefully review the screenshots on this page. The screenshots demonstrate how to install IIS on your home computer (the steps vary depending on your Windows version but this gives you a good idea of how the installation is done): http://www.howtogeek.com/112455/how-to-install-iis-8-on-windows-8/.
  3. Download and install the Visual Studio software and tools to your home computer from here (read the system requirements before installation, the system requirements are towards the bottom of the download page and also close all running applications on your home computer prior to install): http://www.visualstudio.com/en-us/products/visual-studio-community-vs. You may keep the default selections during the installation. This installation may take up to two hours depending on the processing power of your home computer so plan on starting the installation and walking away (just check on it every 20 minutes or so). Do not attempt to do any other work on your home computer during this installation.
  4. Reboot your computer once the installation is complete. At the end of this installation it tells you that you may immediately launch Visual Studio but just out of best practice I always reboot following any installation. So, either click on “Launch” at the end of the installation or reboot and then find the Visual Studio icon on your desktop and double click on it to open Visual Studio (it may be in your start menu under Start > All Programs > Visual Studio 2013).
  5. You don’t have to sign in right now, I would recommend doing it at some point but as you are learning you can skip sign in by selecting “Not now, maybe later”.
  6. You might be prompted to set up your environment for the first time.  If you are, select “Visual C#” from the Development Settings dropdown menu.  You don’t have to select this.  C# is just what I select since I know I will primarily write in the language C#, this can be changed later to something else. Choose a color theme if you are prompted. Select Start Visual Studio. Note: opening Visual Studio for the first time may take several minutes.
  7. With Visual Studio open, you are now in the exploration and experimentation phase. This is where you will look around, read, watch tutorials, and try out sample code to learn as much as you can before jumping in. The first link you should see towards the top of the interface is “New to Visual Studio? Check out coding tutorials and sample Projects” (http://msdn.microsoft.com/en-us/vstudio/dn439939), click on this link and begin! Expect to spend at least 40 hours in this exploration and experimentation phase to get a strong understanding of the environment and writing basic code. I would also recommend watching youtube.com tutorials on Visual Studio (ex. from youtube.com search on this phrase: visual studio community 2013 tutorial).

If you’ve made it through the exploration and experimentation phase of step 7 above, and you are still excited about programming, then it is time to jump into the deep end:

  1. Now is as good a time as any to decide what kind of programmer you will be.  Avoid lying to yourself, you know you better than anyone else ever will.  If you think you are a bad person then you will probably write code with malicious intent.  If you think you are a good person then you will hopefully write code with good intentions.  If you think you are a bad person but believe your ‘badness’ will go undetected because you will write code with malicious intent disguised as code with good intent, you are mistaken.  In the end all secrets are revealed, it doesn’t matter how well you attempt to conceal them.
  2. Carefully review programming rules and best practices from the following sites: http://msdn.microsoft.com/en-us/library/aa260844(v=vs.60).aspx and http://www.w3.org/standards/. They may not make much sense now but they will as you begin to code.
  3. Carefully review code of ethics postings for computer professionals, ACM has a really good one:  http://www.acm.org/about/code-of-ethics, or Wikipedia: http://en.wikipedia.org/wiki/Programming_Ethics.
  4. Complete an introductory computer science book (ex. Invitation to Computer Science by G. Michael Schneider and Judith Gersting).  Make sure you read every chapter and successfully complete every exercise in the book.
  5. Learn HTML, the most basic language for creating web pages.  Go through the fantastic tutorials and chapters found here: http://www.w3schools.com/html/.

I will add more steps soon, happy coding!

Create a free website or blog at WordPress.com.

Up ↑