Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You are provided with an incomplete program given below. Complete this program by
- writing a method called drawBarCode that draws a barcode on the window at a given (x,y)
- coordinate. The coordinate (x,y) is the top-left corner of the barcode. The method also
- takes width and height of barcode as arguments, along with (x,y).
- A barcode is composed of many vertical lines; some of them are closer to each other,
- while some are further apart. Since the width of the barcode is w, there are a total of w
- vertical lines. For each line, you should draw it with black color with a 50% probability.
- Please note that since the barcode generation is done in a probabilistic environment, you
- will get different barcodes for the same method call over various executions.
- //start of barCodes.pde
- // add method drawBarCode here
- void setup() {
- size(400,400);
- background(255);
- drawBarCode(50,50,100,40);
- // add two more calls here
- }
- void draw() {
- }
- //end of barCodes.pde
- Computing probabilities example -
- int r = (int)random(1,5);
- //r is either 1 or 2 or 3 or 4.
- if ( r < 4 ) {
- ! ! //3 out of 4 values satisfy this, hence 75% probability
- }
- if ( r == 1 ) {
- //1 out of 4 values satisfy this, hence 25% probability
- }
- Test your method by drawing barcodes of various sizes. You should include two more
- method calls in addition to the one already given in setup(). To the right is an
- example of the results of using the method as follows:
- drawBarCode(50,50,100,40);
- drawBarCode(50,150,200,40);
- drawBarCode(50,250,300,100);
Add Comment
Please, Sign In to add comment