모르스_부호_변환기
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| 모르스_부호_변환기 [2026/03/19 04:14] – akpil | 모르스_부호_변환기 [2026/09/05 09:28] (현재) – akpil | ||
|---|---|---|---|
| 줄 2: | 줄 2: | ||
| 자바스크립트, | 자바스크립트, | ||
| + | |||
| + | 수정된 버전입니다. (2026/ | ||
| + | |||
| + | 수정 사항은 각 스페이스 (출력되는 내용에서 '/' | ||
| + | |||
| + | < | ||
| + | # 2026.09.05 | ||
| + | # morse-letter to morse ver 0.7 | ||
| + | # written by 6K2LSV | ||
| + | # python3 에서 작동 | ||
| + | # pip3 install flask jamo | ||
| + | # port number 3040 | ||
| + | |||
| + | from flask import Flask, request, render_template_string | ||
| + | import json | ||
| + | from jamo import h2j, j2hcj | ||
| + | |||
| + | app = Flask(__name__) | ||
| + | |||
| + | # 모르스 부호 사전 | ||
| + | MORSE_DICT = { | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' ': '/' | ||
| + | } | ||
| + | |||
| + | HTML_TEMPLATE = """ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | body { font-family: | ||
| + | .container { width: 70%; margin: auto; padding: 30px; background: white; border-radius: | ||
| + | textarea { width: 95%; height: 80px; padding: 15px; font-size: 16px; border: 2px solid #ddd; border-radius: | ||
| + | button { background-color: | ||
| + | .display-area { margin-top: 25px; padding: 20px; background: #2d2d2d; border-radius: | ||
| + | .unit { display: inline-block; | ||
| + | .char { display: block; color: #fff; font-size: 14px; text-align: center; border-bottom: | ||
| + | .morse { display: block; color: #ffeb3b; font-family: | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <div class=" | ||
| + | < | ||
| + | <form method=" | ||
| + | < | ||
| + | <button type=" | ||
| + | </ | ||
| + | |||
| + | {% if pair_data %} | ||
| + | <div class=" | ||
| + | < | ||
| + | const pairData = {{ pair_data | tojson }}; | ||
| + | const displayArea = document.getElementById(' | ||
| + | const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); | ||
| + | |||
| + | function playBeep(symbol) { | ||
| + | if (symbol === ' ' || symbol === '/' | ||
| + | |||
| + | const oscillator = audioCtx.createOscillator(); | ||
| + | const gainNode = audioCtx.createGain(); | ||
| + | |||
| + | oscillator.connect(gainNode); | ||
| + | gainNode.connect(audioCtx.destination); | ||
| + | oscillator.type = ' | ||
| + | oscillator.frequency.setValueAtTime(600, | ||
| + | |||
| + | const duration = (symbol === ' | ||
| + | gainNode.gain.setValueAtTime(0.1, | ||
| + | |||
| + | oscillator.start(); | ||
| + | oscillator.stop(audioCtx.currentTime + duration); | ||
| + | |||
| + | return duration; // 재생된 시간 반환 | ||
| + | } | ||
| + | |||
| + | async function startDisplay() { | ||
| + | for (const item of pairData) { | ||
| + | // 한 글자 단위 박스 생성 | ||
| + | const unit = document.createElement(' | ||
| + | unit.className = ' | ||
| + | unit.innerHTML = `<span class=" | ||
| + | displayArea.appendChild(unit); | ||
| + | |||
| + | const morseSpan = document.getElementById(`m-${item.id}`); | ||
| + | |||
| + | // 해당 문자의 모르스 부호를 한 기호씩 출력 | ||
| + | for (const symbol of item.morse) { | ||
| + | morseSpan.innerText += symbol; | ||
| + | |||
| + | if (symbol === '/' | ||
| + | // 스페이스 기호가 나오면 0.3초(300ms) 동안 대기 | ||
| + | await new Promise(resolve => setTimeout(resolve, | ||
| + | } else { | ||
| + | playBeep(symbol); | ||
| + | // 일반 기호는 음길이 이후 다음 기호와의 간격을 위해 기존 150ms 대기 | ||
| + | await new Promise(resolve => setTimeout(resolve, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | window.onload = startDisplay; | ||
| + | </ | ||
| + | {% endif %} | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | """ | ||
| + | |||
| + | @app.route('/', | ||
| + | def index(): | ||
| + | input_text = "" | ||
| + | pair_data = [] | ||
| + | if request.method == ' | ||
| + | input_text = request.form.get(' | ||
| + | # 자모 분리 및 대문자화 | ||
| + | processed_chars = list(j2hcj(h2j(input_text.upper()))) | ||
| + | |||
| + | for i, char in enumerate(processed_chars): | ||
| + | pair_data.append({ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | |||
| + | return render_template_string(HTML_TEMPLATE, | ||
| + | |||
| + | if __name__ == ' | ||
| + | app.run(host=' | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | 원래 소스 코드는 아래에 .. | ||
| < | < | ||
| 줄 14: | 줄 166: | ||
| ' | ' | ||
| ' | ' | ||
| - | ' | + | ' |
| - | 'ㅄ' : '---.--.-', 'ㅀ' : '.-..--..', ' | + | |
| - | 'ㅉ' : ' | + | 'ㄲ': '.-...-..', |
| + | 'ㅃ' : '..--..', ' | ||
| + | |||
| + | | ||
| ' | ' | ||
| ' | ' | ||
모르스_부호_변환기.1773893691.txt.gz · 마지막으로 수정됨: 저자 akpil
