|
Author |
Topic: Absolute Beginners Guide for coding in p5 (Read 533 times) |
|
elout
|
Absolute Beginners Guide for coding in p5
« on: Jan 8th, 2004, 11:52pm » |
|
Absolute Beginners Startup Guide for programming in processing quote from Arielm; (a bit out of topic but still relevant) i think there's an obvious lack of tutorials for real-beginners (i.e. the reference is too "advanced"), but hey, that's up to us (the "educators")! So here`s my first try to set up the first few bits of knowledge. And I start from when you managed to install p5 correctly (that`s is another faq I guess.) I will start with some basic knowledge, the rest will follow by me (and others I hope.) And I know although it`s easy for a coder to understand things quickly, but for a beginner it will be really difficult to understand, and the same for a coder to explain things. ------------------------------------------------------------ - Output - println - Copy the code into the white screen of processing window and press the play button. Code: println("hello world!"); println("this is processing"); |
| This will print the text into the bottom of your screen. (Besides opening a little grey window that is not used yet. But soon we will!) - Output - print - Now the same thing now with the print function. Code: print("hello"); print(" "); print("world"); print("!"); print("\n"); print("this " + "is "); print("processing"); |
| the print command doesn`t use line-breaks like println but in this example the "\n" creates the new line-break for you. ------------------------------------------------------------ - Adding comments into your source - If you create some software, it`s a good thing to tell you or other programmers what`s going on. Good documentation is really a must, so just do it! Imagine you wrote some piece of software 1 year ago, and you want to re-use again, comments are really helpfull then/always. Code: // this is a comment, it won`t hurt anything or mess with your code // but you can use it for sharing information. println("hello world!"); // this will print 'hello world' |
| or like this Code: /* this is a comment, it won`t hurt anything or mess with your code but you can use it for sharing information. */ println("hello world!"); // this will print 'hello world' |
| ------------------------------------------------------------ - Numbers and math - int - Code: int a=2; int b=3; int c=a+b; println("my a = " + a); println("my b = " + b); println("my c = " + c); |
| adds a+b and put into c Some other ways for adding/substracting Code: int a=0; println("my a=" + a); a++; // add 1 to my a println("my a=" + a); a+=5; // add 5 to my a println("my a=" + a); a--; // substract 1 from my a println("my a=" + a); |
| Note int are 'real' numbers (without floating points), so if you try this. Code: int a=5; int b=2; int c=a/b; println("my a = " + a); println("my b = " + b); println("my c = " + c); |
| The computer will calculate this to another 'real' number that is an integer. - Numbers and math - float - now I want to work with some floating point numbers Code: float a=5; float b=2; float c=a/b; println("my a = " + a); println("my b = " + b); println("my c = " + c); |
| Or the same thing using float`s and int altogether. Code: int a=5; int b=2; float c=(float) a/b; println("my a = " + a); println("my b = " + b); println("my c = " + c); |
| ------------------------------------------------------------ - loops - for Code: for (int i=0;i<50;i++) { print( i + " yeah! "); } |
| prints out the value of 'i' and the word 50 times Now analysing this 'for' loop int i=0; creates a new integer called 'i' with the value '0' i<50; means: is 'i' still smaller then 50?? i++; increases the i by one every time it goes around the loop. and you really don`t need to start at 0 Code: for (int i=20;i<70;i++) { print(" " + i); } |
| or start from 50 till 0 Code: for (int i=50;i>0;i--) { print(" " + i); } |
| note i>0 means if 'i' is still bigger then 0 - loops - while Code: int i=0; while (i<50) { i++; print(" - " + i); } |
| to be continued.. [edit]some typo`s[/edit]
|
« Last Edit: Jan 9th, 2004, 2:30pm by elout » |
|
|
|
|
arielm
|
Re: Absolute Beginners Guide for coding in p5
« Reply #1 on: Jan 9th, 2004, 1:18pm » |
|
hey elout, nice initiative! one comment: at some points, you use the term "command" instead of "comment". + one suggestion: why not posting this one in the "Teaching/Theory & Practice" board, since it's the place absolute beginners will naturally look at for tutorials? a+
|
« Last Edit: Jan 9th, 2004, 1:19pm by arielm » |
|
Ariel Malka | www.chronotext.org
|
|
|
|