Honeycombs: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
(Add FutureBasic solution) |
||
Line 1,641: | Line 1,641: | ||
</pre> |
</pre> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
void local fn BuildWindow |
|||
long tag, index |
|||
CFStringRef title |
|||
CFMutableStringRef letters = fn MutableStringWithString( @"ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) |
|||
window 1, @"Honeycombs", (0,0,419,411), NSWindowStyleMaskTitled |
|||
CGrect r = {20,307,95,85} |
|||
for tag = 1 to 20 |
|||
subclass button tag,,, @"", r,, NSBezelStyleSmallSquare |
|||
index = rnd(len(letters)-1) |
|||
title = mid(letters,index,1) |
|||
ButtonSetTitle( tag, title ) |
|||
MutableStringDeleteCharacters( letters, fn RangeMake( index, 1 ) ) |
|||
ButtonSetBordered( tag, NO ) |
|||
ButtonSetTransparent( tag, YES ) |
|||
r = fn CGRectOffset( r, 0, -82 ) |
|||
if ( tag mod 4 == 0 ) |
|||
r.origin.x += 71 |
|||
if ( r.origin.y < -21.0 ) |
|||
r.origin.y = 307 |
|||
else |
|||
r.origin.y = 266 |
|||
end if |
|||
end if |
|||
next |
|||
end fn |
|||
void local fn ViewDrawRect( tag as long ) |
|||
CGRect r = fn ViewBounds( tag ) |
|||
ColorRef titleColor, fillColor |
|||
if ( fn ControlIsEnabled( tag ) ) |
|||
titleColor = fn ColorRed |
|||
fillColor = fn ColorYellow |
|||
else |
|||
titleColor = fn ColorBlack |
|||
fillColor = fn ColorMagenta |
|||
end if |
|||
BezierPathRef path = fn BezierPathInit |
|||
BezierPathSetLineWidth( path, 5.0 ) |
|||
BezierpathSetLineCapStyle( path, NSRoundLineCapStyle ) |
|||
CGPoint pt = {0,41} |
|||
BezierPathMoveToPoint( path, pt ) |
|||
pt.x += 23.67 : pt.y += 41 |
|||
BezierPathLineToPoint( path, pt ) |
|||
pt.x += 47.34 |
|||
BezierPathLineToPoint( path, pt ) |
|||
pt.x += 23.67 : pt.y -= 41 |
|||
BezierPathLineToPoint( path, pt ) |
|||
pt.x -= 23.67 : pt.y -= 41 |
|||
BezierPathLineToPoint( path, pt ) |
|||
pt.x -= 47.34 |
|||
BezierPathLineToPoint( path, pt ) |
|||
pt.x -= 23.67 : pt.y += 41 |
|||
BezierPathLineToPoint( path, pt ) |
|||
ColorSet( fillColor ) |
|||
BezierPathFill( path ) |
|||
ColorSet( fn ColorBlack ) |
|||
BezierPathStroke( path ) |
|||
CFStringRef title = fn ButtonTitle( tag ) |
|||
CFDictionaryRef attrs = @{ |
|||
NSFontAttributeName:fn FontWithName( @"Helvetica-Bold", 52), |
|||
NSForegroundColorAttributeName:titleColor} |
|||
CFMutableAttributedStringRef aString = fn MutableAttributedStringWithAttributes( title, attrs ) |
|||
MutableAttributedStringSetAlignment( aString, NSTextAlignmentCenter ) |
|||
r.origin.y += 10 |
|||
AttributedStringDrawInRect( aString, r ) |
|||
end fn |
|||
void local fn Finished |
|||
long tag |
|||
for tag = 1 to 20 |
|||
if ( fn ControlIsEnabled( tag ) ) then exit fn |
|||
next |
|||
end |
|||
end fn |
|||
void local fn ButtonAction( tag as long ) |
|||
ControlSetEnabled( tag, NO ) |
|||
fn Finished |
|||
end fn |
|||
void local fn DoDialog( ev as long, tag as long ) |
|||
select ( ev ) |
|||
case _btnClick : fn ButtonAction( tag ) |
|||
case _viewDrawRect : fn ViewDrawRect( tag ) |
|||
end select |
|||
end fn |
|||
random |
|||
fn BuildWindow |
|||
on Dialog fn DoDialog |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
[[file:FutureBasic Honeycombs.png]] |
|||
=={{header|Go}}== |
=={{header|Go}}== |