Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="ru">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Интерактивный Мультиплексор</title>
- <style>
- body {
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- margin: 0;
- padding: 20px;
- background-color: #f0f2f5;
- color: #333;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- h1 {
- color: #2c3e50;
- margin-bottom: 30px;
- }
- .container {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- gap: 40px;
- max-width: 1000px;
- }
- .multiplexer {
- background-color: #fff;
- border-radius: 10px;
- box-shadow: 0 4px 12px rgba(0,0,0,0.1);
- padding: 20px;
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 350px;
- }
- .controls {
- display: flex;
- flex-direction: column;
- gap: 15px;
- width: 100%;
- margin-bottom: 30px;
- }
- .control-group {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .control-label {
- font-weight: bold;
- font-size: 18px;
- }
- .switch {
- position: relative;
- display: inline-block;
- width: 60px;
- height: 34px;
- }
- .switch input {
- opacity: 0;
- width: 0;
- height: 0;
- }
- .slider {
- position: absolute;
- cursor: pointer;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: #ccc;
- transition: .4s;
- border-radius: 34px;
- }
- .slider:before {
- position: absolute;
- content: "";
- height: 26px;
- width: 26px;
- left: 4px;
- bottom: 4px;
- background-color: white;
- transition: .4s;
- border-radius: 50%;
- }
- input:checked + .slider {
- background-color: #2196F3;
- }
- input:checked + .slider:before {
- transform: translateX(26px);
- }
- .visualization {
- background-color: #2c3e50;
- border-radius: 10px;
- padding: 20px;
- color: white;
- width: 100%;
- position: relative;
- }
- .mux-diagram {
- position: relative;
- height: 320px;
- margin-top: 20px;
- }
- .mux-body {
- position: absolute;
- width: 120px;
- height: 200px;
- background-color: #3498db;
- border-radius: 10px;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- display: flex;
- justify-content: center;
- align-items: center;
- font-weight: bold;
- color: white;
- border: 2px solid #2980b9;
- }
- .input-line {
- position: absolute;
- height: 2px;
- background-color: #ccc;
- }
- .input-line.active {
- background-color: #2ecc71;
- box-shadow: 0 0 5px #2ecc71;
- }
- .input-label {
- position: absolute;
- left: 10px;
- font-weight: bold;
- }
- .output-line {
- position: absolute;
- width: 100px;
- height: 2px;
- background-color: #ccc;
- right: 10px;
- top: 50%;
- }
- .output-line.active {
- background-color: #e74c3c;
- box-shadow: 0 0 5px #e74c3c;
- }
- .output-value {
- position: absolute;
- right: 10px;
- top: 42%;
- font-weight: bold;
- }
- .control-line {
- position: absolute;
- height: 2px;
- background-color: #f39c12;
- box-shadow: 0 0 5px #f39c12;
- }
- .control-value {
- position: absolute;
- font-weight: bold;
- color: #f39c12;
- }
- .truth-table {
- margin-top: 30px;
- border-collapse: collapse;
- width: 100%;
- }
- .truth-table th, .truth-table td {
- border: 1px solid #ddd;
- padding: 8px;
- text-align: center;
- }
- .truth-table th {
- background-color: #34495e;
- color: white;
- }
- .truth-table tr.active {
- background-color: rgba(46, 204, 113, 0.2);
- font-weight: bold;
- }
- </style>
- </head>
- <body>
- <h1>Интерактивный Мультиплексор</h1>
- <div class="container">
- <div class="multiplexer">
- <div class="controls">
- <h2>Управление</h2>
- <div class="control-group">
- <span class="control-label">Управляющий вход X:</span>
- <label class="switch">
- <input type="checkbox" id="controlX">
- <span class="slider"></span>
- </label>
- <span id="xValue">0</span>
- </div>
- <div class="control-group">
- <span class="control-label">Управляющий вход Y:</span>
- <label class="switch">
- <input type="checkbox" id="controlY">
- <span class="slider"></span>
- </label>
- <span id="yValue">0</span>
- </div>
- <h3>Логические входы:</h3>
- <div class="control-group">
- <span class="control-label">Вход A:</span>
- <label class="switch">
- <input type="checkbox" id="inputA">
- <span class="slider"></span>
- </label>
- <span id="aValue">0</span>
- </div>
- <div class="control-group">
- <span class="control-label">Вход B:</span>
- <label class="switch">
- <input type="checkbox" id="inputB">
- <span class="slider"></span>
- </label>
- <span id="bValue">0</span>
- </div>
- <div class="control-group">
- <span class="control-label">Вход C:</span>
- <label class="switch">
- <input type="checkbox" id="inputC">
- <span class="slider"></span>
- </label>
- <span id="cValue">0</span>
- </div>
- <div class="control-group">
- <span class="control-label">Вход D:</span>
- <label class="switch">
- <input type="checkbox" id="inputD">
- <span class="slider"></span>
- </label>
- <span id="dValue">0</span>
- </div>
- </div>
- <div class="visualization">
- <h2>Визуализация</h2>
- <div class="mux-diagram">
- <div class="input-line a-line" style="width: 100px; left: 40px; top: 60px;"></div>
- <div class="input-label" style="top: 50px;">A</div>
- <div class="input-line b-line" style="width: 100px; left: 40px; top: 100px;"></div>
- <div class="input-label" style="top: 90px;">B</div>
- <div class="input-line c-line" style="width: 100px; left: 40px; top: 140px;"></div>
- <div class="input-label" style="top: 130px;">C</div>
- <div class="input-line d-line" style="width: 100px; left: 40px; top: 180px;"></div>
- <div class="input-label" style="top: 170px;">D</div>
- <div class="control-line x-line" style="width: 80px; left: 120px; top: 230px;"></div>
- <div class="control-value x-control-value" style="left: 50px; top: 220px;">X = 0</div>
- <div class="control-line y-line" style="width: 80px; left: 120px; top: 260px;"></div>
- <div class="control-value y-control-value" style="left: 50px; top: 250px;">Y = 0</div>
- <div class="mux-body">MUX</div>
- <div class="output-line"></div>
- <div class="output-value">Выход: A</div>
- </div>
- </div>
- </div>
- <div class="truth-table-container">
- <h2>Таблица истинности</h2>
- <table class="truth-table">
- <thead>
- <tr>
- <th>X</th>
- <th>Y</th>
- <th>Выбранный вход</th>
- <th>Выход</th>
- </tr>
- </thead>
- <tbody>
- <tr id="row00" class="active">
- <td>0</td>
- <td>0</td>
- <td>A</td>
- <td id="out00">0</td>
- </tr>
- <tr id="row10">
- <td>1</td>
- <td>0</td>
- <td>B</td>
- <td id="out10">0</td>
- </tr>
- <tr id="row01">
- <td>0</td>
- <td>1</td>
- <td>C</td>
- <td id="out01">0</td>
- </tr>
- <tr id="row11">
- <td>1</td>
- <td>1</td>
- <td>D</td>
- <td id="out11">0</td>
- </tr>
- </tbody>
- </table>
- <div style="margin-top: 30px;">
- <h3>Текущее состояние:</h3>
- <p id="currentState">X=0, Y=0 выбирает вход A. Значение на выходе: 0</p>
- </div>
- </div>
- </div>
- <script>
- // Получаем элементы управления
- const controlX = document.getElementById('controlX');
- const controlY = document.getElementById('controlY');
- const inputA = document.getElementById('inputA');
- const inputB = document.getElementById('inputB');
- const inputC = document.getElementById('inputC');
- const inputD = document.getElementById('inputD');
- // Получаем элементы для отображения значений
- const xValue = document.getElementById('xValue');
- const yValue = document.getElementById('yValue');
- const aValue = document.getElementById('aValue');
- const bValue = document.getElementById('bValue');
- const cValue = document.getElementById('cValue');
- const dValue = document.getElementById('dValue');
- // Получаем элементы визуализации
- const aLine = document.querySelector('.a-line');
- const bLine = document.querySelector('.b-line');
- const cLine = document.querySelector('.c-line');
- const dLine = document.querySelector('.d-line');
- const xLine = document.querySelector('.x-line');
- const yLine = document.querySelector('.y-line');
- const outputLine = document.querySelector('.output-line');
- const outputValue = document.querySelector('.output-value');
- const xControlValue = document.querySelector('.x-control-value');
- const yControlValue = document.querySelector('.y-control-value');
- // Получаем элементы таблицы
- const out00 = document.getElementById('out00');
- const out10 = document.getElementById('out10');
- const out01 = document.getElementById('out01');
- const out11 = document.getElementById('out11');
- const currentState = document.getElementById('currentState');
- const rows = {
- '00': document.getElementById('row00'),
- '10': document.getElementById('row10'),
- '01': document.getElementById('row01'),
- '11': document.getElementById('row11')
- };
- // Функция обновления состояния мультиплексора
- function updateMultiplexer() {
- // Получаем значения управляющих входов
- const x = controlX.checked ? 1 : 0;
- const y = controlY.checked ? 1 : 0;
- // Получаем значения логических входов
- const a = inputA.checked ? 1 : 0;
- const b = inputB.checked ? 1 : 0;
- const c = inputC.checked ? 1 : 0;
- const d = inputD.checked ? 1 : 0;
- // Обновляем отображение значений
- xValue.textContent = x;
- yValue.textContent = y;
- aValue.textContent = a;
- bValue.textContent = b;
- cValue.textContent = c;
- dValue.textContent = d;
- // Обновляем управляющие линии
- xControlValue.textContent = `X = ${x}`;
- yControlValue.textContent = `Y = ${y}`;
- // Обновляем активность входных линий
- aLine.classList.toggle('active', inputA.checked);
- bLine.classList.toggle('active', inputB.checked);
- cLine.classList.toggle('active', inputC.checked);
- dLine.classList.toggle('active', inputD.checked);
- // Определяем активный вход и выход
- let activeInput;
- let outputVal;
- if (x === 0 && y === 0) {
- activeInput = 'A';
- outputVal = a;
- } else if (x === 1 && y === 0) {
- activeInput = 'B';
- outputVal = b;
- } else if (x === 0 && y === 1) {
- activeInput = 'C';
- outputVal = c;
- } else {
- activeInput = 'D';
- outputVal = d;
- }
- // Обновляем выходную линию и значение
- outputLine.classList.toggle('active', outputVal === 1);
- outputValue.textContent = `Выход: ${outputVal}`;
- // Обновляем таблицу
- out00.textContent = a;
- out10.textContent = b;
- out01.textContent = c;
- out11.textContent = d;
- // Обновляем активную строку в таблице
- Object.keys(rows).forEach(key => {
- rows[key].classList.remove('active');
- });
- rows[`${x}${y}`].classList.add('active');
- // Обновляем текущее состояние
- currentState.textContent = `X=${x}, Y=${y} выбирает вход ${activeInput}. Значение на выходе: ${outputVal}`;
- }
- // Добавляем обработчики событий
- controlX.addEventListener('change', updateMultiplexer);
- controlY.addEventListener('change', updateMultiplexer);
- inputA.addEventListener('change', updateMultiplexer);
- inputB.addEventListener('change', updateMultiplexer);
- inputC.addEventListener('change', updateMultiplexer);
- inputD.addEventListener('change', updateMultiplexer);
- // Инициализируем состояние мультиплексора
- updateMultiplexer();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement