CHAPTER 6

Programs to Generate Simple Line Drawings 


You now know how to write the simplest kind of program to generate a line drawing.

- Primitive Graphic Commands:

6.1 Square

prog6_1.jpg

  1. size(1024,1024);
  2. line(400,200,700,200);
  3. line(700,200,700,500);
  4. line(700,500,400,500);
  5. line(400,500,400,200);

6.2 Cross

prog6_2.jpg

  1. size(800,600);
  2. line(400,200,700,500);
  3. line(700,200,400,500);


- A Complete Graphics Program:

6.3 Square: setup and draw

prog6_1.jpg

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. void draw(){
  6. line(400,200,700,200);
  7. line(700,200,700,500);
  8. line(700,500,400,500);
  9. line(400,500,400,200);
  10. }

6.4 Square: using variables

prog6_1.jpg

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. void draw(){
  6. int x1 = 400;
  7. int y1 = 200;
  8. int x2 = 700;
  9. int y2 = 500;
  10.  
  11. line(x1,y1,x2,y1);
  12. line(x2,y1,x2,y2);
  13. line(x2,y2,x1,y2);
  14. line(x1,y2,x1,y1);
  15. }

6.5 Square: reading in coordinate values

prog6_5.jpg

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. String typing = "";
  6. String saved = "";
  7.  
  8. void draw(){
  9.  
  10. //Prompt the request
  11. text("ENTER INTEGER FOR X1 AND PRESS ENTER",10,90);
  12. text(saved,10,130);
  13.  
  14. //The string is converted to its
  15. //integer representation
  16. int x1 = int(saved);
  17. int y1 = 200;
  18. int x2 = 700;
  19. int y2 = 500;
  20.  
  21. //Draw the square when x1 is different from 0
  22. if(x1 != 0){
  23. line(x1,y1,x2,y1);
  24. line(x2,y1,x2,y2);
  25. line(x2,y2,x1,y2);
  26. line(x1,y2,x1,y1);
  27. }
  28. }
  29.  
  30. //This is a function where we detect the value
  31. //pressed on keyboard
  32. void keyPressed(){
  33.  
  34. //In case enter is pressed, saves the sequence
  35. //of numbers in a string
  36. if (key == '\n' ) {
  37. saved = typing;
  38. typing = "";
  39. } else {
  40. typing = typing + key;
  41. }
  42. }

 

Exercises

1. Gridded Paper

  Screen_Shot_2013-06-18_at_4.52.30_AM.png

2. Equilateral Triangle

ex6_2-1.jpg

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. void draw(){
  6. line(300,200,400,373.2050);
  7. line(400,373.2050,200,373.2050);
  8. line(200,373.2050,300,200);
  9. }

3. Initials

          In this example, we used the autor's initials, WJM. 

ex6_3.jpg

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. void draw(){
  6. line(10,10,30,110); //W
  7. line(30,110,50,50);
  8. line(50,50,70,110);
  9. line(70,110,90,10);
  10.  
  11. line(110,10,150,10); //J
  12. line(130,10,130,110);
  13. line(100,110,130,110);
  14. line(100,110,100,95);
  15.  
  16. line(170,10,170,110); //M
  17. line(170,10,190,70);
  18. line(190,70,210,10);
  19. line(210,10,210,110);
  20. }

5. Paul Klee's Active Line

ex6_5.jpg

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. void draw(){
  6. line(30,300,220,200); //1st line
  7. line(220,200,190,280); //2nd line
  8. line(190,280,450,260); //3rd line
  9. line(450,260,420,350); //4th line
  10. line(420,350,600,180); //5th line
  11. line(600,180,630,200); //6th line
  12. line(630,200,620,320); //7th line
  13. line(620,320,700,300); //8th line
  14.  
  15. }

Comments

Posted by admin on
Test.
Posted by http://www.lygialimayoga.com.br on
MOURA, A. A.; SILVA, M. A. M.; FERRAZ, M. R. M. T.;
RIVERA, I. R. Prevalência com pressão nas artérias distinta
perante escolares e também adolescentes de Maceió. http://www.lygialimayoga.com.br
Leave a Reply



(Your email will not be publicly displayed.)


Captcha Code

Click the image to see another captcha.