It's a "just for fun" challenge. Choose your favorite language for this one. Here it goes:
Part A: Display/print a vertical sin wave using * characters.
Part B: Display same sin wave horizontally using * characters.
Part A should get you going in the right direction (esp. if you've never played with the sin functions in your language), but Part B is a bit more tricky. No graphics libraries, cheater.
Post source in comments (must be logged in to comment).
Winner to receive 1 small shot of self satisfaction of completing trivial problem through useless challenge on obscure blog.

Comments
string input = Console.ReadLine();
if (input.Contains('A') || input.Contains('a'))
{
int amplitude = Console.WindowWidth / 2 - 1;
double frequency = 0.1;
for (double i=0; i < 100; i++)
{
Console.WriteLine(new string(' ', Convert.ToInt32(amplitude * Math.Sin(i * frequency) + amplitude)) + "*");
}
}
else if (input.Contains('B') || input.Contains('b'))
{
int amplitude = 10;
double frequency = 0.2;
int height = amplitude * 2;
for (int y = 1; y <= height + 1; y++)
{
int previousX = 0;
for (int x = 1; x < Console.WindowWidth; x++)
{
int spaces = Convert.ToInt32(amplitude * Math.Sin(x * frequency) + amplitude);
if (spaces == height - y + 1)
{
for (int i = 1; i < x - previousX; i++)
Console.Write(' ');
Console.Write("*");
previousX = x;
}
}
Console.WriteLine();
}
}
Console.WriteLine("Press Enter to close.");
Console.ReadLine();
public static void main(String[] args) {
int periods = 5;
int text_offset = 20;
int amplitude = 20;
int freq = 20;
double resolution = .01;
for(double x=0; x for(double z = text_offset+(amplitude*Math.sin(x*freq)); z>0; z--)
System.out.print(" ");
System.out.println("*");
}
}
Sign in or create an account to leave a comment.