Laser

From Esolang
Jump to navigation Jump to search

Laser is a 2D programming language built by User:FizzyApple12 based on lasers, color, brightness and direction.

Commands

The laser is created (program start) with: ~ (laser always starts going right)
The laser is destroyed (program end) with: `

Laser instructions are categorized into 5 groups: up, down, left, right, and all.

All: instruction same from all directions (direction commands)
/ | Mirror
\ | Mirror
^ | changes laser's direction to up
V | changes laser's direction to down
< | changes laser's direction to left
> | changes laser's direction to right
& | sets laser's color or brightness to the value of the variable named the character to the right

Up: instruction is executed using this rule only if the laser is going up (string commands)
@ | changes laser's color to the character to the right
+ | pushes character to the right to the end of the laser's color
- | subtracts character from the end of the laser's color
$ | sets variable named the character to the right to the laser's color

Down: instruction is executed using this rule only if the laser is going down (number commands)
@ | changes laser's brightness to the number to the right
+ | adds brightness specified by the number to the right
- | subtracts brightness specified by the number to the right
* | multiplies brightness specified by the number to the right
% | divides brightness specified by the number to the right
$ | sets variable named the character to the right to the brightness

Left: instruction is executed using this rule only if the laser is going left (I/O commands)
@ | prints the color
$ | prints the brightness
= | sets the color to the next character in the keyboard buffer
: | prompts the user for keyboard input then sets the color to the text inputted

Right: instruction is executed using this rule only if the laser is going right (flow commands)
| | if brightness is greater than the number specified to the right, the laser will go up, if it is equal, the laser will go right, and if it is less, the laser will go down
- | if color is equal to the character on the right it will go up, otherwise laser will go down
{ | while the brightness is greater than the number specified the the right it will go right until it hits a ]
( | while the brightness is less than the number specified the the right it will go right until it hits a ]
[ | for the brightness values starting at the number on the bottom and ending at the number on the top incrementing by the number on the right until the laser hits a ]
] | when the laser hits this, it will loop back to the beginning of the loop unless the loop is completed, then the laser will go on like normal

Examples

Hello World

  / \/ \/ \`@\
  +l +  +r   +!
  +e +o +o   +d
  @H +l +W   +l
~ / \/ \/ \  /

Truth Machine

~ \`@\  
/:// /  
\  -0   
   @1   
   \ {0\
   /@/@/
   \]\] 

Cat Program

~  \
`@:/

Implementations

JavaScript

An interpreter built in node.js can be found here.