X
GO
en-USen-GBfr-FRes-ESit-ITnn-NOsv-SE
AMOS Ball
Code
Boob Load "amigaball.png", 1
Boob Load "amos.png",2



' Lens paramenter
DIST0=512 : ZOM=256

' Radius and resolution of ball  
R=64



On Error Goto _EXIT
Degree 
NP=256
Dim X3D(NP),Y3D(NP),Z3D(NP)
SJ#=2*R : SJ#=SJ#/16
SI#=360 : SI#=SI#/16
K=0
For J#=-R To R Step SJ#
   For I#=1 To 360-SI Step SI#
      Inc K
      X3D(K)=Sqr(R*R-(J#*J#))*Cos(I#)
      Y3D(K)=Sqr(R*R-(J#*J#))*Sin(I#)
      Z3D(K)=J#
   Next I#
Next J#
_EXIT:
NP=K-1


 Curs Off : paper 0 : double buffer




RAD = 50

do
   
   Clw 

   
   ' Increment rotation angles

   TETA = TETA + 1 : if TETA > 359 then TETA = 0
   PHI = PHI + 2 : If PHI > 359 then PHI = 0
   
   ' Precalculation of COSs and SINs  
   ' ( *256 to stay in integer mode (faster!))    
   CPHI=Cos(PHI)*256
   SPHI=Sin(PHI)*256
   CTETA=Cos(TETA)*256
   STETA=Sin(TETA)*256
   
   ' Modify zoom
   DIST=DIST0+SPHI
   
   Boob Off
   
   For I=1 To NP
      
      ' Calculation of rotated 3D coords for each displayable
      ' point of the ball (Z>=0) 
      ' ( /256 to bring back COS and SIN beetween 0->1)    
      ' rotation (X-Z with PHI) & rotation (X-Y with TETA) 
      Z=(Z3D(I)*CPHI-Y3D(I)*SPHI)/256
      Y=(Z3D(I)*SPHI+Y3D(I)*CPHI)/256
      X=(X3D(I)*CTETA-Y*STETA)/256
      Y=(X3D(I)*STETA+Y*CTETA)/256
      
      ' Calculation of screen coords of A,B,C,D and draw lines     
      X=(X*ZOM)/(DIST+Z) 
      X = X + 160
      Y=(Y*ZOM)/(DIST+Z) 
      Y = Y + 100+sin(ANG)*RAD
      
      ' Display point
      Boob I,X,Y,1
      Boob Zoom I,0.025,0.025
    
   Next I
   ANG = ANG + 4

   Boob 0,160 + sin (ANG) * RAD,50,2
   Boob Zoom 0, 0.5, 0.5   
   Boob Set Hotspot 0, "center", "middle"
   
   Boob Draw
   Screen Swap 
   Wait Vbl 
   
Loop




 end




//
// Now come new instructions specially created to 
// display bobs in AMOS 2 until the real Bob and Sprites instructions 
// are implemented: boobs!
// With 'Instruction' and 'Function' keywords, new in AMOS 2,
// you can program your own instruction set in Basic! (I used Javascript
// here, but it can be in AMOS).
// The language is now expandable, in a much better and more open
// system than extensions.
// Who wants to do AMOS 3D instruction set? (no kidding! In Basic it will
// be fast and simple to program...)
//
// "Boob" set of instructions, like Bobs but more sexy!
//
Instruction "Boob Load", imageName$, number
	WAITING = 0

	// Goto Javascript
	{	
		if ( !this.amos.boobImages )
			this.amos.boobImages = [];

		var self = this;
		var path = 'resources/' + this.vars.imageName$;
		var image = new Image();
		image.onload = function()
		{
			self.amos.boobImages[ self.vars.number ] = image;
			self.vars.WAITING = 1;
		}
		image.src = path;
	}
	While( WAITING = 0 )
		Wait 1
	Wend
End Instruction

Instruction "Boob Off"
	// Goto Javascript
	{
		this.amos.boobs = []
	}
End Instruction

Instruction "Boob", number, x, y, image

	If number < 0 Then Error 23
	If image < 0 Then Error 23

	// Goto Javascript
	{	
		if ( !this.amos.boobs )
			this.amos.boobs = [];
		if ( !this.amos.boobImages )
			throw 'illegal_function_call';		
		var image = this.amos.boobImages[ this.vars.image ];
		if ( !image )
			throw 'illegal_function_call';
		var canvas = document.createElement( 'canvas' );
		canvas.width = image.width;
		canvas.height = image.height;
		this.amos.boobs[ this.vars.number ] =
		{
			image: this.vars.image,
			x: this.vars.x,
			y: this.vars.y,
			z: 0,
			hotSpotX: 0,
			hotSpotY: 0,
			zoomX: 1,
			zoomY: 1,
			canvas: canvas,
			context: canvas.getContext( '2d' )
		}
	}
End Instruction

Instruction "Boob Z", number, z
	
	If number < 0 Then Error 23

	// Goto Javascript
	{
		if ( !this.amos.boobs )
			throw 'illegal_function_call';
		var boob = this.amos.boobs[ this.vars.number ];
		if ( !boob )
			throw 'illegal_function_call';
		boob.z = this.vars.z;
	}
End Instruction

Instruction "Boob Sort"	
	// Goto Javascript
	{
		if ( !this.amos.boobs )
			throw 'illegal_function_call';
		this.amos.boobs = this.amos.boobs.sort( function( first, second )
		{
			return first.z < second.z;
		} );
	}
End Instruction

Instruction "Boob Zoom", number, zoomX, zoomY
	
	If number < 0 Then Error 23

	// Goto Javascript
	{
		if ( !this.amos.boobs )
			throw 'illegal_function_call';
		var boob = this.amos.boobs[ this.vars.number ];
		if ( !boob )
			throw 'illegal_function_call';
		boob.zoomX = typeof this.vars.zoomX == 'undefined' ? boob.zoomX : this.vars.zoomX;
		boob.zoomY = typeof this.vars.zoomY == 'undefined' ? boob.zoomY : this.vars.zoomY;
	}
End Instruction

Instruction "Boob Set Hotspot", number, xPosition$, yPosition$
	
	If number < 0 Then Error 23

	// Goto Javascript
	{
		if ( !this.amos.boobs )
			throw 'illegal_function_call';
		var boob = this.amos.boobs[ this.vars.number ];
		if ( !boob )
			throw 'illegal_function_call';
		var image = this.amos.boobImages[ boob.image ];
		if ( !image )
			throw 'illegal_function_call';
		switch ( this.vars.xPosition$ )
		{
			case 'left':
				boob.hotSpotX = 0;
				break;
			case 'center':
				boob.hotSpotX = image.width / 2;
				break;
			case 'left':
				boob.hotSpotX = image.width;
				break;
		}
		switch ( this.vars.yPosition$ )
		{
			case 'top':
				boob.hotSpotY = 0;
				break;
			case 'middle':
				boob.hotSpotY = image.height / 2;
				break;
			case 'bottom':
				boob.hotSpotY = image.height;
				break;
		}
	}
End Instruction

Instruction "Boob Draw"
	// Goto Javascript
	{
		if ( this.amos.boobs )
		{
			for ( var b = 0; b < this.amos.boobs.length; b++ )
			{
				var boob = this.amos.boobs[ b ];
				if ( boob )
				{
					var image = this.amos.boobImages[ boob.image ];
					if ( image )
						this.amos.currentScreen.context.drawImage( image, 0, 0, image.width, image.height, boob.x - boob.hotSpotX * boob.zoomX, boob.y - boob.hotSpotY * boob.zoomY, image.width * boob.zoomX, image.height * boob.zoomY );
				}
			}
			this.amos.currentScreen.setModified();
		}
	}
End Instruction

Instruction "Boob Save"
	// Goto Javascript
	{
		if ( this.amos.boobs && this.amos.boobImages )
		{
			for ( var b = 0; b < this.amos.boobs.length; b++ )
			{
				var boob = this.amos.boobs[ b ];
				var image = this.amos.boobImages[ boob.image ];
				if ( boob && image)
				{
					boob.canvas.width = image.width * boob.zoomX;
					boob.canvas.height = image.height * boob.zoomY;
					boob.context.drawImage( this.amos.currentScreen.canvas, boob.x - boob.hotSpotX * boob.zoomX, boob.y - boob.hotSpotY * boob.zoomY, image.width * boob.zoomX, image.height * boob.zoomY, 0, 0, boob.canvas.width, boob.canvas.height );
				}
			}
		}
	}
End Instruction

Instruction "Boob Clear"
	// Goto Javascript
	{
		if ( this.amos.boobs && this.amos.boobImages )
		{
			for ( var b = 0; b < this.amos.boobs.length; b++ )
			{
				var boob = this.amos.boobs[ b ];
				var image = this.amos.boobImages[ boob.image ];
				if ( boob && image )
				{
					this.amos.currentScreen.context.drawImage( boob.canvas, 0, 0, boob.canvas.width, boob.canvas.height, boob.x - boob.hotSpotX * boob.zoomX, boob.y - boob.hotSpotY * boob.zoomY, image.width * boob.zoomX, image.height * boob.zoomY );
				}
			}
		}
	}
End Instruction

//
// Some simple sound instructions, but the music
// will only play if the application is located on a real
// web server... (stupid DOM protection of browsers)
//
Instruction "Sound Load", name$
	// Goto Javascript
	{
		this.amos.audio = new Audio( 'resources/' + this.vars.name$ );
	}
End Instruction
Instruction "Sound Play"
	// Goto Javascript
	{
		if ( this.amos.audio )
			this.amos.audio.play();
	}
End Instruction
Instruction "Sound Position", position
	// Goto Javascript
	{
		if ( this.amos.audio )
			this.amos.audioCurrentTime = this.vars.position;
	}
End Instruction