How do I draw a circle?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Daxel
Posts: 996
Joined: Wed Mar 27, 2019 8:34 pm

Re: How do I draw a circle?

Post by Daxel »

ggoblin wrote: Sat Jun 25, 2022 3:19 am
BTW Apologies for all gif videos I'm posting recently.. just trying out a new freeby screen capture software. :D
Which one? :o Does it record regions, or did you crop it in a video editor?
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

The one I'm using right now is EaseUS Rec Experts.

https://www.easeus.com/screen-recorder/

The free version only allows 1min videos but does record regions. But its has about a dozen .exe files so took ages creating rules in my firewall to prevent them accessing the web.. who knows what they might record on my pc and send out.

Windows has a built in recorder - Game bar, accessed by pressing Win+G, but I cant figure out how to record regions with it.

https://www.lifewire.com/windows-10-game-bar-4150524

I also tried ScreenRec, the free one without registration gives a more generous 5 min record time, and it does regions in theory but because the free version is limited to SD quality it seems to get confused where the region is on my non-sd screen, even if the regions size its less than SD size. You can register for free and have longer videos - but its cloud based which I am not a fan of. [ EDIT: Its all free but the difference is between registered and non-registered ]

https://screenrec.com/screen-recorder/

BTW They all record mp4 which then I have to convert to gif. [ EDIT: EaseUS does record directly to GIF ]

If you find anything better please do let me know, thanks. :D
Daxel
Posts: 996
Joined: Wed Mar 27, 2019 8:34 pm

Re: How do I draw a circle?

Post by Daxel »

ggoblin wrote: Sat Jun 25, 2022 1:22 pm The one I'm using right now is EaseUS Rec Experts.
...
BTW They all record mp4 which then I have to convert to gif. [ EDIT: EaseUS does record directly to GIF ]

If you find anything better please do let me know, thanks. :D
I have found one! Since I didn't like the limitations you mentioned, I've been searching for something better and I found ScreenToGif, an open source free tool that you can download here: https://www.screentogif.com

You can download it as a portable version with just a single executable. It records regions, it has editing tools (some of them quite cool) and can export as GIF. It's also very intuitive so I'm loving it so far.
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

I also just found one. ShareX - again open source, no limits, converts to gif without all the dithering crap and uploads to imgBB or other sites..

https://getsharex.com/

I will check out screentogif, thank you
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

Daxel wrote: Sat Jun 25, 2022 1:54 pm
I have found one! Since I didn't like the limitations you mentioned, I've been searching for something better and I found ScreenToGif, an open source free tool that you can download here: https://www.screentogif.com

You can download it as a portable version with just a single executable. It records regions, it has editing tools (some of them quite cool) and can export as GIF. It's also very intuitive so I'm loving it so far.
Love the gif editor in that, very nice
Daxel
Posts: 996
Joined: Wed Mar 27, 2019 8:34 pm

Re: How do I draw a circle?

Post by Daxel »

ggoblin wrote: Sat Jun 25, 2022 2:22 pm I also just found one. ShareX - again open source, no limits, converts to gif without all the dithering crap and uploads to imgBB or other sites..

https://getsharex.com/

I will check out screentogif, thank you
Oh that one is also very good. The auto uploading to imgur is a nice feature I didn't know I wanted. Hmm now that I look for it, screentogif seems to have it too.
User avatar
LeviFiction
Posts: 18
Joined: Thu Jul 10, 2014 4:19 am

Re: How do I draw a circle?

Post by LeviFiction »

I personally just use OBS to record, and Moho to export a region to a GIF or do basic animation highlighting areas. I admit it's not the best, and a little slow at times, but the flexibility cannot be denied.
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

LeviFiction wrote: Sat Jun 25, 2022 7:53 pm I personally just use OBS to record, and Moho to export a region to a GIF or do basic animation highlighting areas. I admit it's not the best, and a little slow at times, but the flexibility cannot be denied.
I never learnt OBS, but yes its meant to be very powerful. I remember reading somewhere that it is possible to record regions in OBS?
User avatar
LeviFiction
Posts: 18
Joined: Thu Jul 10, 2014 4:19 am

Re: How do I draw a circle?

Post by LeviFiction »

I suppose that depends on the definition of "region". But yes. There are two main screen capture modes, full screen capture and Window specific screen capture. If you want to record an area of the screen and everything that pops into that area you can do a fullscreen capture, then scale the capture source to narrow in on a specific region. Which is mostly what I do for tutorials. I make my output 1280x720 then scale the fullscreen source to show only the top-left corner of the screen at exactly 720p resolution. And move programs in and out of that area to display. If I want to make a GIF I just record full screen, import the movie into Moho, and scale the movie layer to fit in the camera viewport on the region I wanted the focus.
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

ggoblin wrote: Sat Jun 25, 2022 3:19 am Well I can confirm that your magic numbers work :D

I didn't try 12 points, was more interested in seeing if I could draw a circle in Moho with just 2 point.. with your magic numbers it works!

Image

BTW When you really zoom in, in moho, you can see the difference between 0.3905 and 0.3914 4-point circles, but at that zoom level the lines look straight anyway.

BTW Apologies for all gif videos I'm posting recently.. just trying out a new freeby screen capture software. :D
Hi, I'm having problems trying to create the two point circle from lua using Hayasidist's magic number 0.66667 (creating it in Moho using UI isn't a problem). The magic number for curvature is not enough, I need to specify something related to the positions of the bezier handles?

I used the following code

Code: Select all

function GG_Test:DrawCircle(moho,shapename,mag,x,y)
	local mesh = moho:Mesh()
	local pointCount = mesh:CountPoints()
	
	mesh:SelectNone()
	local v = LM.Vector2:new_local()
	
	v.x = 0.1*mag + x
	v.y = 0.0*mag + y
	mesh:AddLonePoint(v, 0)

	v.x = 0.1*mag + x
	v.y = 0.0*mag	+ y
	mesh:AppendPoint(v, 0)

	v.x = -0.1*mag + x
	v.y = 0.0*mag + y
	mesh:AppendPoint(v, 0)
	
	mesh:WeldPoints(pointCount, mesh:CountPoints() - 1, 0)

	mesh:Point(pointCount+0):SetCurvature(0.66667,0)
	mesh:Point(pointCount+1):SetCurvature(0.66667,0)
	mesh:SelectConnected()
	
	local shapeid = moho:CreateShape(true,false,0)	
	local shape = mesh:Shape(shapeid)
	shape:SetName(shapename)
	return shape
end

The function could be called from Run() using something like:

Code: Select all

myshape = self:DrawCircle(moho, "circleShape",1, 0,0)

It generated this - as you can see the points are there and connected correctly with the correct magic numbers for curvature but its not enough as the bezier handles are not positioned right. Not sure how to position them in lua.

Image

I thought maybe I need to get the curve that passes through each point ,and then use SetControlHandle to position the bezier handles? But not sure what the parameters mean and what values I would need..

Code: Select all

	where = -1
	curve, where = mesh:Point(pointCount+0):Curve(0,where)
	curve:SetControlHandle(where, ???

Any insight would be great, thank you.

I was creating the 2 point circle to use in a particle layer, I assume it would be much more efficient that a standard 4 point circle .. half the points..?
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

Or am I overthinking it, and its my welding gone wrong again? :roll:
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

Ok, I've tried experimenting with the curve commands related to beziers:

Using SetControlHandle:

Code: Select all

	local where = -1
	local curve
	local vec2 = LM.Vector2:new_local()
	vec2.x = 0.1
	vec2.y = 0.1
	curve, where = mesh:Point(pointCount+0):Curve(0,where)
	curve:SetControlHandle(where, vec2, moho.frame, false)
	vec2.x = -0.1
	vec2.y = -0.1
	curve, where = mesh:Point(pointCount+1):Curve(0,where)
	curve:SetControlHandle(where, vec2, moho.frame, false)
produces:

Image

Using SetControlHandle + SetOffset:

Code: Select all

	local where = -1
	local curve
	local vec2 = LM.Vector2:new_local()
	vec2.x = 0.1
	vec2.y = 0.1
	curve, where = mesh:Point(pointCount+0):Curve(0,where)
	curve:SetControlHandle(where, vec2, moho.frame, false)
	curve:SetOffset(where, 0.1,0, false)
	vec2.x = -0.1
	vec2.y = -0.1
	curve, where = mesh:Point(pointCount+1):Curve(0,where)
	curve:SetControlHandle(where, vec2, moho.frame, false)
	curve:SetOffset(where, 0.1,0, false)
produces:

Image

Using SetControlHandle + SetWeight:

Code: Select all

	local where = -1
	local curve
	local vec2 = LM.Vector2:new_local()
	vec2.x = 0.1
	vec2.y = 0.1
	curve, where = mesh:Point(pointCount+0):Curve(0,where)
	curve:SetControlHandle(where, vec2, moho.frame, false)
	curve:SetWeight(where, 0.1,0, false)
	vec2.x = -0.1
	vec2.y = -0.1
	curve, where = mesh:Point(pointCount+1):Curve(0,where)
	curve:SetControlHandle(where, vec2, moho.frame, false)
	curve:SetWeight(where, 0.1,0, false)
produces:

Image

I've tried all the bezier set commands I could find. It seems all of them only act on one of the bezier handles at any point. To draw a 2-point circle I need to be able to set both handles:

Image

I don't know enough about beziers or the Moho API to proceed any further.

Thank you for your help.
User avatar
hayasidist
Posts: 3526
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How do I draw a circle?

Post by hayasidist »

maybe if you take a look at the code for my bezier curve tool you might get some ideas to help ... I've tried it with a two-point / two path shape interactively and it does the job.
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

Thanks Hayasidist, I will check it out :)
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: How do I draw a circle?

Post by ggoblin »

Do you know what

AimControlHandleAtNeighbor

and

CorrectControlHandleAngles

does, and how to use them?

Having checked both your wonderful script and Moho's own Curvature script, these are the two M_Curve commands I'm not using which might have something to do with why my code only seems to effect one of the two bezier handles. The documentation is very sparse, with just a mention of the parameter types with no description of what they do.

Essentially I think I need to connect the two bezier handles together again (in a line) to rid the peak at each point with a smooth curve to achieve my circle.

Thank you.
Post Reply