Jump to content

[APORTE] dxDrawElipse


Bc#

Recommended Posts

Hola, he querido compartir esta usefull function con motivo de mejorar el diseño de los scripts de la comunidad, para tener un toque mas moderno y darle versatilidad a nuestras interfaces.

 

dxDrawElipse(pX = 100, pY=100, a=0, b=0, n=2, color=white, fill=false, stroke=1 )

px = Posicion en el eje X
py = Posicion en el eje Y
a = Ancho
b = Alto
n = Borde
color = Color de la figura
fill = Relleno solido
stroke = tamaño de la linea en caso de que el relleno no sea solido

Quote

function dxDrawElipse(pX,pY,a,b,n,color,fill,stroke)
	--Validacion de paramertos
	local a = a or 100
	if a < 0 then a=0 end
	local b = b or 100
	if b < 0 then b=0 end
	local n = n or 2
	if n<=0 then n=0.1 end
	local color = color or tocolor(255,255,255,255)
  	local stroke = stroke or 1
  	if stroke<1 then stroke=1 end
	--Variables de uso local
	local angle
	local xStart, xEnd
	local fistHalf, secondHalf
	local presition = 0.01
	local na = 2/n
	local b2 = 2*b
	if fill then
		for y=0,b2 do
			--Calcula el angulo en funcion de y
			angle = math.asin(math.abs(math.pow(y/b,1/na)))
			if isnan(angle) then break end
			--Calcula el inicio y termino de una linea
			xStart=(math.pow(math.abs(math.cos(angle)),na)*a*1)+a+pX
			xEnd=(math.pow(math.abs(math.cos(angle)),na)*a*-1)+a+pX
			--Centra la elipse
			fistHalf=-y+b+pY
			secondHalf=y+b+pY
			--Dibuja la elipse
			if xStart~=NaN and fistHalf~=NaN and xEnd~=NaN and secondHalf~=NaN then
				dxDrawLine( xStart, fistHalf, xEnd, fistHalf, color)
				dxDrawLine( xStart, secondHalf+1, xEnd, secondHalf+1, color)
			end		
		end
	else
		local two_pi = math.pi*2
		local presition = 0.05
		local antX, antY
		for angle=0,two_pi+presition,presition do
			local x = math.pow(math.abs(math.cos(angle)),na)*a*sgn(math.cos(angle))+a+pX
			local y = math.pow(math.abs(math.sin(angle)),na)*b*sgn(math.sin(angle))+b+pY

			if angle > 0 then
				dxDrawLine( antX, antY, x, y, color,stroke)
			end
			antX = x
			antY = y
		end
	end
end

 

 

Ejemplos de uso

Quote

local sx,sy = guiGetScreenSize()

function generar()
	--Violeta
	dxDrawElipse(sx/2,sy/2,100,100,2,tocolor(55,0,55,200),true)
	dxDrawElipse(sx/2,sy/2,100,100,2,tocolor(255,255,255,200),false,2)

	--Verde
	dxDrawElipse(sx/4,sy/4,100,15,10,tocolor(0,155,55,200),true)
	dxDrawElipse(sx/4,sy/4,100,15,10,tocolor(200,200,200,100),false)

	--Rosa
	dxDrawElipse(sx/2,sy/8,100,100,10,tocolor(150,40,155,200),true)

	--Blanco
	dxDrawElipse(sx/4,sy/2,50,50,100,tocolor(255,255,255,255),false)

end
addEventHandler ( "onClientRender", root, generar )

Screenshoot:

https://imgur.com/a/97I2I

 

  • Like 1
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...