# Make a Surfin' Word

Your goal is to map a piece of text to a sine curve of the form:

# a sin ( mx - b )

Where a and m are non-zero rational numbers, b is a rational number, and the calculations are in radians.

It doesn't really matter where the origin of your graph is, as long as you fit all the letters in your output. Also, it must be ASCII art, no graphical output.

You can take the equation input in as a string OR you can have a separate input for each parameter: a, m, and b.

Also

### Examples:

Input: "A-well-a", "3sin(x)" or (3,1,0)

Output:

 -w
a

A  e
-
l
l


Explanation:

The index of the character is the x-value, and each line represents one y-value. So we take 3sin(x) of the appropriate indices and round them to the nearest integer to get our values:

  'A' : 3sin(0) = 0 => (0,0)
'-' : 3sin(1) = 2.5244 => (1,3)
'w' : 3sin(2) = 2.7279 => (2,3)
etc. , to give you the rest of the word.


Input: "Everybody's", "3.5sin(x-2)" or (3.5,1,2)

Calculations:

3.5sin(x-2), x = 0,1,2,3,...,10 -3.1815,-2.9435,0,2.9435,3.1815,0.4935,-2.6495,-3.3565,-0.9765,2.2995,3.4615,

Output:

   ry     s
'

e  b
y

Ev    od


Input: "heard", "4sin(2x)" or (4,2,0)

4sin(2x) [0-4] = 0,3.636,-3.028,-1.116,3.956,

Output:

 e  d

h
r

a


-5sin(x+1) [0-4] : -4.205,-4.545,-0.705,3.785,4.795,

Output:

    t
u

o

a
b


Input: "the word", "-2.4sin(0.5x-1.2)" or (-2.4,0.5,1.2)

-2.4sin(0.5x-1.2) [0-7] : 2.2368,1.5456,0.4776,-0.7104,-1.7208,-2.3136,-2.3376,-1.7904

Output:

th

e

word


• What is the input format? Do we need to parse the expression as a string? – Zgarb Jan 13 '16 at 17:53
• @Zgarb Actually, if your language supports abstract mathematical functions, you can use that datatype for the expression. – geokavel Jan 13 '16 at 18:02
• so the input format is flexible? for instance, I could take the function input (in python) as "3*math.sin(x)"? – quintopia Jan 13 '16 at 18:19
• @quintopia No, only if your language natively supports mathematical expressions as a dataype (like MATLAB or Mathematica). – geokavel Jan 13 '16 at 18:23
• Otherwise, we have to take the input as a string exactly in the format you described? – quintopia Jan 13 '16 at 21:34

# Dyalog APL, 37 bytes

{⍉↑v⌽¨⍵↑¨⍨v←(-∘1-⌈/)⌊.5+⎕×1○⎕-⍨⎕×⍳≢⍵}


Takes text as right argument, and then prompts for m, b, and a.

## Python 2, 190159 171 bytes

import math
a,b,c,d=input()
q=len(a)
s=""
m=int(abs(b)+.5)
for i in range(2*m*q+q):s+=""if i%q else"\n";s+=a[i%q]if i/q==-int(round(b*math.sin(i%q*c-d)))+m else" "    print s


Example usage:

\$ python2 surfin2.py

t
u

o

a
b


This can probably be golfed further, but I can't see how at the moment. I just wanted to see this question get at least one answer. EDIT: Decently golfed once I saw how to do it in one pass. May have extra leading and trailing lines, but such was expressly allowed: "It doesn't really matter where the origin of your graph is, as long as you fit all the letters in your output."

• Yeah, I wanted one too! – geokavel Jan 14 '16 at 5:26
• I also wrote a version that parses the expression from a string in the format you describe, but it was longer. – quintopia Jan 14 '16 at 5:29
• You can include it if you want. – geokavel Jan 14 '16 at 5:29
• Nah, it wasn't particularly well-golfed. I stopped once I realized it would be considerably longer. – quintopia Jan 14 '16 at 5:45