ch01.md 985 B

Part I: Introduction to Nim via graphics

Chapter 1. Introduction

In this chapter we will show the basics of Nim language (types, for loops, if and case statements, procedures, etc.) while using basic graphic primitives to create shapes. The premise is that the putPixel proc exists and we can use it, not worrying about its implementation details. All we need to know is: that proc takes the x and y coordinate of a point and its Color (default: white), and places a pixel of that color at those coordinates for us. This is how to use it:

 import pixels  # 1
 putPixel(5, 9)          # 2
 putPixel(11, 18, Red)  # 3
  • 1 We import pixels so we can use the putPixel proc.
  • 2 Puts a white (that is the default color) pixel at the (5, 9) coordinate.
  • 3 Puts a red pixel at the (11, 18) coordinate.

Your Nim installation ships with a package manager called Nimble. Nimble can install additional packages. You can install the pixels library via: nimble install pixels