Instrux

**Instrux** and its pixel-displaying successor **InstruxPixel** (and later **InstruxPixel+**) were the first Epsilonian programming languages. The first version of Instrux was developed in 1840 by Rutherford Texas, inventor of the Ti Graphing Phones, to simplify the production of his previously analog electronics. InstruxPixel+ was also used to make Scientist Jump in 1865. Instrux was succeeded by Voxelite.

## History

The concept of a "machine" language dates back to shortly after the 18th century invention of computers. (TBC)

## Syntax

*The following discusses the 1845 Instrux Pixel.*

Instrux is an event-driven, language, meaning each block of code runs simultaneously and executes when a specified event occurs. Events include screen tapping, button/key pressing, sensor output, and more. It is also flat-nested, so code within loops and conditions must be intended.

### Printing

The **display** keyword prints the following text at the specified location. If unspecified, displayed at the center. You can also center the text with **centered display**.

```
display "Hello, world!"
display "I'm up here!" @ (0, 100) // (x, y)

```

### Variables

The syntax for declaring variables is **var** name **==** value. To increment or decrement a variable, use the **++** and **--** operators, respectively, instead.

```
var num == 68
num ++ 1
display num // prints 69

```

### Conditionals

Conditionals execute the following intended code if the given condition is **True**. Conditions are written like regular equations and with keywords such as **not**, **or**, **and**, & **in**.

```
if 1 + 1 = 2: // Will return True
 display "This equation is correct."

var myList == ["apple", "banana"]

if not "banana" in myList: // Will return False
 display "\*sad banana noises\*"

```

### Loops and Events

A **While** loop executes the following code repeatedly whenever the given condition is **True**. For instance, in the following program, pressing the space bar turns random pixels black.

```
while space.pressed():
 pixel.random() == "black"
 wait 0.5 secs // Prevents all the pixels from becoming black too quickly

```
A **When** loop is just a **While** loop except once executed, it waits for its condition to become **False** and then **True** again before re-executing. The following program increments and then displays the **num** variable when the screen is tapped.

```
var num == 0
display num

when screenTapped():
 num ++ 1
 clearDisplay() // Clears previous displayed number
 display num

```

#### Other Stuff

* A **Once** loop re-executes the following code once the given condition becomes **True**.
* An **Until** is a Once loop except it stops being checked after executing once.
* A **forever** loop executes the code until the program stops.
* The **break** function stops executing the code block it is in.
* The **exit** function permanently stops the current loop or event from being checked.

### Custom Events

Furthermore, you can declare custom events using variables.

```
var jumping == space.pressed()
when jumping:
 display "Jumped!"

```

### Built-in Functions

* key.pressed(): Returns True if the given key is being pressed.
* screenTapped(): Returns True if something is touching the screen.
* tapLocation(): Returns the x and y coordinates of the last tapped/pressed pixel in a list (ex. [82, -147])
* retrieveChar(): Returns the last pressed key.
* expression.quantify(): Returns the result of the expression.
* string[index]: Returns the index'th character in the string.
* number[index]: Returns the index'th digit in the number.
* list[index]: Returns the item at the given index in the list.
* list.add(value): Adds the value to the list.
* list.insert(value, index): Adds the value to the list at the given index.
* list.remove(value): Removes the first instance of the value in the list.
* list.remove(#index): Removes the item at the given index in the list.
* list.random(): Returns a random item of the list.
* string.random(): Returns a random character in the string.
* number.random(): Returns a random digit in the number.
* end(): Terminates the program.
* clearDisplay(): Clears the screen of all printed text.
* clearPixels(): Resets the color of all pixels to white.
* randomLoc(): Displays a random (x, y) position on the screen. Equivalent to
* resizeScreen(height, width): Resizes the screen to be height by width pixels long. The height and width must retain the same aspect ratio and be powers of two less than the screen's regular pixel size.

### Other neat features

* The **maybe** Boolean has a 50/50 chance to return **True** or **False**.
* The built-in **it** variable returns the value of the last used variable.

## Example programs

### Truth machine

```
when zero.pressed():
 display 0
 end()

 display 1

```

### Calculator

```
// Declares a variable to store the expression
var expression == ""

// When a key is pressed, the program finds which key it is.
when anykey.pressed():
 var char == retrieveChar()

 // If the key is a digit or operator, it will be displayed on the screen and added to the text variable.
 if char in "1234567890+-/\*^":
 display it
 expression ++ it

// When enter is pressed, the result of the typed expression will be printed.
when enterbutton.pressed():
 display expression.quantify()

```