Net.Processing
1.9
Documentation
|
Main reference (NetProcessing.Sketch class, in French).
Quick Reference with links to Processing pages. (in English)
Sorry, only this page and the Quick Reference are in English for now.
Net.Processing (pronounced net processing) is a simple graphical library using the model offered by Processing (www.processing.org), but adapted to C#/.NET standards. Net.Processing is really similar and Processing documentation (www.processing.org/reference) can be used to learn more about the possibilities of Net.Processing (see also the quick reference guide). Net.Processing was developped mainly to be used by computer science students, in a first or second programming course.
The main difference from Processing is that Net.Processing mostly use integer parameters for positions and sizes (Processing uses float
, but does not need the f
suffix for litteral value, that would be necessary, and annoying, in C#).
Most of the time, the programs deal with pixels, so integers are more natural and simpler. However, in many calculations, conversions and rounding (mostly from doubles
) will be necessary. It's something that must be learned properly and that's one of the reasons why Net.Processing intentionaly uses integers. An "all double" version of Net.Processing is also planned.
The other important difference is that, in Net.Processing, identifiers follow .NET convention of using a capital initial letter in properties, methods, etc., whereas Processing use a lowercase letter. So Net.Processing offers FrameCount
, Rect()
, Size()
, etc., instead of frameCount
, rect()
, size()
, etc. The uppercase constant names (CENTER
, LEFT
, PIE
, ARROW
, etc.) do exist in Net.Processing, but other more natural names, in enum
types, can also be used (Parameter.Center
, Parameter.Left
, ArcStyle.Pie
, MouseCursor.Arrow
, etc.).
Other permanent differences, because of technical aspects of C#/.NET:
bool
. Color(...)
method; to create a color use new Color(...)
;¹ #
, but the value can be put in a string
(for example "#4C12A6"
); frameRate
variable is a property called FrameRateValue
. FrameRate()
is the method to change its value;²mousePressed
et keyPressed
are called IsMousePressed
and IsKeyPressed
. MousePressed()
and KeyPressed()
are the methods to be overriden to detect actions from the mouse or the keyboard;² level
parameter has no effect in Smooth(level)
; keyboard codes (for KeyCode
) starts with KC_
(for example KC_DOWN
). There are much more of these values than in Processing.
In most cases, the reason Net.Processing is different is because Processing accepts some dubious constructs:
¹ In C#, a method cannot have the same name as a class.
² In C#, a property cannot have the same name as a method.
Other differences, that could change in the next versions of Net.Processing :
ColorMode()
exists but does nothing, it's always RGB mode; LoadImage()
does not work with URL; Net.Processing adds the MouseDoubleClicked()
method, that can be overriden to detect double-clicks..
Contrary to Processing, Net.Processing can completely interact with the user through a standard console (Console.ReadLine()
, Console.Write()
, etc.) by creating a console application. So a console is normally opened at startup, along with the graphical window. It is brought to front whenever there is an input operation (Console.ReadLine()
for example). It can be hidden using the HideConsole()
method, but it will be shown at startup and reopened if there is an input operation. The console can be completely eliminated by changing to a Windows Application project.
To help getting started, Net.Processing adds the ReadConsoleInt()
, ReadConsoleDouble()
, ReadConsoleString()
and ReadConsoleChar()
methods to read (and validate) values from the console.
Creation (version 1.9) : Michel Michaud, december 2013 - october 2017
Copyright ©Michel Michaud
To use Net.Processing :
using NetProcessing;
can be added but many programs will only refer once to the NetProcessing namespace. Program
class from NetProcessing.Sketch
: "class Program: NetProcessing.Sketch
" (or class Program: Sketch
if using NetProcessing
was used). Main()
, call Start()
: new Program().Start();
. NPMain()
method: type override
than a space, than choose NPMain()
. The general application code (that would be globally written in Processing) can now be written in the NPMain()
method... Draw()
method (see above). That method will be called repeatedly. The Setup()
method can also be overridden, it will be called only once, before the calls to Draw()
. base.NPMain()
, base.Draw()
ou base.Setup()
) should be removed. Program
class. However, by adding the new classes inside the Program
class, using the Sketch.
(or NetProcessing.Sketch.
) prefix won't be necessary, so it will be more like normal Processing code. Original Processing program and Net.Processing/C# version (the basic usings are omitted):
/** namespace Pointillism * Pointillism { * by Daniel Shiffman. class Program : NetProcessing.Sketch * { * Mouse horizontal location controls size of dots. static void Main(string[] args) * Creates a simple pointillist effect using ellipses colored { * according to pixels in an image. new Program().Start(); */ }
PImage img; PImage img; int smallPoint, largePoint; int smallPoint, largePoint;
void setup() { public override void Setup() size(640, 360); { img = loadImage("moonwalk.jpg"); Size(640, 360); smallPoint = 4; img = LoadImage("moonwalk.jpg"); largePoint = 40; smallPoint = 4; imageMode(CENTER); largePoint = 40; noStroke(); ImageMode(CENTER); // Or ImageMode(Parameter.Center); background(255); NoStroke(); } Background(255); }
void draw() { public override void Draw() float pointillize = map(mouseX, 0, width, smallPoint, largePoint); { int x = int(random(img.width)); int pointillize = (int)Map(MouseX, 0, Width, smallPoint, largePoint); int y = int(random(img.height)); int x = (int)Random(img.Width); color pix = img.get(x, y); int y = (int)Random(img.Height); fill(pix, 128); Color pix = img.Get(x, y); ellipse(x, y, pointillize, pointillize); Fill(pix, 128); } Ellipse(x, y, pointillize, pointillize); } } }