Honeycombs: Difference between revisions

3,134 bytes added ,  1 month ago
m
→‎{{header|FutureBasic}}: Display chosen letters and set window background colour
m (→‎{{header|FutureBasic}}: Display chosen letters and set window background colour)
 
(5 intermediate revisions by 2 users not shown)
Line 1,641:
 
</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,443), NSWindowStyleMaskTitled
WindowSetBackgroundColor( 1, fn ColorWhite )
CGrect r = {20,339,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 )
ButtonSetKeyEquivalent( tag, lcase(title) )
MutableStringDeleteCharacters( letters, fn RangeMake( index, 1 ) )
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 = 339
else
r.origin.y = 298
end if
end if
next
textlabel 21,, (18,20,383,24)
ControlSetFont( 21, fn FontSystemFontOfSize(20) )
ControlSetAlignment( 21, NSTextAlignmentCenter )
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 )
CFStringRef string = fn StringByAppendingString( fn ControlStringValue(21), fn ButtonTitle(tag) )
ControlSetStringValue( 21, string )
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}}==
Line 4,144 ⟶ 4,264:
 
The following script uses a font called ''memory.ttf''. If this is not present in your DOME distribution, it can be downloaded from [https://github.com/domeengine/dome/raw/main/examples/fonts/memory.ttf here] and should be placed in the same directory as the script itself.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window, Process
import "math" for Math
416

edits