Skip to main content
added 462 characters in body
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

Charcoal, 55 bytes

BNNJNNPψ↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1W¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online! Link is to verbose version of code. Edit: I don't know why but that code isn't working right now. Here's a tweaked version instead. Explanation of the original code:

BNN

Draw the outer box.

JNNPψ

Move the cursor to the entry point and make a hole in the box at this point, so this becomes the background.

↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1P

Rotate to the appropriate direction to print the initial line segment.

W¬℅KK«¹

While the cursor is over a hole, draw the next line segment.

F³¿∧κ℅KK«↷κ¶↷κ

Look for a hole in which to draw the next line segment. This works by repeating the same code three times. The first time, nothing happens. The second time, if the cursor is not over a hole, it rotates right 45°, then takes one step to the right, then rotates right 45°. This has the effect of reflecting it in one axis. The third time, if the cursor is still not over a hole, it rotates right 90°, then takes one step to the right, then rotates right 90°. This has the effect of changing the reflection to the other axis. If there still isn't a hole, then a corner or infinite loop has been reached, so the outer loop halts.

Charcoal, 55 bytes

BNNJNNPψ↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1W¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online! Link is to verbose version of code. Explanation:

BNN

Draw the outer box.

JNNPψ

Move the cursor to the entry point and make a hole in the box at this point, so this becomes the background.

↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1P

Rotate to the appropriate direction to print the initial line segment.

W¬℅KK«¹

While the cursor is over a hole, draw the next line segment.

F³¿∧κ℅KK«↷κ¶↷κ

Look for a hole in which to draw the next line segment. This works by repeating the same code three times. The first time, nothing happens. The second time, if the cursor is not over a hole, it rotates right 45°, then takes one step to the right, then rotates right 45°. This has the effect of reflecting it in one axis. The third time, if the cursor is still not over a hole, it rotates right 90°, then takes one step to the right, then rotates right 90°. This has the effect of changing the reflection to the other axis. If there still isn't a hole, then a corner or infinite loop has been reached, so the outer loop halts.

Charcoal, 55 bytes

BNNJNNPψ↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1W¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online! Link is to verbose version of code. Edit: I don't know why but that code isn't working right now. Here's a tweaked version instead. Explanation of the original code:

BNN

Draw the outer box.

JNNPψ

Move the cursor to the entry point and make a hole in the box at this point, so this becomes the background.

↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1P

Rotate to the appropriate direction to print the initial line segment.

W¬℅KK«¹

While the cursor is over a hole, draw the next line segment.

F³¿∧κ℅KK«↷κ¶↷κ

Look for a hole in which to draw the next line segment. This works by repeating the same code three times. The first time, nothing happens. The second time, if the cursor is not over a hole, it rotates right 45°, then takes one step to the right, then rotates right 45°. This has the effect of reflecting it in one axis. The third time, if the cursor is still not over a hole, it rotates right 90°, then takes one step to the right, then rotates right 90°. This has the effect of changing the reflection to the other axis. If there still isn't a hole, then a corner or infinite loop has been reached, so the outer loop halts.

added 1011 characters in body
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

Charcoal, 55 bytes

BNNJNN↷⎇⁼δBNNJNNPψ↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1PψW¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1W¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online!Try it online! Link is to verbose version of code. Explanation:

BNN

Draw the outer box.

JNNPψ

Move the cursor to the entry point and make a hole in the box at this point, so this becomes the background.

↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1P

Rotate to the appropriate direction to print the initial line segment.

W¬℅KK«¹

While the cursor is over a hole, draw the next line segment.

F³¿∧κ℅KK«↷κ¶↷κ

Look for a hole in which to draw the next line segment. This works by repeating the same code three times. The first time, nothing happens. The second time, if the cursor is not over a hole, it rotates right 45°, then takes one step to the right, then rotates right 45°. This has the effect of reflecting it in one axis. The third time, if the cursor is still not over a hole, it rotates right 90°, then takes one step to the right, then rotates right 90°. This has the effect of changing the reflection to the other axis. If there still isn't a hole, then a corner or infinite loop has been reached, so the outer loop halts.

Charcoal, 55 bytes

BNNJNN↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1PψW¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online! Link is to verbose version of code.

Charcoal, 55 bytes

BNNJNNPψ↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1W¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online! Link is to verbose version of code. Explanation:

BNN

Draw the outer box.

JNNPψ

Move the cursor to the entry point and make a hole in the box at this point, so this becomes the background.

↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1P

Rotate to the appropriate direction to print the initial line segment.

W¬℅KK«¹

While the cursor is over a hole, draw the next line segment.

F³¿∧κ℅KK«↷κ¶↷κ

Look for a hole in which to draw the next line segment. This works by repeating the same code three times. The first time, nothing happens. The second time, if the cursor is not over a hole, it rotates right 45°, then takes one step to the right, then rotates right 45°. This has the effect of reflecting it in one axis. The third time, if the cursor is still not over a hole, it rotates right 90°, then takes one step to the right, then rotates right 90°. This has the effect of changing the reflection to the other axis. If there still isn't a hole, then a corner or infinite loop has been reached, so the outer loop halts.

Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

Charcoal, 55 bytes

BNNJNN↷⎇⁼δ/⎇∧⁻⁻θ¹ζIε⁷I3⎇∧IζIε⁵I1PψW¬℅KK«¹F³¿∧κ℅KK«↷κ¶↷κ

Try it online! Link is to verbose version of code.