// Allison Obourn
// CS& 141, Autumn 2021
// Lecture 5

// This program prints out two images of random black and white barcodes with
// a red line running diagonally through them from bottom left to upper right

import java.awt.*;
import java.util.*;

public class Barcode {
   public static final int PANEL_HEIGHT = 300;

   public static void main(String[] args) {
      DrawingPanel panel = new DrawingPanel(300, PANEL_HEIGHT);
      Graphics2D g = panel.getGraphics();
      Random r = new Random();
      drawBarcode(r, g, 50, 0, 10);
      drawBarcode(r, g, 80, 100, 5);
   }
   
   // takes a random generator, a graphics object, a upper left x, y coordinate and
   // a number of bars and draws a barcode with the passed in number different random width bars
   // at with its upper left corner at the specified x, y location
   public static void drawBarcode(Random r, Graphics2D g, int x, int y, int bars) {
      g.setColor(Color.BLACK);
      for(int i = 0; i < bars; i++) {
         int width = r.nextInt(5) + 3;
         g.fillRect(x + i * 10, y, width, 70); 
      }
      g.setColor(Color.RED);
      g.setStroke(new BasicStroke(3));
      g.drawLine(x, y + 70, x + bars * 9, y);
   }
}