Jump to content

[Help]DxDrawCircle


bebo1king

Recommended Posts

i edited the code to do it , i had just removed the clamp function from the function so it looks like this : 

function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI )
	if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then
		return false
	end
	
	
	radius = type( radius ) == "number" and radius or 50
	width = type( width ) == "number" and width or 5
	angleAmount = type( angleAmount ) == "number" and angleAmount or 1
	color = color or tocolor( 255, 255, 255, 200 )
	postGUI = type( postGUI ) == "boolean" and postGUI or false
	
	if ( stopAngle < startAngle ) then
		local tempAngle = stopAngle
		stopAngle = startAngle
		startAngle = tempAngle
	end
	
	for i = startAngle, stopAngle, angleAmount do
		local startX = math.cos( math.rad( i ) ) * ( radius + width )
		local startY = math.sin( math.rad( i ) ) * ( radius + width )
		local endX = math.cos( math.rad( i ) ) * ( radius - width )
		local endY = math.sin( math.rad( i ) ) * ( radius - width )
	
		dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI )
	end
	return true
end

 

Link to comment

You can't set it to minus 90 because there is no negative value for index loop, but if you want to make it draw in reverse mode (like you said draw from middle to right) here is may help. Im not testing it yet but maybe this could help.


-- [Sorry for Bad English]
-- I added "isReverse" argument (a boolean value), if the value is "true" then it will draw the circle to the right, default value is "false" (draw the circle to the left)

function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI, isReverse )
	if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then
		return false
	end
	
	
	radius = type( radius ) == "number" and radius or 50
	width = type( width ) == "number" and width or 5
	angleAmount = type( angleAmount ) == "number" and angleAmount or 1
	color = color or tocolor( 255, 255, 255, 200 )
	postGUI = type( postGUI ) == "boolean" and postGUI or false
	isReverse = type(isReverse) == "boolean" and isReverse or false
	
	if ( stopAngle < startAngle ) then
		local tempAngle = stopAngle
		stopAngle = startAngle
		startAngle = tempAngle
	end
	
	for i = startAngle, stopAngle, angleAmount do
		if isReverse then
      		-- If isReverse is true, then it will change the "i" value to negative
			i = -i 
		else
      		-- If isReverse is false(default), "i" will be positive
			i = i
		end
		local startX = math.cos( math.rad( i ) ) * ( radius + width )
		local startY = math.sin( math.rad( i ) ) * ( radius + width )
		local endX = math.cos( math.rad( i ) ) * ( radius - width )
		local endY = math.sin( math.rad( i ) ) * ( radius - width )
	
		dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI )
	end
	return true
end

-- This code below will draw the circle from mid to left (default)
function drawToLeft()
	dxDrawCircle(screenWidth/2, screenHeight/2, 110, 7, 1, 0, 90, tocolor( 255, 255, 255, 200 ), false, false)
end
addEventHandler("onClientRender", getRootElement(), drawToLeft)

-- This code below will draw the circle from mid to right (reverse)
function drawToRight()
	dxDrawCircle(screenWidth/2, screenHeight/2, 110, 7, 1, 0, 90, tocolor( 255, 255, 255, 200 ), false, true)
end
addEventHandler("onClientRender", getRootElement(), drawToRight)

 

Link to comment

EDIT: Already tried that code, doesnt work. I made this new one, work for me.

Spoiler

code


function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI, isReverse )
	if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then
		return false
	end
	
	
	radius = type( radius ) == "number" and radius or 50
	width = type( width ) == "number" and width or 5
	angleAmount = type( angleAmount ) == "number" and angleAmount or 1
	color = color or tocolor( 255, 255, 255, 200 )
	postGUI = type( postGUI ) == "boolean" and postGUI or false
	isReverse = type(isReverse) == "boolean" and isReverse or false
	
	if ( stopAngle < startAngle ) then
		local tempAngle = stopAngle
		stopAngle = startAngle
		startAngle = tempAngle
	end
	if isReverse then
		for i = stopAngle, startAngle, -angleAmount do
			local startY = math.cos( math.rad( i ) ) * ( radius + width )
			local startX = math.sin( math.rad( i ) ) * ( radius + width )
			local endY = math.cos( math.rad( i ) ) * ( radius - width )
			local endX = math.sin( math.rad( i ) ) * ( radius - width )
		
			dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI )
		end
	else
		for i = startAngle, stopAngle, angleAmount do
			
			local startX = math.cos( math.rad( i ) ) * ( radius + width )
			local startY = math.sin( math.rad( i ) ) * ( radius + width )
			local endX = math.cos( math.rad( i ) ) * ( radius - width )
			local endY = math.sin( math.rad( i ) ) * ( radius - width )
		
			dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI )
		end
	end
	return true
end

If you want to draw the circle with reverse mode, set the last argument to true

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...