Honeycombs: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(C++ - added link to screenshot) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(13 intermediate revisions by 8 users not shown) | |||
Line 14:
Honeycomb class:
<syntaxhighlight lang="actionscript3">
package {
Line 229:
}
</syntaxhighlight>
Document (main) class:
<syntaxhighlight lang="actionscript3">
package {
Line 399:
}
</syntaxhighlight>
=={{header|Ada}}==
{{libheader|SDLAda}}
<
with Ada.Numerics.Discrete_Random;
Line 607:
Window.Finalize;
SDL.Finalise;
end Honeycombs;</
=={{header|AutoHotkey}}==
Requires [https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517&start=320 Gdip Library]
<syntaxhighlight lang="autohotkey">Columns := 5 ; cater for a different number of columns
hexPerCol := 4 ; cater for a different number of hexagons
size := 40
w := sqrt(3) * size
h := 2 * size
Coord := [], Chosen := [], Seq:= ""
Letters := StrSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
x := A_ScreenWidth/2 - w*(Columns/2) + w/2
y := A_ScreenHeight/2 - h*(hexPerCol/2) + h/2
x1:= x, y1:=y
Gdip()
; Draw High Columns
loop % Ceil(Columns/2)
{
col := A_Index
loop % hexPerCol
{
Random, rnd, 1, % Letters.count()
letter := Letters.RemoveAt(rnd)
Draw_Hexagon(x,y,size,Letter)
y += sqrt(3) * size
}
x:=x1, y:=y1
x+= col*3*size
}
; Draw Low Columns
x:= x1, y:=y1
x+= size*1.5, y += sqrt(3) * size/2
loop % Floor(Columns/2)
{
col := A_Index
loop % hexPerCol
{
Random, rnd, 1, % Letters.count()
letter := Letters.RemoveAt(rnd)
Draw_Hexagon(x,y,size,Letter)
y += sqrt(3) * size
}
x:=x1, y:=y1
x+= size*1.5, y += sqrt(3) * size/2
x+= col*3*size
}
OnExit, Exit
Return
;---------------------------------------------------------------
~LButton::
CoordMode, Mouse, Screen
MouseGetPos, mx, my, mc, mw
if (mc <> hwnd1)
return
minD := []
for L, c in coord
{
x := c.x
y := c.y
D := Sqrt((x-mx)**2 + (y-my)**2)
minD[D] := L
min := A_Index = 1 ? D : min < D ? min : D
}
thisLetter := minD[min]
gosub SelectHex
return;
;---------------------------------------------------------------
KeyPress:
thisLetter := A_ThisHotkey
gosub, SelectHex
return
;---------------------------------------------------------------
SelectHex:
if Chosen[thisLetter]
return
Chosen[thisLetter] := true ; record of chosen letters
Seq .= thisLetter ; record of the chosen letters in order chosed
pBrush := Gdip_BrushCreateSolid(0xFFFF00FF)
x := coord[thisLetter, "x"]
y := coord[thisLetter, "y"]
Draw_Hexagon(x,y,size,thisLetter, "FF000000")
Progress, % "m2 b fs16 zh0 y0 w400 x" A_ScreenWidth/2-200, % Seq,,, Courier New
if (Chosen.Count() = Columns * hexPerCol)
ExitApp
return
;---------------------------------------------------------------
Draw_Hexagon(x,y,size,Letter,TextColor:="FFFF0000"){
global
deg2rad := 3.141592653589793/180
a := x + Size "," y
b := x+ Size*Cos(60*deg2rad) "," y + Size*Sin(60*deg2rad)
c := x+ Size*Cos(120*deg2rad) "," y + Size*Sin(120*deg2rad)
d := x - Size "," y
e := x+ Size*Cos(240*deg2rad) "," y + Size*Sin(240*deg2rad)
f := x+ Size*Cos(300*deg2rad) "," y + Size*Sin(300*deg2rad)
Gdip_FillPolygon(G, pBrush, a "|" b "|" c "|" d "|" e "|" f)
Gdip_DrawLines(G, pPen, a "|" b "|" c "|" d "|" e "|" f "|" a)
Font := "Arial", Gdip_FontFamilyCreate(Font)
Options := "x" x-size/2 " y" y-size/2 "c" TextColor " Bold s" size
Gdip_TextToGraphics(G, Letter, Options, Font)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
Hotkey, % letter, KeyPress
Coord[letter, "x"] := x
Coord[letter, "y"] := y
}
;---------------------------------------------------------------
gdip(){
global
Gdip_Startup()
Width := A_ScreenWidth, Height := A_ScreenHeight
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pBrush := Gdip_BrushCreateSolid(0xFFFFFF00)
pPen := Gdip_CreatePen(0xFF000000, 3)
}
;---------------------------------------------------------------
Exit:
Gdip_DeleteBrush(pBrush)
Gdip_DeletePen(pPen)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return
;---------------------------------------------------------------</syntaxhighlight>
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
VDU 23,22,252;252;8,16,16,128
*FONT Arial,24,B
Line 694 ⟶ 827:
SYS "TextOut", @memhdc%, x%-size.dx%/2, y%-size.dy%/2, text$, LEN(text$)
SYS "CreatePolygonRgn", ^pt%(0,0), 6, ALTERNATE TO hrgn%
= hrgn%</
[[File:honeycombs_bbc.gif]]
=={{header|C}}==
<syntaxhighlight lang="c">
/* Program for gtk3 */
Line 969 ⟶ 1,102:
return EXIT_SUCCESS;
}
</syntaxhighlight>
=={{header|C sharp}}==
<
using System.Collections.Generic;
using System.Linq;
Line 1,169 ⟶ 1,302:
}
}
}</
XAML:
<
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Line 1,183 ⟶ 1,316:
<Canvas x:Name="HoneycombCanvas" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Window></
[[File:CSharpHoneycomb.jpg]]
=={{header|C++}}==
{{libheader|Qt}}
<
// honeycombwidget.h
//
Line 1,217 ⟶ 1,352:
};
#endif // HONEYCOMBWIDGET_H</
<
// honeycombwidget.cpp
//
Line 1,318 ⟶ 1,453:
update(cell->polygon.boundingRect());
}
}</
<
// main.cpp
//
Line 1,330 ⟶ 1,465:
w.show();
return a.exec();
}</
{{out}}
[[Media:Honeycombs_qt.png]]
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
[[File:DelphiHoneycomb.png|frame|none]]
You can click on any hexagon in the honeycomb and it will be highlighted purple.
<syntaxhighlight lang="Delphi">
{Structure containing information for one hexagon}
type THexagon = record
Points: array [0..6-1] of TPoint;
Center: TPoint;
Letter: Char;
Selected: boolean;
end;
{Array of hexagons}
var Hexagons: array of array of THexagon;
function PointInPolygon(Point: TPoint; const Polygon: array of TPoint): Boolean;
{Test if point is in the polygon}
var Rgn: HRGN;
begin
Rgn := CreatePolygonRgn(Polygon[0], Length(Polygon), WINDING);
Result := PtInRegion(rgn, Point.X, Point.Y);
DeleteObject(rgn);
end;
function HitTest(X,Y: integer; var Col,Row: integer): boolean;
{Find hexagon that X,Y may be in}
{Return a hexagon found, Hexagon is in specified by Col, Row}
var C,R: integer;
begin
Result:=True;
for R:=0 to High(Hexagons[0]) do
for C:=0 to High(Hexagons) do
if PointInPolygon(Point(X,Y),Hexagons[C,R].Points) then
begin
Col:=C; Row:=R;
exit;
end;
Result:=False;
end;
procedure BuildHoneyComb(Pos: TPoint; Radius: integer);
{Build honeycombo from hexagons}
var XStep,YStep: integer;
var Off: TPoint;
var Col,Row: integer;
var Cnt: integer;
procedure SetHexagon(var Hex: THexagon; Pos: TPoint);
{Set the points for one hexagon}
begin
Hex.Center:=Pos;
Hex.Points[0]:=Point(Pos.X-Radius,Pos.Y);
Hex.Points[1]:=Point(Pos.X-XStep,Pos.Y-YStep);
Hex.Points[2]:=Point(Pos.X+XStep,Pos.Y-YStep);
Hex.Points[3]:=Point(Pos.X+Radius,Pos.Y);
Hex.Points[4]:=Point(Pos.X+XStep,Pos.Y+YStep);
Hex.Points[5]:=Point(Pos.X-XStep,Pos.Y+YStep);
{Assign one char to hexagon, A..Z in order created}
Hex.Letter:=Char(Cnt+$41);
{Deselect hexagon}
Hex.Selected:=False;
Inc(Cnt);
end;
procedure RandomizeChars;
{Randomize the characters}
var X1,Y1,X2,Y2: integer;
var C: char;
begin
for X1:=0 to High(Hexagons) do
for Y1:=0 to High(Hexagons[0]) do
begin
X2:=Random(Length(Hexagons));
Y2:=Random(Length(Hexagons[0]));
C:=Hexagons[X1,Y1].Letter;
Hexagons[X1,Y1].Letter:=Hexagons[X2,Y2].Letter;
Hexagons[X2,Y2].Letter:=C;
end;
end;
begin
Cnt:=0;
{Set number of hexagons in honey comb}
SetLength(Hexagons,5,4);
{Values to set the corners of the hexagon}
XStep:=Round(Radius / 2);
YStep:=Round(Radius * 0.866025403784438646);
for Col:=0 to High(Hexagons) do
for Row:=0 to High(Hexagons[0]) do
begin
{Calculate the position of hexagon in honeycomb}
Off.X:=Pos.X+(Radius+XStep) * Col;
Off.Y:=Pos.Y+YStep*Row*2;
if (Col and 1)=1 then Off.Y:=Off.Y + YStep;
{Set hexagon in honeycomb}
SetHexagon(Hexagons[Col,Row],Off);
end;
RandomizeChars;
end;
procedure DrawHoneyComb(Canvas: TCanvas);
{Draw polygons describing honeycomb}
var Col,Row: integer;
var Hex: THexagon;
var FS: TSize;
begin
Canvas.Pen.Width:=4;
Canvas.Font.Size:=20;
Canvas.Font.Style:=[fsBold];
Canvas.Font.Name:='Arial';
FS:=Canvas.TextExtent('M');
for Col:=0 to High(Hexagons) do
for Row:=0 to High(Hexagons[0]) do
begin
Hex:=Hexagons[Col,Row];
if Hex.Selected then Canvas.Brush.Color:=clFuchsia
else Canvas.Brush.Color:=clYellow;
Canvas.Polygon(Hex.Points);
Canvas.TextOut(Hex.Center.X-FS.CX div 2,Hex.Center.Y-FS.CY div 2,Hex.Letter);
end;
end;
procedure ShowHoneycomb(Image: TImage);
var MW: TMouseWaiter;
var MI: TMouseData;
var Row,Col: integer;
begin
MW:=TMouseWaiter.Create(TWinControl(Image));
Image.Canvas.Pen.Width:=3;
BuildHoneyComb(Point(140,90),40);
DrawHoneyComb(Image.Canvas);
Image.Canvas.Brush.Color:=clWhite;
Image.Canvas.TextOut(10,10,'Click outside honeycomb to terminate');
Image.Invalidate;
while true do
begin
MI:=MW.WaitForMouse;
if HitTest(MI.X,MI.Y,Col,Row) then
begin
Hexagons[Col,Row].Selected:=True;
DrawHoneyComb(Image.Canvas);
Image.Invalidate;
end
else break;
if Application.Terminated then break;
end;
end;
</syntaxhighlight>
{{out}}
<pre>
</pre>
=={{header|Go}}==
{{libheader|raylib-go}}
<
import (
Line 1,460 ⟶ 1,767:
rl.CloseWindow()
}</
=={{header|Haskell}}==
{{libheader|gloss}}
{{libheader|random-shuffle}}
<
import Data.Function (on)
import Data.List (zipWith4)
Line 1,605 ⟶ 1,912:
(return . drawWorld)
handleInput
(\_ x -> return x)</
=={{header|Icon}} and {{header|Unicon}}==
Line 1,616 ⟶ 1,923:
Label selection is straight forward. Mouse selection first determines if x,y is within the widgets rectangular outer bounds. The x,y point is then reflected into the north west quadrant of the cell and the helper data is used to calculate an abbreviated cross-product (x and y will always be 0). The direction of the resultant z indicates if the point is inside or outside of the widgets inner bounds.
<
procedure main(A)
Line 1,723 ⟶ 2,030:
return W
}
end</
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf.icn provides formatting]
=={{header|J}}==
<syntaxhighlight lang="j">require'ide/qt/gl2'
coinsert'jgl2'
NB. corners of a unit hexagon
ucorn=: +.^j.2p1*(%~i.)6
NB. center to center offset for columns and rows
uof=: %:2.3 3
shape=: 4 5
scale=: 50
scorn=: scale*ucorn
centers=: scale*(((%:0 0.75)*/~2|{:"1)+uof*"1 1:+|."1)shape#:i.shape
honeycomb=: {{)n
pc honeycomb nosize closeok;
minwh 460 460;
cc hex isidraw flush;
pshow;
}}{{
sel=: 0"0 grid=: shape$u:65+(*/shape)?26
txt=:''
wd m
draw y
}}
draw=: {{
glfill 0 0 0 255
hex"0 i.$grid
gltextcolor glrgb 0 0 255
glfont 'courier 24'
gltextxy 60 10
glpaint gltext txt
}}
hex=: {{
coord=. <shape#:y
center=. coord{centers
glbrush glrgb (-coord{sel)|.255 255 0
glrgb 255 255 255
glpen 3,PS_SOLID
glpolygon,<.center+"1 scorn
gltextcolor glrgb 255 0 0
glfont 'courier 24 bold'
gltextxy <.center-10
gltext coord{grid
}}
select_character=: {{
if. -. y{,sel do. NB. the selected character has been determined
txt=:txt, y{,grid
end.
draw sel=: 1 (y"_)} sel
}}
honeycomb_hex_char=: {{
ch=. toupper {.sysdata
if. ch e. ,grid do. select_character (,grid)i.ch end.
}}
honeycomb_hex_mbldown=:{{
xy=. 2{.".sysdata
k=. (i.<./)dist=.,+/&.:*:"1 centers-"1 xy
if. scale > k{dist do.select_character k end.
}}
honeycomb''</syntaxhighlight>
=={{header|Java}}==
<
import java.awt.event.*;
import javax.swing.*;
Line 1,859 ⟶ 2,236:
g.drawString(s, x, y);
}
}</
=={{header|Julia}}==
Uses Cairo and Gtk for graphics. Tasks done include the optional one of recording and then displaying letters as chosen with mouse or keyboard on exit once all letters are chosen.
<
mutable struct Hexagon
Line 1,972 ⟶ 2,349:
exit()
</syntaxhighlight>
=={{header|Kotlin}}==
This is a translation of the Java entry except that code has been added to end the program automatically when all the hexagons have been selected.
<
import java.awt.BasicStroke
Line 2,122 ⟶ 2,499:
}
}
}</
=={{header|Liberty BASIC}}==
By Andy Amaya, Sept. 24, 2015 -- with thanks from the Liberty BASIC Community.
<syntaxhighlight lang="lb">
NoMainWin
Dim hxc(20,2), ltr(26)
Line 2,264 ⟶ 2,641:
End If
End Function
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Two players, 5 by 4.
<
Polygon[Transpose[{{1/2, 1/4, -1/4, -1/2, -1/4, 1/4} +
x, {0, Sqrt[3]/4, Sqrt[3]/4, 0, -Sqrt[3]/4, -Sqrt[3]/4} + y}]];
Line 2,300 ⟶ 2,677:
cols, {If[blue, Blue, Red],
Nearest[locs, MousePosition["Graphics"]][[1]]}];
blue = ! blue]}]]</
=={{header|MATLAB}}==
Line 2,311 ⟶ 2,688:
*Works for up to 26 hexagons before using lowercase labels, 52 hexagons before repeating letters
*Works off of mouse-click events, so program doesn't need to "quit" as it is not really running constantly
<
nRows = 4; % Number of rows
nCols = 5; % Number of columns
Line 2,367 ⟶ 2,744:
set(axesH, 'UserData', newList)
title(newList)
end</
=={{header|Nim}}==
{{libheader|gintro}}
This program is largely inspired by the C version, but this is not a direct translation. We have reused many parts of the C version, for instance the computations and the way to draw the cells. But we have also introduced a “honeycomb” object, improved somewhat the drawing of the labels and taken advantage of the high level binding to Gtk3 provided by “gintro”.
<syntaxhighlight lang="nim">import lenientops, math, random, sequtils, strutils, tables
import gintro/[gobject, gdk, gtk, gio, cairo]
import gintro/glib except PI
const
Size = 308 # Size of drawing area.
NHexagons = 20 # Number of hexagons.
Radius = 30.0
XOffset = 1 + sin(PI / 6)
YOffset = cos(PI / 6)
type
Letter = range['A'..'Z']
# Description of a hexagon.
Hexagon = object
cx, cy: float
letter: Letter
selected: bool
# Description of the honeycomb.
HoneyComb = ref object
hexagons: array[NHexagons, Hexagon] # List of hexagons.
indexes: tables.Table[char, int] # Mapping letter -> index of hexagon.
archive: seq[Letter] # List of selected letters.
label: Label # Label displaying the selected letters.
#---------------------------------------------------------------------------------------------------
proc newHoneyComb(): HoneyComb =
## Create a honeycomb.
new(result)
var letters = toSeq('A'..'Z')
letters.shuffle()
for i in 0..<NHexagons:
result.hexagons[i].letter = letters[i]
result.indexes[letters[i]] = i
# Compute position of hexagon center.
let q = i div 4
let m = i mod 4
result.hexagons[i].cx = Radius * (2 + q * XOffset)
result.hexagons[i].cy = Radius * (2 * (1 + m * YOffset) + (q and 1) * YOffset)
#---------------------------------------------------------------------------------------------------
proc drawHexagons(context: Context; honeyComb: HoneyComb; select: bool) =
## Draw a hexagon (content or border).
for hex in honeyComb.hexagons:
if select == hex.selected:
let cx = hex.cx
let cy = hex.cy
context.moveTo(cx + Radius, cy)
for i in 1..5:
let x = cx + Radius * cos(i * PI / 3)
let y = cy + Radius * sin(i * PI / 3)
context.lineTo(x, y)
#---------------------------------------------------------------------------------------------------
proc drawLabels(context: Context; honeyComb: HoneyComb; select: bool) =
## Draw the labels of the hexagons.
for hex in honeyComb.hexagons:
if select == hex.selected:
let letter = $hex.letter
var extents: TextExtents # Used to adjust letter position in hexagon.
context.getTextExtents(letter, extents)
context.moveTo(hex.cx - extents.width / 2, hex.cy + extents.height / 2)
context.showText(letter)
#---------------------------------------------------------------------------------------------------
proc onDraw(area: DrawingArea; context: Context; honeyComb: HoneyComb): bool =
## Callback to draw/redraw the drawing area contents.
# Fill unselected in yellow.
context.setSource(0.8, 0.8, 0.0, 1.0)
context.drawHexagons(honeyComb, false)
context.fill()
# Fill selected in purple.
context.setSource(0.8, 0.0, 0.8, 1.0)
context.drawHexagons(honeyComb, true)
context.fill()
# Draw border.
context.setLineWidth(3.0)
context.setSource(0.7, 0.7, 0.7, 0.7)
context.drawHexagons(honeyComb, false)
context.stroke()
# Prepare label drawing.
context.selectFontFace("cairo:monospace", FontSlant.normal, FontWeight.bold)
context.setFontSize(14.0)
# Draw labels for selected hexagons.
context.setSource(0, 0, 0, 1)
context.drawLabels(honeyComb, true)
context.stroke()
# Draw labels for unselected hexagons.
context.setSource(0, 0, 1, 1)
context.drawLabels(honeyComb, false)
context.stroke()
result = true
#---------------------------------------------------------------------------------------------------
proc select(honeyComb: HoneyComb; hex: var Hexagon) =
## Select a hexagon.
hex.selected = true
honeyComb.archive.add(hex.letter)
honeyComb.label.setText(honeyComb.label.text() & hex.letter)
#---------------------------------------------------------------------------------------------------
proc onButtonPress(area: DrawingArea; event: Event; honeyComb: HoneyComb): bool =
## Callback to process a button press event.
var xwin, ywin: float
if not event.getCoords(xwin, ywin): return false
# Search the hexagon selected.
for hex in honeyComb.hexagons.mitems:
if hypot(xwin - hex.cx, ywin - hex.cy) < Radius * cos(PI / 15):
if not hex.selected:
honeyComb.select(hex)
area.window().invalidateRect()
break
return true
#---------------------------------------------------------------------------------------------------
proc onKeyPress(area: DrawingArea; event: Event; honeyComb: HoneyComb): bool =
## Callbakc to process a key press event.
var keyval: int
if not event.getKeyval(keyval): return false
if keyval notin ord('a')..ord('z'): return false # For ASCII letters, keyvals are ASCII codes.
let letter = chr(keyval).toUpperAscii() # We want the uppercase letter.
if letter notin honeyComb.indexes: return false
let idx = honeyComb.indexes[letter]
if not honeyComb.hexagons[idx].selected:
honeyComb.select(honeyComb.hexagons[idx])
area.window().invalidateRect()
#---------------------------------------------------------------------------------------------------
proc activate(app: Application) =
## Activate the application.
var honeyComb = newHoneyComb()
let window = app.newApplicationWindow()
window.setTitle("Honeycombs")
let vbox = newBox(Orientation.vertical, 1)
window.add(vbox)
honeyComb.label = newLabel()
vbox.packEnd(honeyComb.label, false, false, 4)
# Create the drawing area.
let area = newDrawingArea()
area.setEvents({EventFlag.buttonPress, EventFlag.keyPress, EventFlag.exposure})
vbox.packStart(area, true, true, 4)
area.setSizeRequest(Size, Size)
area.setCanFocus(true)
# Connect events.
discard area.connect("draw", ondraw, honeyComb)
discard area.connect("button-press-event", onButtonPress, honeyComb)
discard area.connect("key-press-event", onKeyPress, honeyComb)
window.showAll()
#———————————————————————————————————————————————————————————————————————————————————————————————————
randomize()
let app = newApplication(Application, "Rosetta.honeycombs")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
=={{header|Perl}}==
Line 2,373 ⟶ 2,945:
The programme uses the ''Tk'' GUI toolkit.
<
use warnings;
use strict;
Line 2,462 ⟶ 3,034:
)->pack;
$mw->bind('<Alt-q>', sub { $btn->invoke });
MainLoop();</
=={{header|Phix}}==
Line 2,468 ⟶ 3,040:
In the 2 player game, the string chosen contains the selections of both players: odd chars = player 1, even chars = player 2.<br>
Included in the distribution as demo\rosetta\honeycomb.exw
<
include ..\arwen\axtra.ew
Line 2,658 ⟶ 3,230:
setHandler(main,routine_id("mainHandler"))
WinMain(main, SW_NORMAL)</
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<
new(W, window('Honeycomb')),
new(Counter, counter(20)),
Line 2,877 ⟶ 3,449:
:- pce_end_class(cell).
</syntaxhighlight>
[[File:Prolog_honeycombs.png|400px]]
=={{header|PureBasic}}==
Requires PureBasic v4.60. Screen controls in PureBasic are referred to as 'gadgets'.
<
text.s
Status.i ;nonselected = 0, selected = 1
Line 3,084 ⟶ 3,656:
FreeGadget(honeycomb\gadgetID)
CloseWindow(0)
EndIf</
[[File:PureBasic_Honeycomb.png]]
Line 3,091 ⟶ 3,663:
=={{header|Racket}}==
<
(struct Hex (x y letter clicked?) #:mutable #:transparent)
Line 3,151 ⟶ 3,723:
(displayln "The letters were chosen in the order:")
(for-each display (add-between (reverse letters-chosen) " "))</
=={{header|Ruby}}==
{{libheader|Shoes}}
<
C = Math::cos(Math::PI/3)
S = Math::sin(Math::PI/3)
Line 3,289 ⟶ 3,861:
end
end
end</
=={{header|Scala}}==
Line 3,295 ⟶ 3,867:
{{libheader|Scala Java Swing interoperability}}
{{works with|Scala|2.13}}
<
Font, FontMetrics, Graphics, Graphics2D, Point, Polygon, RenderingHints}
import java.awt.event.{KeyAdapter, KeyEvent, MouseAdapter, MouseEvent}
Line 3,385 ⟶ 3,957:
}
}</
=={{header|Sidef}}==
{{trans|Perl}}
[[File:Honeycombs_sidef.png|250px|thumb|right]]
<
class Honeycombs(
Line 3,473 ⟶ 4,045:
}
Honeycombs().display(title: 'Honeycombs')</
=={{header|Tcl}}==
{{libheader|Tk}}
<
package require Tk
Line 3,563 ⟶ 4,135:
tkwait window .c
puts "overall list of characters: $chosen"
exit</
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|DOME}}
{{libheader|Wren-polygon}}
Unlike the Kotlin entry, the 20 capital letters are now chosen at random from the available 26.
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="wren">import "graphics" for Canvas, Color
import "dome" for Window, Process
import "math" for Math
import "font" for Font
import "input" for Mouse, Keyboard
import "random" for Random
import "./polygon" for Polygon
var Rand = Random.new()
class Hexagon is Polygon {
static baseColor { Color.yellow }
static selectedColor { Color.pink }
construct new(x, y, halfWidth, letter) {
_x = x
_y = y
_letter = letter
var vertices = List.filled(6, null)
for (i in 0..5) {
var vx = x + halfWidth * Math.cos(i * Num.pi / 3)
var vy = y + halfWidth * Math.sin(i * Num.pi / 3)
vertices[i] = [vx, vy]
}
super(vertices, "")
_selected = false
}
letter { _letter }
selected { _selected }
selected=(v) { _selected = v }
draw() {
var col = selected ? Hexagon.selectedColor : Hexagon.baseColor
drawfill(col)
super.draw(Color.black)
col = selected ? Color.black : Color.red
Canvas.print(_letter, _x - 8, _y - 8, col)
}
}
class Honeycombs {
construct new(width, height) {
Window.title = "Honeycombs"
Window.resize(width, height)
Canvas.resize(width, height)
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toList
Rand.shuffle(letters)
_letters = letters[0..19]
_x1 = 150
_y1 = 100
_x2 = 225
_y2 = 143
_w = 150
_h = 87
_hs = null
_comb = List.filled(20, null)
Font.load("memory", "memory.ttf", 48)
Font["memory"].antialias = true
Canvas.font = "memory"
}
drawHexagons() {
for (i in 0..._comb.count) {
var x
var y
if (i < 12) {
x = _x1 + (i % 3) * _w
y = _y1 + (i / 3).floor * _h
} else {
x = _x2 + (i % 2) * _w
y = _y2 + ((i - 12) / 2).floor * _h
}
_comb[i] = Hexagon.new(x, y, (_w / 3).floor, _letters[i])
_comb[i].draw()
}
}
allSelected() { _comb.all { |h| h.selected } }
init() {
drawHexagons()
}
update() {
_hs = null
if (Mouse.isButtonPressed("left")) {
for (h in _comb) {
if (h.contains(Mouse.position.x, Mouse.position.y)) {
_hs = h
break
}
}
} else if (Keyboard.allPressed.count > 0) {
for (h in _comb) {
if (Keyboard.isKeyDown(h.letter)) {
_hs = h
break
}
}
}
}
draw(alpha) {
if (_hs) {
_hs.selected = true
_hs.draw()
if (allSelected()) Process.exit(0)
}
}
}
var Game = Honeycombs.new(600, 500)</syntaxhighlight>
=={{header|XPL0}}==
[[File:HoneyXPL0.gif|right]]
<
proc DrawHexagon(X0, Y0, Side, Color); \Draw a filled hexagon centered at X0,Y0
Line 3,608 ⟶ 4,301:
until Counter >= Cols*Rows;
SetVid($03); \restore normal text display
]</
{{omit from|ACL2}}
|