Type your ugBASIC program in the following box. Some BASIC rules:
  • keywords must be UPPERCASE, like PRINT
  • comments that are placed at the end of a line must be preceded by a colon:
    • this is good: PRINT "OK!": ' comment
    • this is wrong: PRINT "OK!" ' comment
Click on Build menu to select the target: you will download the compiled binary file!

' Enable BITMAP mode with a black background. BITMAP ENABLE(320,200) CLS BLACK ' Precalculate vectorial directions. DIM dx(4) AS POSITION = #{ 0, 1, 0, -1 } DIM dy(4) AS POSITION = #{ -1, 0, 1, 0 } ' Define the single ant structure. TYPE antType x AS POSITION y AS POSITION d AS SIGNED BYTE END TYPE ' Declare a single ant variable. DIM ant AS antType ' Put ant at the center of the screen. ant.x = SCREEN WIDTH / 2 ant.y = SCREEN HEIGHT / 2 ' Endless loop! DO ' Take the color in the current ant's position. c = POINT(ant.x, ant.y) ' If the current ant's cell color is black... IF c = BLACK THEN ' Rotate 90° clockwise. INC ant.d IF ant.d = 4 THEN ant.d = 0 ' Change the cell's color. PLOT ant.x, ant.y, WHITE ' ... else, if the color is white... ELSE ' Rotate 90° counter clockwise DEC ant.d IF ant.d = -1 THEN ant.d = 3 ' Change the cell's color. PLOT ant.x, ant.y, BLACK ENDIF ' Move the ant forward. ADD ant.x, dx(ant.d) ADD ant.y, dy(ant.d) ' Pac-man border style :-D IF ant.x < 0 THEN x = SCREEN WIDTH - 1 IF ant.x > SCREEN WIDTH - 1 THEN x = 0 IF ant.y < 0 THEN y = SCREEN HEIGHT - 1 IF ant.y > SCREEN HEIGHT - 1 THEN y = 0 LOOP
Learn to Write (Retro)Videogames! new

Welcome to the ugBASIC sandbox!

This tool was designed to quickly test whether the code you are writing compiles correctly and determines the desired results. Since the source is compiled thanks to dedicated servers, separate from the browser you are using, some commands are not available: for example, you cannot load external files or resources by using the LOAD command. If you need to develop a program with a complete tool, we recommend installing the executables or the UGBASIC-IDE.

Unless required by applicable law or agreed to in writing, this website is given on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.