ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[normal]],
		Motions = 
		{
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\butterfly\butterfly.anim]],
						Name = [[butterfly]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[normal]],
			},
			motion2 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\butterfly\butterfly.anim]],
						Name = [[butterfly]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[toolbar]],
			},
		},
	},
	Extensions = 
	{
		FlippableExtension = 
		{
		},
		PhysicsExtension = 
		{
		},
		PositionExtension = 
		{
		},
		LevelEditorExtension = 
		{
			blocks_items = false,
			flippable = true,
			locked = true,
		},
	},
}

-- Begin Scripting --

help_text_header = "$00603"
help_text = "$00604"

function OnInit()
	
	time_to_apply = 0
	
	--remember where i was
	original_height = this:GetPosition().y
	original_width = this:GetPosition().x
	
	this:EnableCollisions(false)
	this:EnablePhysics(false)
	
	index_on_sine = 0
	index_increment = math.pi/(60+60*World_GetDeterministicDouble())
		
	if World_GetDeterministicDouble() > 0.5 then
		index_on_sine_x = math.pi
	else
		index_on_sine_x = 0
	end
	
	index_increment_x = math.pi/(80+60*World_GetDeterministicDouble())
	
	MAX_HEIGHT = 20+(10*World_GetDeterministicDouble())
	MAX_WIDTH = 30+(10*World_GetDeterministicDouble())
	
end

--require "util.lua"


function Update()

	Profile_Start("butterfly")

	local pos = this:GetPosition()

	height = math.sin( index_on_sine )*MAX_HEIGHT
	index_on_sine = index_on_sine + index_increment
	
	if index_on_sine >= math.pi*2 then
		index_on_sine = index_on_sine - math.pi*2
	end

	width = math.sin( index_on_sine_x )*MAX_WIDTH
	index_on_sine_x = index_on_sine_x + index_increment_x
	
	if index_on_sine_x >= math.pi*2 then
		index_on_sine_x = index_on_sine_x - math.pi*2
	end
	
	this:SetPosition( Vector2( original_width + width, original_height + height ) )
		
	this:SetFlipped( index_on_sine_x > math.pi/2 and index_on_sine_x < 3*math.pi/2 ) 
	
	Profile_Stop("butterfly")
		
end

