Guest User

Untitled

a guest
Jul 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. You are provided with an incomplete program given below. Complete this program by
  2. writing a method called drawBarCode that draws a barcode on the window at a given (x,y)
  3. coordinate. The coordinate (x,y) is the top-left corner of the barcode. The method also
  4. takes width and height of barcode as arguments, along with (x,y).
  5. A barcode is composed of many vertical lines; some of them are closer to each other,
  6. while some are further apart. Since the width of the barcode is w, there are a total of w
  7. vertical lines. For each line, you should draw it with black color with a 50% probability.
  8. Please note that since the barcode generation is done in a probabilistic environment, you
  9. will get different barcodes for the same method call over various executions.
  10. //start of barCodes.pde
  11. // add method drawBarCode here
  12. void setup() {
  13. size(400,400);
  14. background(255);
  15. drawBarCode(50,50,100,40);
  16. // add two more calls here
  17. }
  18. void draw() {
  19. }
  20. //end of barCodes.pde
  21.  
  22. Computing probabilities example -
  23.  
  24. int r = (int)random(1,5);
  25. //r is either 1 or 2 or 3 or 4.
  26. if ( r < 4 ) {
  27. ! ! //3 out of 4 values satisfy this, hence 75% probability
  28. }
  29.  
  30. if ( r == 1 ) {
  31. //1 out of 4 values satisfy this, hence 25% probability
  32. }
  33.  
  34. Test your method by drawing barcodes of various sizes. You should include two more
  35. method calls in addition to the one already given in setup(). To the right is an
  36. example of the results of using the method as follows:
  37.  
  38. drawBarCode(50,50,100,40);
  39. drawBarCode(50,150,200,40);
  40. drawBarCode(50,250,300,100);
Add Comment
Please, Sign In to add comment