Find if a point is within a triangle: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 877:
........................................
</pre>
 
 
 
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_textLabel
end enum
 
void local fn BuildWindow
'~'1
window _window, @"Find if a point is within a triangle", (0, 0, 340, 360 )
WindowCenter(_window)
WindowSubclassContentView(_window)
ViewSetFlipped( _windowContentViewTag, YES )
ViewSetNeedsDisplay( _windowContentViewTag )
 
subclass textLabel _textLabel, @"", ( 20, 320, 300, 20 ), _window
end fn
 
void local fn DrawInView( tag as NSInteger )
'~'1
BezierPathRef path = fn BezierPathInit
BezierPathMoveToPoint( path, fn CGPointMake( 30, 300 ) )
BezierPathLineToPoint( path, fn CGPointMake( 300, 300 ) )
BezierPathLineToPoint( path, fn CGPointMake( 150, 30 ) )
BezierPathClose( path )
BezierPathStrokeFill( path, 3.0, fn ColorBlack, fn ColorGreen )
AppSetProperty( @"path", path )
end fn
 
void local fn DoMouse( tag as NSInteger )
'~'1
CGPoint pt = fn EventLocationInView( tag )
if ( fn BezierPathContainsPoint( fn AppProperty( @"path" ), pt ) )
ControlSetStringValue( _textLabel, fn StringWithFormat( @"Inside triangle: x = %.f y = %.f", pt.x, pt.y ) )
else
ControlSetStringValue( _textLabel, fn StringWithFormat( @"Outside triangle: x = %.f y = %.f", pt.x, pt.y ) )
end if
end fn
 
void local fn DoDialog( ev as long, tag as long )
'~'1
select ( ev )
case _viewDrawRect : fn DrawInView(tag)
case _viewMouseDown : fn DoMouse( tag )
case _viewMouseMoved : fn DoMouse( tag )
end select
end fn
 
fn BuildWindow
 
on dialog fn DoDialog
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:FB Find Point in a Triangle.png]]
 
 
 
=={{header|Go}}==
715

edits