<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ian Kloppers</title>
    <description>The latest articles on DEV Community by Ian Kloppers (@iankloppers).</description>
    <link>https://dev.to/iankloppers</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F227086%2Fd6074f2d-d465-4b6d-8fd8-0c01ed75808f.png</url>
      <title>DEV Community: Ian Kloppers</title>
      <link>https://dev.to/iankloppers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iankloppers"/>
    <language>en</language>
    <item>
      <title>SketchIt (C#) Intro - Just Draw Something</title>
      <dc:creator>Ian Kloppers</dc:creator>
      <pubDate>Tue, 10 Sep 2019 21:22:45 +0000</pubDate>
      <link>https://dev.to/iankloppers/sketchit-c-intro-just-draw-something-4p0e</link>
      <guid>https://dev.to/iankloppers/sketchit-c-intro-just-draw-something-4p0e</guid>
      <description>&lt;p&gt;This is my first post, so please bear with me, and let me know where and how I can improve on my writing skills.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is SketchIt
&lt;/h1&gt;

&lt;p&gt;&lt;a href="http://sketchit.org"&gt;SketchIt&lt;/a&gt; is a small, .NET based development environment, created to have fun while learning to code, or simply to sketch together a visual idea using code. The project was launched in August 2018, and heavily inspired by the Processing open source project. I hope to create a similar experience for .NET developers as what &lt;a href="https://processing.org"&gt;Processing&lt;/a&gt; does for Java/JavaScript (&lt;a href="https://p5js.org"&gt;p5.js&lt;/a&gt;) developers.&lt;/p&gt;

&lt;p&gt;SketchIt &lt;strong&gt;is not&lt;/strong&gt; an alternative (not even close) to an IDE like Visual Studio, but rather an environment where you can immediately start to code, and not be intimidated by an advanced IDE such as Visual Studio:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vMKxUjMf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fsr464teyds9hdzgx7xa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vMKxUjMf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fsr464teyds9hdzgx7xa.png" alt="SketchIt IDE"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Some key concepts
&lt;/h1&gt;

&lt;p&gt;When needed, SketchIt "wraps" your code into a class which allows for code to be entered without declaring namespaces/classes/methods. The following code can be entered into the SketchIt code editor and run without an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;PrintLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above example is referred to as a "static" sketch, which means the code is executed sequentially from top to bottom, and the program comes to an end.&lt;/p&gt;

&lt;p&gt;When developing a SketchIt project, there are two ways to generate output to the screen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;writing to the console window&lt;/li&gt;
&lt;li&gt;drawing to the canvas&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Writing to the console is as simple as using the &lt;code&gt;PrintLine()&lt;/code&gt; or &lt;code&gt;Print()&lt;/code&gt; methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nf"&gt;PrintLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drawing to the canvas is done using different draw methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nf"&gt;DrawCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, the above example can be entered into the SketchIt code editor as is and the program will run without an error. The resulting program will draw a circle on the canvas at a random location within the size (&lt;code&gt;Width&lt;/code&gt; and &lt;code&gt;Height&lt;/code&gt;) of the canvas, and the diameter (in pixels) of the circle is based on a random number between 10 and 50:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hWocWcg4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9hyw6n22kwwtj86e2cmu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hWocWcg4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9hyw6n22kwwtj86e2cmu.png" alt="Draw a circle"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Making use of the animation loop
&lt;/h1&gt;

&lt;p&gt;To make use of the animation loop, you need to have a &lt;code&gt;Draw()&lt;/code&gt; method declared. The &lt;code&gt;Draw()&lt;/code&gt; method is called a number of times per second, based on the requested frame rate. The default frame rate is 60 frames per second, which means the &lt;code&gt;Draw()&lt;/code&gt; method will be called 60 times per second.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SIDE NOTE: SketchIt currently implements rendering using GDI+ drawing routines, so frame rates can become slower than requested once animations become more complicated, especially when running a sketch in full-screen mode. If you are a developer with OpenGL experience, then please get involved to help develop an OpenGL renderer.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If we take the previous example which draws a random circle, and we put it into a &lt;code&gt;Draw()&lt;/code&gt; method, we will have a program generating random circles in a continuous loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;DrawCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make it a bit more interesting, we can clear the background of the canvas with a black, semi-transparent color:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;DrawBackground&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;DrawCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above example will create an animation which draw circles that appear to fade away:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HeVfu8Hd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3lnpf10kwdgxe3jefnob.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HeVfu8Hd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3lnpf10kwdgxe3jefnob.gif" alt="Fading circles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another important method that can be utilized is the &lt;code&gt;Setup()&lt;/code&gt; method. This method is called when the program starts, and is intended to be used to "set up" your program, like loading data, initializing objects (like video camera) or setting the canvas size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//set the size of the canvas to 800 x 400 pixels (width x height)&lt;/span&gt;
    &lt;span class="nf"&gt;SetSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;800&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;DrawBackground&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;DrawCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The preview pane scales the canvas to fit:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pinj3xMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e7842uelsjhbvsxcv5wh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pinj3xMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e7842uelsjhbvsxcv5wh.png" alt="Using Setup()"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Running the project
&lt;/h1&gt;

&lt;p&gt;When the project is run, an &lt;em&gt;executable (.exe)&lt;/em&gt; is compiled and launched:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R5UTRPWB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ampo287cxamxsqu8d0eq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R5UTRPWB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ampo287cxamxsqu8d0eq.png" alt="Launch a sketch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SketchIt attempts to embed the required resources into the &lt;em&gt;.exe&lt;/em&gt; so you can easily share your project without having to include additional files. This, of course, may not always be possible depending on additional libraries referenced by your project.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;This really was just a quick introduction to what SketchIt is, and what it attempts to accomplish. Please &lt;a href="http://sketchit.org"&gt;download&lt;/a&gt; and play around with it, or maybe get involved via &lt;a href="https://github.com/sketchit/sketchit"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope to post more soon, and maybe work through a small project like a basic game, and how to make use of additional drawing methods and keyboard/mouse input.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>tutorial</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
