CHAPTER 5

The Processing Programming Language


We have now introduced the basics of Processing: how a program is set out; how variables and constants are declared; how numbers may be input; how arithmetic may be performed; and how results may be output.

- The General Organization of a Processing Program:

5.1 Building

prog12_1.png

  1. //Settings
  2. void setup(){
  3. size(800,600);
  4. }
  5.  
  6. //Execute and repete
  7. void draw(){
  8. pantheon(400,300,200);
  9. }
  10.  
  11. //Function created by the programmer
  12. void pantheon(int x_square,int y_square,int side){
  13.  
  14. //Relate circle to square
  15. int x_circle = x_square;
  16. int y_circle = y_square;
  17. int diameter = 2*side;
  18.  
  19. //Draw circle
  20. ellipse(x_circle, y_circle, diameter, diameter);
  21. //Draw square
  22. rect(x_square, y_square, side, side);
  23. }

5.2 Rectangle

Output: 1000

  1. //Give values to length and width
  2. int length1 = 50;
  3. int width1 = 20;
  4.  
  5. //Calculate area
  6. int area = length1 * width1;
  7.  
  8. //Print out the result
  9. print(area);

Comments

Leave a Reply



(Your email will not be publicly displayed.)


Captcha Code

Click the image to see another captcha.