213
edits
No edit summary |
|||
Line 168: | Line 168: | ||
ellipse(100,100,20,20); | ellipse(100,100,20,20); | ||
</source> | </source> | ||
=== II Relations === | |||
<source lang="java"> | |||
/* RELATIONS | |||
* | |||
* Instead of using fixed values, we use variables | |||
* to formulate relations. In this example a structure | |||
* based on two vertical parallel lines with a circle | |||
* in between is formulated. | |||
* | |||
* Frederic Gmeiner 2011 | |||
*/ | |||
// variable to store the radius of the circle: | |||
int rad = 40; | |||
// variables to store the x and y position of the structure: | |||
int startPointX = 100; | |||
int startPointY =100; | |||
size(400,400); | |||
// left line starts at the defined values and has a length of 80px: | |||
line(startPointX, startPointY, startPointX, startPointY+80); | |||
// the ellipse in between the two lines has a radius of "rad", | |||
// so the width and hight is "2*rad". Since ellipses have their | |||
// origin in the middle in processing, we need to add the radius | |||
// to our "startPointX" value to have it centered in between the lines: | |||
ellipse(startPointX+rad, startPointY+40, 2*rad, 2*rad); | |||
// the right line is set in relation to the width of the circle: | |||
line(startPointX+(2*rad), startPointY, startPointX+(2*rad), startPointY+80); | |||
</source> | |||
=== III Functions === | |||
<source lang="java"> | |||
/* FUNCTIONS | |||
* | |||
* Here we define a custom function ("crossFunction()") which draws a | |||
* cross onto the screen. | |||
* It takes the parameters: X value, Y value and the size. | |||
* Also the continuous mode is introduced, which | |||
* uses the processing functions setup() and draw(). | |||
* Via the pre-defined variables "mouseX" and "mouseY" we | |||
* can access the current mouse position. | |||
* | |||
* Frederic Gmeiner 2011 | |||
*/ | |||
// the setup() function is called everytime the program | |||
// starts once. | |||
void setup(){ | |||
size(400,400); | |||
} | |||
// the draw() function is the main loop function of your program: | |||
// after every operation in the draw function has been | |||
// called, the draw function is called again. this | |||
// goes on until the program quits. | |||
void draw(){ | |||
background(255); | |||
crossFunction(mouseX,mouseY,10); | |||
} | |||
// this is the definition of the custom function "crossFunction()": | |||
void crossFunction(int crossX, int crossY, int crossSize){ | |||
line(crossX-crossSize/2, crossY-crossSize/2, crossX+crossSize/2, crossY+crossSize/2); | |||
line(crossX+crossSize/2, crossY-crossSize/2, crossX-crossSize/2, crossY+crossSize/2); | |||
} | |||
</source> | |||
[[Category:WS11]] | [[Category:WS11]] |
edits