Alexander Morou
Sponsor
This is just a frivolous topic about coding whilst bored. Sometimes it can create some very annoying results.
I was messing around in Visual Studio 2008 Standard, and decided to write some code for allowing a password to be entered. While doing so I decided that certain characters weren't valid input, like tab. So I wanted to present a beep with them. I didn't like the default beep and noticed that there were overloads, Console.Beep allows you to enter a frequency and duration. After a bit of screwing around I decided 'let's have some fun with this'.
That's probably one of the most useless bits of code I've ever written. Strange how easily amused I can be when I'm bored. The above code basically beeps with varying frequency for 7 millisecond bursts, and sleeps in-between them, causing a noise that's best described as undulating and annoying. If you're wondering the min = 0 + 37 is all about, the minimum frequency required by the Beep function is 37.
I was messing around in Visual Studio 2008 Standard, and decided to write some code for allowing a password to be entered. While doing so I decided that certain characters weren't valid input, like tab. So I wanted to present a beep with them. I didn't like the default beep and noticed that there were overloads, Console.Beep allows you to enter a frequency and duration. After a bit of screwing around I decided 'let's have some fun with this'.
Code:
[font=courier new][color=#0000FF]using[/color] [color=#008080]System[/color][color=#808080];[/color]
[color=#0000FF]using[/color] [color=#008080]System[/color][color=#808080].[/color][color=#008080]Collections[/color][color=#808080].[/color][color=#008080]Generic[/color][color=#808080];[/color]
[color=#0000FF]using[/color] [color=#008080]System[/color][color=#808080].[/color][color=#008080]Linq[/color][color=#808080];[/color]
[color=#0000FF]using[/color] [color=#008080]System[/color][color=#808080].[/color][color=#008080]Text[/color][color=#808080];[/color]
[color=#0000FF]using[/color] [color=#008080]System[/color][color=#808080].[/color][color=#008080]Threading[/color][color=#808080];[/color]
[color=#0000FF]namespace[/color] [color=#008080]QuarkyConsole[/color]
[color=#808080]{[/color]
[color=#0000FF]class[/color] [color=#008080]Program[/color]
[color=#808080]{[/color]
[color=#0000FF]static[/color] [color=#0000FF]void[/color] [color=#008080]Main[/color][color=#808080]([/color][color=#0000FF]string[/color][color=#808080][[/color][color=#808080]][/color] [color=#008080]args[/color][color=#808080])[/color]
[color=#808080]{[/color]
[color=#808040]DateTime[/color] [color=#008080]lastBeep[/color] [color=#808000]=[/color] [color=#808040]DateTime[/color][color=#808080].[/color][color=#008080]Now[/color][color=#808080];[/color]
[color=#0000FF]int[/color] [color=#008080]frequency[/color] [color=#808000]=[/color] [color=#FF0000]0[/color][color=#808080];[/color]
[color=#0000FF]double[/color] [color=#008080]angle[/color] [color=#808000]=[/color] [color=#FF0000]0[/color][color=#808080];[/color]
[color=#0000FF]int[/color] [color=#008080]last[/color] [color=#808000]=[/color] [color=#FF0000]7[/color][color=#808080];[/color]
[color=#0000FF]int[/color] [color=#008080]max[/color] [color=#808000]=[/color] [color=#FF0000]50[/color][color=#808080];[/color]
[color=#0000FF]int[/color] [color=#008080]min[/color] [color=#808000]=[/color] [color=#FF0000]0[/color] [color=#808000]+[/color] [color=#FF0000]37[/color][color=#808080];[/color]
[color=#0000FF]while[/color] [color=#808080]([/color][color=#0000FF]true[/color][color=#808080])[/color]
[color=#808080]{[/color]
[color=#808040]DateTime[/color] [color=#008080]currentBeep[/color] [color=#808000]=[/color] [color=#808040]DateTime[/color][color=#808080].[/color][color=#008080]Now[/color][color=#808080];[/color]
[color=#0000FF]if[/color] [color=#808080]([/color][color=#808080]([/color][color=#008080]currentBeep[/color] [color=#808000]-[/color] [color=#008080]lastBeep[/color][color=#808080])[/color][color=#808080].[/color][color=#008080]TotalMilliseconds[/color] [color=#808000]>=[/color] [color=#008080]last[/color][color=#808080])[/color]
[color=#808080]{[/color]
[color=#008080]angle[/color] [color=#808000]+[/color][color=#808000]=[/color] [color=#FF0000]1[/color][color=#808080].[/color][color=#FF0000]5[/color][color=#808080];[/color]
[color=#008080]frequency[/color] [color=#808000]=[/color] [color=#808080]([/color][color=#0000FF]int[/color][color=#808080])[/color][color=#808080]([/color][color=#008080]max[/color] [color=#808000]*[/color] [color=#800080]Math[/color][color=#808080].[/color][color=#008080]Sin[/color][color=#808080]([/color][color=#808080]([/color][color=#808080]([/color][color=#008080]angle[/color] [color=#808000]/[/color] [color=#FF0000]360[/color][color=#808080])[/color][color=#808080])[/color] [color=#808000]*[/color] [color=#808080]([/color][color=#FF0000]2[/color] [color=#808000]*[/color] [color=#800080]Math[/color][color=#808080].[/color][color=#008080]PI[/color][color=#808080])[/color][color=#808080])[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]frequency[/color] [color=#808000]>[/color] [color=#008080]max[/color][color=#808080])[/color]
[color=#008080]frequency[/color] [color=#808000]=[/color] [color=#008080]max[/color][color=#808080];[/color]
[color=#800080]Console[/color][color=#808080].[/color][color=#008080]Beep[/color][color=#808080]([/color][color=#800080]Math[/color][color=#808080].[/color][color=#008080]Abs[/color][color=#808080]([/color][color=#008080]frequency[/color][color=#808080])[/color] [color=#808000]+[/color] [color=#008080]min[/color][color=#808080],[/color] [color=#008080]last[/color] [color=#808000]+[/color] [color=#FF0000]2[/color][color=#808080])[/color][color=#808080];[/color]
[color=#008080]lastBeep[/color] [color=#808000]=[/color] [color=#008080]currentBeep[/color][color=#808080];[/color]
[color=#800080]Console[/color][color=#808080].[/color][color=#008080]Title[/color] [color=#808000]=[/color] [color=#008080]frequency[/color][color=#808080].[/color][color=#008080]ToString[/color][color=#808080]([/color][color=#808080])[/color][color=#808080];[/color]
[color=#800080]Thread[/color][color=#808080].[/color][color=#008080]Sleep[/color][color=#808080]([/color][color=#FF0000]1[/color][color=#808080])[/color][color=#808080];[/color]
[color=#808080]}[/color]
[color=#808080]}[/color]
[color=#808080]}[/color]
[color=#808080]}[/color]
[color=#808080]}[/color][/font]
That's probably one of the most useless bits of code I've ever written. Strange how easily amused I can be when I'm bored. The above code basically beeps with varying frequency for 7 millisecond bursts, and sleeps in-between them, causing a noise that's best described as undulating and annoying. If you're wondering the min = 0 + 37 is all about, the minimum frequency required by the Beep function is 37.