Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
57
Task/Morse-code/Wren/morse-code-1.wren
Normal file
57
Task/Morse-code/Wren/morse-code-1.wren
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import "/str" for Str
|
||||
import "/sound" for Wav
|
||||
|
||||
var charToMorse = {
|
||||
"!": "---.", "\"": ".-..-.", "$": "...-..-", "'": ".----.",
|
||||
"(": "-.--.", ")": "-.--.-", "+": ".-.-.", ",": "--..--",
|
||||
"-": "-....-", ".": ".-.-.-", "/": "-..-.",
|
||||
"0": "-----", "1": ".----", "2": "..---", "3": "...--",
|
||||
"4": "....-", "5": ".....", "6": "-....", "7": "--...",
|
||||
"8": "---..", "9": "----.",
|
||||
":": "---...", ";": "-.-.-.", "=": "-...-", "?": "..--..",
|
||||
"@": ".--.-.",
|
||||
"A": ".-", "B": "-...", "C": "-.-.", "D": "-..",
|
||||
"E": ".", "F": "..-.", "G": "--.", "H": "....",
|
||||
"I": "..", "J": ".---", "K": "-.-", "L": ".-..",
|
||||
"M": "--", "N": "-.", "O": "---", "P": ".--.",
|
||||
"Q": "--.-", "R": ".-.", "S": "...", "T": "-",
|
||||
"U": "..-", "V": "...-", "W": ".--", "X": "-..-",
|
||||
"Y": "-.--", "Z": "--..",
|
||||
"[": "-.--.", "]": "-.--.-", "_": "..--.-"
|
||||
}
|
||||
|
||||
var textToMorse = Fn.new { |text|
|
||||
text = Str.upper(text)
|
||||
var morse = ""
|
||||
for (c in text) {
|
||||
if (c == " ") {
|
||||
morse = morse + (" " * 7)
|
||||
} else {
|
||||
var m = charToMorse[c]
|
||||
if (m) morse = morse + m.join(" ") + " "
|
||||
}
|
||||
}
|
||||
return morse.trimEnd()
|
||||
}
|
||||
|
||||
var morse = textToMorse.call("Hello world!")
|
||||
System.print(morse) // print to terminal
|
||||
|
||||
// now create a .wav file
|
||||
morse = morse.replace("-", "...") // replace 'dash' with 3 'dot's
|
||||
var data = []
|
||||
var sampleRate = 44100
|
||||
var samples = 0.2 * sampleRate // number of samples assuming 'dot' takes 200 ms.
|
||||
var freq = 500 // say
|
||||
var omega = 2 * Num.pi * freq
|
||||
for (c in morse) {
|
||||
if (c == ".") {
|
||||
for (s in 0...samples) {
|
||||
var value = (32 * (omega * s / sampleRate).sin).round & 255
|
||||
data.add(value)
|
||||
}
|
||||
} else {
|
||||
for (s in 0...samples) data.add(0)
|
||||
}
|
||||
}
|
||||
Wav.create("morse_code.wav", data, sampleRate)
|
||||
16
Task/Morse-code/Wren/morse-code-2.wren
Normal file
16
Task/Morse-code/Wren/morse-code-2.wren
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import "audio" for AudioEngine
|
||||
|
||||
class Main {
|
||||
construct new() {}
|
||||
|
||||
init() {
|
||||
AudioEngine.load("morse", "morse_code.wav")
|
||||
AudioEngine.play("morse")
|
||||
}
|
||||
|
||||
update() {}
|
||||
|
||||
draw(alpha) {}
|
||||
}
|
||||
|
||||
var Game = Main.new()
|
||||
Loading…
Add table
Add a link
Reference in a new issue