Cistercian numerals: Difference between revisions

Content added Content deleted
(FutureBasic solution added)
Line 2,057: Line 2,057:


{{FormulaeEntry|page=https://formulae.org/?script=examples/Cistercian_numerals}}
{{FormulaeEntry|page=https://formulae.org/?script=examples/Cistercian_numerals}}

=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_numView
_numFld
end enum

_numHeight = 54
_lineLength = _numHeight/3


void local fn BuildWindow
window _window, @"Cistercian Numerals",, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
subclass view _numView, (237,153,76,94)
ViewSetFlipped( _numView, YES )
textfield _numFld,, @"0", (237,20,76,21)
ControlSetAlignment( _numFld, NSTextAlignmentCenter )
ControlSetFormat( _numFld, @"0123456789", YES, 4, 0 )
WindowMakeFirstResponder( _window, _numFld )
end fn


void local fn PathDraw1( path as BezierPathRef, x as CGFloat, y as CGFloat )
BezierPathMoveToPoint( path, fn CGPointMake( x, y ) )
BezierPathLineToPoint( path, fn CGPointMake( x + _lineLength, y ) )
end fn

void local fn PathDraw2( path as BezierPathRef, x as CGFloat, y as CGFloat )
BezierPathMoveToPoint( path, fn CGPointMake( x, y + _lineLength ) )
BezierPathLineToPoint( path, fn CGPointMake( x + _lineLength, y + _lineLength ) )
end fn

void local fn PathDraw3( path as BezierPathRef, x as CGFloat, y as CGFloat )
BezierPathMoveToPoint( path, fn CGPointMake( x, y ) )
BezierPathLineToPoint( path, fn CGPointMake( x + _lineLength, y + _lineLength ) )
end fn

void local fn PathDraw4( path as BezierPathRef, x as CGFloat, y as CGFloat )
BezierPathMoveToPoint( path, fn CGPointMake( x, y + _lineLength ) )
BezierPathLineToPoint( path, fn CGPointMake( x + _lineLength, y ) )
end fn

void local fn PathDraw5( path as BezierPathRef, x as CGFloat, y as CGFloat )
fn PathDraw4( path, x, y )
fn PathDraw1( path, x, y )
end fn

void local fn PathDraw6( path as BezierPathRef, x as CGFloat, y as CGFloat )
BezierPathMoveToPoint( path, fn CGPointMake( x + _lineLength, y ) )
BezierPathLineToPoint( path, fn CGPointMake( x + _lineLength, y + _lineLength ) )
end fn

void local fn PathDraw7( path as BezierPathRef, x as CGFloat, y as CGFloat )
fn PathDraw6( path, x, y )
fn PathDraw1( path, x, y )
end fn

void local fn PathDraw8( path as BezierPathRef, x as CGFloat, y as CGFloat )
fn PathDraw6( path, x, y )
fn PathDraw2( path, x, y )
end fn

void local fn PathDraw9( path as BezierPathRef, x as CGFloat, y as CGFloat )
fn PathDraw8( path, x, y )
fn PathDraw1( path, x, y )
end fn

void local fn PathDrawNum( path as BezierPathRef, num as long, x as CGFloat, y as CGFloat )
select ( num )
case 1 : fn PathDraw1( path, x, y )
case 2 : fn PathDraw2( path, x, y )
case 3 : fn PathDraw3( path, x, y )
case 4 : fn PathDraw4( path, x, y )
case 5 : fn PathDraw5( path, x, y )
case 6 : fn PathDraw6( path, x, y )
case 7 : fn PathDraw7( path, x, y )
case 8 : fn PathDraw8( path, x, y )
case 9 : fn PathDraw9( path, x, y )
end select
end fn


void local fn ViewDrawRect
CFStringRef numString = fn ViewProperty( _numView, @"num" )
if ( numString )
CGFloat x = 38, y = 20
long i
for i = 0 to 3
BezierPathRef path = fn BezierPathWithRect( fn ViewBounds(_numView) )
BezierPathMoveToPoint( path, fn CGPointMake(x,y) )
BezierPathLineToPoint( path, fn CGPointMake( x, y + _numHeight ) )
long num = intval( mid( numString, i, 1 ) )
if ( num )
fn PathDrawNum( path, num, x, y )
CGFloat xScale = 1.0, yScale = 1.0
select ( i )
case 0 : xScale = -1.0 : yScale = -1.0 // 1000
case 1 : yScale = -1.0 // 100
case 2 : xScale = -1.0 // 10
case else // 1-9
// do nothing
end select
if ( xScale < 0.0 || yScale < 0.0 )
CGRect bounds = fn BezierPathBounds( path )
AffineTransformRef tx = fn AffineTransformInit
AffineTransformScaleXY( tx, xScale, yScale )
if ( xScale < 0.0 ) then AffineTransformTranslate( tx, -bounds.origin.x-bounds.size.width, 0.0 )
if ( yScale < 0.0 ) then AffineTransformTranslate( tx, 0.0, -bounds.size.height )
BezierPathTransformUsingAffineTranform( path, tx )
end if
end if
BezierPathStroke( path )
next
end if
end fn


void local fn DrawAction
CFStringRef string = fn StringWithFormat( @"%.4ld", fn ControlIntegerValue( _numFld ) )
ViewSetProperty( _numView, @"num", string )
ViewSetNeedsDisplay( _numView )
end fn


void local fn DoAppEvent( ev as long )
select ( ev )
case _appDidFinishLaunching
fn BuildWindow
fn DrawAction
case _appShouldTerminateAfterLastWindowClosed : AppEventSetBool(YES)
end select
end fn


void local fn DoDialog( ev as long, tag as long, wnd as long )
select ( ev )
case _btnClick
select ( tag )
case _numFld : fn DrawAction
end select
case _viewDrawRect
select ( tag )
case _numView : fn ViewDrawRect
end select
end select
end fn


on appevent fn DoAppEvent
on dialog fn DoDialog

HandleEvents
</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==