Skip to content

mattbasta/graphicsbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graphics Bytecode

Version 0.1

GBC is a bytecode language intended for use by code golfers and hobbyists to create interesting and fun scripts that generate graphical output.

Literals

The only type of literal in GBC is a number. Strings do not exist. Boolean values are represented by 0 and 1. Numbers have no theoretical minimum or maximum value. All numbers may be floating point and exact comparisons should not be relied upon.

Numbers may internally be represented as negative, however no numeric literal is capable of being negative. Instead, the negation prefix operation is used to make numbers negative (n). :

123
.15
n4

Infinity is generated by dividing any positive number by zero. Negative infinity is generated by dividing any negative number by zero.

Whitespace

All whitespace is ignored, however, whitespace will cause continuations to be broken and the top prefix expression will stop accepting new tuple values. This means that tuples can be very easily divided up: :

a && b + c && d)
(&a,b)+(&c,d)
&a,b +&c,d

Continuations/Tuples

Each operation only accepts one parameter. However, tuples can be built out using the continuation construct (represented by a comma ,). The continuation construct is an infix operator. :

p123,456
C44,56,203

Blocks

Blocks begin with an operation and end with a closing parenthesis. Closing parenthesis always close the innermost block. :

L20a0,a0 *2)

Operations

Note that the symbol for each operator IS case-sensitive.

Block

Name Symbol Description

Loop

L..)

The bytecode within the block is executed N times where N is the number returned by the first expression within the block.

If

i..)

The bytecode within the block is only executed if the number returned by the first expression within the block is not zero.

Function

{..)

The bytecode within the block is executed when the ID provided by the number returned by the first expression within the block is called by the q operation. Arguments are the same as Lambdas.

Any

T..)

Each expression within the block is evaluated sequentially until one of the expressions is non-zero, at which point that expression is returned. If no expression evaluates to a non-zero value, 0 is returned. This operation will short circuit.

All

A..)

Each expression within the block is evaluated sequentially. If any expression equals 0, 0 is returned. If no expression evaluates to zero, 1 is returned. This operation will short circuit.

Sum

U..)

Sums and returns the return values of the evaluated expressions within the block.

No Params

Name Symbol Description
Clear Mat # Clear the transformations on the cursor's matrix.

Pop Mat

<

Pops the last transformation matrix from the top of the stack.

Dot d Draw a dot at the cursor.

Path

P

Draw a solid line from the last location that any drawing occurred at to the current cursor position.

Break ; Breaks out of the current loop block.

Prefix - Statements

These operations may only be contained within a block.

Name Symbol Description

RGB

C

Changes the active color to the RGB[A] color represented by the three or four-tuple parameter.

HSL

H

Changes the active color to the HSL[A] color represented by the three or four-tuple parameter.

Cursor

p

Places the cursor at the two-tuple coordinates specified by the parameter.

Translate

t

Translate the matrix used by the cursor by the (x, y) two-tuple specified by the parameter.

Rotate

r

Rotate the matrix used by the cursor by R degrees where R is the value specified by the parameter (in radians)

Scale

S

Scale the matrix used by the cursor by the (x_scale, y_scale) two-tuple specified by the parameter.

Prefix - Expressions

These operations may exist in any context, however, they have return a value and have no side effects*, making them useless within a block.

* The exception to this is Assign.

Name Symbol Description
Negate n The equivalent of param * -1
Not N param == 0
And & param[0] == 0 ? 0 : param[1]
Or | param[0] != 0 ? param[0] : param[1]
Iff I param[0] ? param[1] : param[2]
XOR X &(N&<param0>,<param1>),|(<param0>,<param1>)
Sine s sin(param)
Cosine o cos(param)
Tangent T tan(param)
Secant E sec(param)
Cosecant O csc(param)
Cotangent Y cot(param)
Floor _ floor(param)
Ceil ` ceil(param)
Square " Returns the square of the parameter

Inverter

!

A special operation. Any trigonemetric function within it is made to be the inverse. I.e.: !s2 == sin^-1(2)

Root

\

Square root. If a two-tuple is provided, the second value is used as the degree of the root.

Assign

a

If the parameter is a two-tuple, the second value is assigned to a global "variable" in the position denoted by the first value. If the parameter is a single value, the value at the position denoted by the parameter is returned. The default value at all positions is 0.

Call

q

Calls a function or lambda with the arguments passed in the parameter. The first element of the tuple in the parameter must be the number given to the function or lambda.

Infix

All infix operations behave the same as prefix expression operations with the sole exception that their operator is between first and second values that would otherwise be joined into a tuple. :

<PREFIX>1,2 == 1<INFIX>2
Name Symbol Description
Plus + x + y
Minus - x - y
Mult * x * y
Div / x / y
Pow ^ x ** y
Mod % x % y
Greater > x > y
Greater/Eq g x >= y
Equal = x == y
Not Equal x x != y

Operation Precedence -------------------

There are fewer precedence rules in GBC than in standard languages:

  1. Blocks will always be obeyed, no matter what.
  2. Block statements will never be placed into infix operations.
  3. Infix operations will never end a tuple (i.e.: a3+4,5 == (a(3+4,5)))
  4. Whitespace will always end the top expression or statement (and consequently break any open tuples)
  5. Whitespace will never end a block.
  6. All infix operators are computed in the order that they're encountered. Order of operations is not obeyed.

Comments

There are no comments in this language.

About

A microscript for creating graphics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published