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 colorfull bitmap graphic (up to 16 colors) BITMAP ENABLE(16) ' Clear the screen CLS ' Enable trigonometric functions using radiants. RADIAN ' ugBASIC is an integer BASIC, so we need to ' specify that some variables are floating point, ' instead. Using the DIM instruction we can ' declare the type of each variable. ' This is the center of the screen. DIM cx AS FLOAT, cy AS FLOAT ' These variables store the coordinates ' of each point to draw, in a 3D reference system. DIM x AS FLOAT, y AS FLOAT, z AS FLOAT ' These variables store the coordinates ' of each point to draw, in a 2D reference system. DIM stx AS FLOAT, sty AS FLOAT ' Calculate the "center" of the flag using ' a proportional calculation with the original ' values on the ZX spectrum resolution. cx=(SCREEN WIDTH / 2.0) cy=(SCREEN HEIGHT / 12.0) ' Do nested loops. FOR ix=120 TO -19 STEP -4 FOR iy=100 TO 1 STEP -4 ' Calculate the 3D coordinates. x = ix y = iy z = 30 + ( (10*SIN(x/11.0)) * COS(y/52.0) ) ' Transform them in a 2D projection. stx = cx+x-y: sty = cy+x/2+y/2+z ' Draw the point on the screen. PLOT stx, sty PLOT stx, sty+1 ' Change the color on the flag based ' on the abscissa of the 2D point. ' (and avoid to draw the "star" if outside range). INK LIGHT RED IF x<(SCREEN WIDTH / 3.41) THEN INK LIGHT WHITE IF x<(SCREEN WIDTH / 16.0) THEN INK LIGHT GREEN IF x<(SCREEN WIDTH / 3.12) AND x>(SCREEN WIDTH / 3.76) THEN GOTO skip IF x<(SCREEN WIDTH / 10.66) AND x>(SCREEN WIDTH / 32.0) THEN GOTO skip ' Draw the star around the point. ' Fixed by Francesco Sblendorio here: ' https://www.facebook.com/groups/2057165187928233/posts/4023940781250654/?comment_id=4025561614421904 PLOT stx+1, sty+1 PLOT stx, sty+2 PLOT stx-1, sty+1 PLOT stx, sty skip: NEXT iy NEXT ix
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.