@Override
    public void paintComponent(Graphics graphics) {
        int xOrigin = (int) (xOffset - ((getCanvasWidth() * getScale()) / 2D));
        int yOrigin = (int) (yOffset - ((getCanvasHeight() * getScale()) / 2D));
        for (int x = 0; x < getCanvasWidth(); x += 8) {
            for (int y = 0; y < getCanvasHeight(); y += 8) {
                graphics.setColor(((x / 8) + ((y / 8) % 2 == 0 ? 1 : 0)) % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE);
                graphics.fillRect((int) (xOrigin + (x * getScale())), (int) (yOrigin + (y * getScale())), (int) (8 * getScale()), (int) (8 * getScale()));
            }
        }
        graphics.setColor(Color.BLACK);
        graphics.drawRect(xOrigin, yOrigin, (int) (canvasWidth * getScale()), (int) (canvasHeight * getScale()));

        Graphics2D graphics2D = (Graphics2D) graphics;
        graphics2D.translate(xOffset, yOffset);
        graphics2D.scale(scale, scale);

        frames.get(frame).render(graphics);

        if (workingPivot != null && mousePressed && getToolboxPanel().isConnectorSelected()) {
            graphics.setColor(Color.ORANGE);
            graphics.drawLine((int) workingPivot.getLocation().getX(), (int) workingPivot.getLocation().getY(), mouseX, mouseY);
        }

        if (mousePressed && getToolboxPanel().isLightSourceSelected()) {
            graphics.setColor(new Color(255, 255, 128));
            int dy = startY - mouseY;
            int dx = startX - mouseX;
            int radius = (int) Math.round(Math.sqrt(dy * dy + dx * dx));
            graphics.drawOval(startX - radius, startY - radius, radius * 2, radius * 2);
        }

        graphics2D.scale(1D / scale, 1D / scale);
        graphics2D.translate(-xOffset, -yOffset);
    }