We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am looking for something that I can interact with. Like http://www.w3schools.com/ , which I used for html/css/javascript. Rather than videos. In order to learn Processing. Currently the only one I know is:
http://www.learningprocessing.com/examples/
Any others?
Answers
on the main page you find tutorials and examples
in processing included you find examples (menu file)
see also http://www.openprocessing.org
see also a complete book here
http://natureofcode.com/book
there is also the WIKI with interesting "technical FAQ"
http://wiki.processing.org/w/Main_Page
http://wiki.processing.org/w/Technical_FAQ
Books
there are a lot more books when you look on the main page, section books
http://www.processing.org
and of course khan academy
Thank you.
you're welcome!
I think the best way to learn is to practice.
Think of small tasks and try to accomplish them.
E.g. make this:
or this
or make pong or 3D pong or boggle or pac man or snake or tetris or arkanoid
http://en.wikipedia.org/wiki/Arkanoid
or write an editor or tic tac toe
or
Peg solitaire
http://en.wikipedia.org/wiki/Peg_solitaire
Graph of a function in 2D and 3D
http://en.wikipedia.org/wiki/Graph_of_a_function
or a paint program
you'll find them all on wikipedia
I'm just a beginner. Making those things you listed is way beyond my level at the moment.
the stars at the beginning of my post may not be too hard.
Also pong is not hard.
It's good to practice OOP.
;-)
Nice!
Now do the same with circles in the main window
Nice!
and now with lines...
You mean something like:
yes, but with different lengths like the stars
also different color and thickness
You could then make a class LineMine and store the properties there
and then you could move them
finally you could go 3D
just go step by step...
How far are you now?
;-)
Do floats have to be initialised? As I couldn't run without first giving r,b, and g initial values. I thought by default, if you don't initialise them, they are set to 0.0f? Hence, that it's necessary to initialise?
float r;
is enough
it's 0.0 then
That's what I get when I just have "float r;"
And isn't it, 0.0f?
all right!
See now you're better than me
You could then make a class LineMine and store the properties there
Lol, I don't understand why I must initialize? r isn't a local variable. I'm not sure what's going on.
yeah, it's a global variable in processing, you are right
from what's going on behind the scenes it's a local var
don't worry about this, it's need an initial value
you should say this
before
otherwise 1st line is always black ;-)
You could then make a class LineMine and store the properties there
I don't understand why it's treated as a local variable?
No, that's not the right approach.
The class should hold only one item of a type (a line e.g.) - that's the purpose of a class
when you have multiple lines, pls. instantiate multiple objects in an array
pls consider
just write
color lineColor;
I didn't understand. I also didn't understand why r is treated as a local variable, when I have it as a global variable.
don't worry over r, it's a technicality
for the class: it needs posX,posY, length, color, thickness ...
define it in setup()
Well it just confuses me, as it contradicts what I've read regarding global vs local variables. Global variables are accessible throughout the program. I've declared it as global, and didn't have a local variable in that function (that would of masked the global variable). So it doesn't make sense as to why it's treated as local, when I didn't declare it as a local variable (in which case, the error message would make sense, as you have to initialise local variables). I'm finding programming hard enough, I don't need the added stress of confusing error messages.
this works
it's probably a thing of active versus static mode
you're right it's a global var
Okay thanks. Got a lot to study.
yeah, when you want to practice, work on that class as I said
;-)
I am not sure what this means?
So the class, should look like this:
And that if I want more lines, have multiple objects?
that's correct!
for the class: it needs posX,posY, length, color, thickness ...
then you could start before setup() with
and handle those in draw()
http://www.learningprocessing.com/exercises/chapter-9/exercise-9-7/
While practising, I didn't understand this class.
I didn't understand, why it's not:
Rather than;
why did you quit our nice lines? It's not finished!
Lol I didn't quit anything. I struggled with understanding Objects & Arrays, so returned back to the chapter on Arrays, tried a few examples to re-understand, and got stuck on the one above. It feels like I'm progressing, but then feels like I'm not learning as much as I thought.
As for the snakes:
since it's wonderfully commented, it's easy:
each snake consists of the elements of the body.
Each element is stored with x and y pos in 2 parallel arrays (we could use PVector instead)
look at display() to see how it is used
ellipse(xpos[i],ypos[i]
the radius is also i, so the size is bigger (try 10 instead of i)
update()
update() has the purpose to move the snake:
the head comes as a new pos where the mouse is
the elements after the head each get the pos of the element before it
Ok thanks.
Is this correct?
that's better
look, c1 in the constructor could be called c_
so all parameters end with the sign _
that's good to have same things identified as being same (parameters)
now, you understood that a class holds one type of item and only one (a line in that case).
next step
Now as a next step you could e.g. start using an array of lines
then instead of
you could for-loop over it
also in setup() you would have an array instead of so many similar lines
so
Linemine [] lines;
etc.
A class can hold more than one type of item, right? But it defeats the purpose of a class, since it's use is made for one type of item only? A cookie cutter after all, is made for making cookies only. Same with class. Right?
correct!
it's made for one type of item like a line or a car or a ball.
This entity has different properties (like position and length) and methods
Seems like you had re-declared fields as local variables by using the same name, overshadowing their field counterparts!
Only fields are auto-initialized w/ a corresponding default value appropriate for their data-types!
On the other hand, local variables demand an initial value before their usage!
Yes to both comments above.
But I keep getting confused with fields and global variables. Let me get this straight, once and for all!! I've looked at all the past posts and this is what I've arrived at:
Lets take a look at a portion of the snake class above:
These are "non-static fields". When an object is instantiated, by calling the constructor, the non-static fields are instantiated. Everything else in the class is not, to save memory.
So each object, gets it's own individual copy of the "non-static fields" from the class, when it's created. The constructor is responsible for giving the "non-static fields" initial values. So object, in memory, only contains "non-static fields" and values assigned to those fields. No methods, nothing else. But the object can access those from the class, as if it belonged to the object itself. So it appears the object "inherits" everything from the class, but only "non-static fields" are taken from the class, and the rest remain.
Another name for "non-static fields" is "instance variables". Because each instant of a class (each object), have values unique to it.
"Static" fields are not instantiated, and shared among all objects of the class.
A field declared with a "static" modifier, is called a "Class Variable" or "static field". For example:
"A state" means a "value"?
A "field" is like a "global variable". It is a type of variable that has a scope throughout the entire program/class (i.e not declared within a method). A class variable has scope throughout the whole class, and is accessible from any method of that class, static or instance (non-static). So a class variable is a field, a static field.
Fields are given default values (if not initialised) depending on their data type (i.e 0.0f for float, 0 for int, false for boolean etc). Local variables are not given default values, thus MUST be initialised, or error will occur.
Is this all correct?
I will like to thank you both for your patience & support. It's been very helpful! It's only been a few weeks of Processing for me, so it's going quite good so far! With your help, I'm sure to get a lot more advanced within a short period of time. ;)
Let's retry it!
All object creations (instantiations) involve dynamically (at runtime) setting apart a contiguous block of memory
(generally from the heap zone) of just enough size, so each of them can have their own copy of all the non-static fields
(instance variables) from their class.
Even though it's a block of memory, for reference purposes, it's enough to track it by its 1st physical memory address.
Java has its own means to determine both the size of the block and where each field is at within it by that value alone!
That memory value is called reference or pointer to that object. In order to maintain a track of it,
there gotta be at least 1 variable holding that value, thus making a strong reference to it.
Objects which got no variable strongly referencing it & it's not currently active are marked for destruction by the GC!
Within a class context, keyword
this
means the reference value which is currently accessing a class member.A class is generally instantiated by using keyword
new
& calling its constructor.Which in turn implicitly returns
this
, so we can both keep track of it and access its members.Even though an object stores non-static fields only, we still have access to the rest of its class' members transparently!
All non-static fields (instance variables) from an object form what is called the state of an object.
An object is considered having the same state as another when all their non-static fields have exactly the same values!
I think that's all for now! ;)
Thanks.
What is "the heap zone"?
A special area in memory, for objects, arrays, classes etc?
How can an object have no variable strongly referencing it?
Don't we have to declare, for example;
Forgive me, but I'm still struggling to understand this part.
https://en.wikipedia.org/wiki/Stack_and_heap
Merely instantiate an object w/o assigning it to a variable:
new PVector(10, 30, -50.5);
The recent instantiated object above got no variable holding/tracking its reference.
It'll be put in the "death row". And eventually "executed" by the Garbage Collector (GC)!
A class has members: static & non-static fields, methods & constructors.
In order to access any of those members, we need a reference plus the dot
.
operator:http://processing.org/reference/dot.html
hey, xb23, that is all under the hood of the system
you seem to me like somebody who wants to learn to drive and starts by taking apart the engine and trying to understand it.
Two different things.
Better concentrate on practicing.
What are they gonna ask you in your exam? Nothing about the heap, right?
Chrisir, I understand what you're saying. Since I'm studying for a Computer Science degree, I'm eager to learn as much as I can, even the small technical details, as it helps understand what's going on, when I'm learning Programming (and why errors occur etc).
But I suppose, you're right. Best to practice now, and worry about what's under the hood in year 2, as it hasn't been covered this year. I'm in year 1 of a 3 year course. I just feel that there is so much to learn, and I want to catch up, that's why I'm asking lots of questions.
;-)