About Monkey 2 › Forums › Monkey 2 Development › canvas.Scale() Bug or bad practice?
This topic contains 2 replies, has 3 voices, and was last updated by 
 Mark Sibly
 2 years, 5 months ago.
		Viewing 3 posts - 1 through 3 (of 3 total)
	
	- 
		AuthorPosts
 - 
		
			
				
November 19, 2016 at 10:15 am #5240
I’ve encoutered an artifact with canvas.scale
May be we’re not supposed to zoom in but the circle is nice when zoomed so I assume it’s a bugWith the following code you can see that th radius of the circle is not correctly placed when zoomed but is ok when growing the circle.
[/crayon]Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647[crayon-5cba8d89b1bf1987216971 inline="true" ]Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField zoom:=1.0Field radius:=4.2Field x:=9.3Field y:=9.2Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText("Press space to zoom, Enter to grow circle, R to reset",10,10)canvas.Scale(zoom,zoom)canvas.DrawCircle( x,y,radius )canvas.Color=Color.Blackcanvas.DrawLine(x,y,x+Cos(0.7)*radius,y+Sin(0.7)*radius)If Keyboard.KeyDown(Key.Space) Then zoom=zoom*1.1If Keyboard.KeyDown(Key.Enter) Then radius=radius*1.1If Keyboard.KeyDown(Key.R)zoom=1.0radius=1.2EndifPrint zoomEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndNovember 19, 2016 at 2:14 pm #5243Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField zoom:=.01Field radius:=400.2Field x:=9.3Field y:=9.2Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText("Press space to zoom, Enter to grow circle, R to reset",10,10)canvas.Scale(zoom,zoom)canvas.DrawCircle( x,y,radius )canvas.Color=Color.Blackcanvas.DrawLine(x,y,x+Cos(0.7)*radius,y+Sin(0.7)*radius)If Keyboard.KeyDown(Key.Space) Then zoom=zoom*1.1If Keyboard.KeyDown(Key.Enter) Then radius=radius*1.1If Keyboard.KeyDown(Key.R)zoom=.01radius=400.2EndifPrint zoomEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()Endhows that
there might be a rounding error involved ?
November 19, 2016 at 7:48 pm #5253Nice bug! Potential fix pushed to develop branch.
 - 
		AuthorPosts
 
		Viewing 3 posts - 1 through 3 (of 3 total)
	
	You must be logged in to reply to this topic.