Two lasers between two mirrors
JavaScript (ES6), 149 bytes
Takes input in currying syntax (w)(h)([a,b])
.
w=>h=>g=(p,d=[1,-1],s=Array(w).fill` `)=>h--?`|${p=p.map((x,i)=>~(k=d[i],s[x]='/X\\'[x-p[i^1]?k+1:1],x+=k)&&x<w?x:x+(d[i]=-k)),s.join``}|
`+g(p,d):''
Try it online!
Commented
w => h => // w = width, h = height
g = ( // g = recursive function taking:
p, // p[] = array holding the point coordinates
d = [1, -1], // d[] = directions
s = Array(w).fill` ` // s = array of w spaces (we can't use a string because it's
) => // immutable in JS)
h-- ? // if we haven't reached the last row yet:
`|${ // append the left pipe
p = p.map((x, i) => // for each x at position i in p[]:
~(k = d[i], // k = direction for this point
s[x] = '/X\\'[ // insert either '/', 'X' or '\' at position x in s
x - p[i ^ 1] ? // if p[0] != p[1]:
k + 1 // use the direction
: // else:
1 // force 'X'
], x += k // add k to x
) && // if the result is not equal to -1
x < w ? // and is less than w:
x // use the current value of x
: // else:
x + (d[i] = -k) // change the direction and restore the initial value of x
), // end of map()
s.join``}|\n` + // join and append s; append the right bar and a linefeed
g(p, d) // followed by the result of a recursive call
: // else:
'' // stop recursion
Stax, 40 bytes
àù@○⌡┼PY¼îαφu^·A☺°É⌠■╟¡Åt^◘v(µ╩Ñ♣t{╓○xß╦
Run and debug it
Try it online!
Pretty sure this can be further golfed.
Input is given in the form of width [right-going left-going] length
(per comment by @EngineerToast).
ASCII equivalent:
xHXdmzx);hi+x%Y92&;Hi-x%cy=41*47+&2ME:R\{|+m'||S
Python 2, 119 bytes
w,l,a,b=input()
exec"print'|%s|'%''.join(' \/X'[sum(i==k%(2*w)for k in[a,~b]+[~a,b]*2)]for i in range(w));a+=1;b-=1;"*l
Try it online!