OTHER CONTRIBUTIONS: ITALIAN FLAG

This small program draws a waving Italian flag. The original program was written by Matthew Logue and posted in the "BASIC on the ZX Spectrum" group. He modified a program that generated bar graphs. The program has been adapted to run on many ugBASIC-supported computers.

Click here for more informations.

source compile sandbox issues? back to examples

SOURCE CODE ()

	' 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

How to compile and run the example

The instructions here refer to compiling the example from the command line. For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile each single example with just one click.



Are instructions for your specific home computer / console missing? First of all, check if your computer is supported by clicking here. If so, since ugBASIC is a language which does not provide abstractions, it is possible that this example will not work on your target. If you think this is an issue, please click here.

Amstrad CPC 464, Amstrad CPC 6128, Amstrad CPC 664

In order to compile the example, type this command on the command line:

Linux

ugbc.cpc -O dsk -o contrib_italian_flag.dsk contrib_italian_flag.bas

Windows

ugbc.cpc.exe -O dsk -o contrib_italian_flag.dsk contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

Coleco Vision, Dina (Chuang Zao Zhe 50), SpectraVideo SV-603 VGA

In order to compile the example, type this command on the command line:

Linux

ugbc.coleco -O rom -o contrib_italian_flag.rom contrib_italian_flag.bas

Windows

ugbc.coleco.exe -O rom -o contrib_italian_flag.rom contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

Olivetti Prodest PC128, Thomson MO6

In order to compile the example, type this command on the command line:

Linux

ugbc.pc128op -O k7 -o contrib_italian_flag.k7 contrib_italian_flag.bas

Windows

ugbc.pc128op.exe -O k7 -o contrib_italian_flag.k7 contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

SEGA SC-3000

In order to compile the example, type this command on the command line:

Linux

ugbc.sc3000 -O rom -o contrib_italian_flag.rom contrib_italian_flag.bas

Windows

ugbc.sc3000.exe -O rom -o contrib_italian_flag.rom contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

SEGA SG-1000

In order to compile the example, type this command on the command line:

Linux

ugbc.sg1000 -O rom -o contrib_italian_flag.rom contrib_italian_flag.bas

Windows

ugbc.sg1000.exe -O rom -o contrib_italian_flag.rom contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

TRS-80 Color Computer 3

In order to compile the example, type this command on the command line:

Linux

ugbc.coco3 -O bin -o contrib_italian_flag.bin contrib_italian_flag.bas

Windows

ugbc.coco3.exe -O bin -o contrib_italian_flag.bin contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

Thomson MO5

In order to compile the example, type this command on the command line:

Linux

ugbc.mo5 -O k7 -o contrib_italian_flag.k7 contrib_italian_flag.bas

Windows

ugbc.mo5.exe -O k7 -o contrib_italian_flag.k7 contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

Thomson TO8

In order to compile the example, type this command on the command line:

Linux

ugbc.to8 -O k7 -o contrib_italian_flag.k7 contrib_italian_flag.bas

Windows

ugbc.to8.exe -O k7 -o contrib_italian_flag.k7 contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

ZX Spectrum +2, ZX Spectrum 128K, ZX Spectrum 48K

In order to compile the example, type this command on the command line:

Linux

ugbc.zx -O tap -o contrib_italian_flag.tap contrib_italian_flag.bas

Windows

ugbc.zx.exe -O tap -o contrib_italian_flag.tap contrib_italian_flag.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

Any problem?

If you have found a problem trying to run this example, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO EXAMPLES