# Chess game

**URL:** <https://discourse.julialang.org/t/chess-game/16417>\
**Category:** New to Julia\
**Created:** [October 16, 2018, 4:29pm UTC](https://discourse.julialang.org/t/chess-game/16417 "2018-10-16T16:29:46Z")\
**Posts on this page:** 1\
**Showing post:** 29

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [October 17, 2018, 8:46am UTC](https://discourse.julialang.org/t/chess-game/16417/29 "2018-10-17T08:46:20Z")

</div>

Here’s how you can draw a chess board in Gtk.jl (from the [docs](http://juliagraphics.github.io/Gtk.jl/latest/manual/canvas.html)) :

```julia
using Gtk, Graphics
c = @GtkCanvas()
win = GtkWindow(c, "Canvas")

function rect!(ctx,x,y,w,h,col)
    rectangle(ctx, x, y, w, h)
    set_source_rgb(ctx, col...)
    fill(ctx)
end

@guarded draw(c) do widget
    ctx = getgc(c)
    h,w = height(c), width(c)
    
    N=8
    for (i,x) in enumerate(linspace(0,w,N)), (j,y) in enumerate(linspace(0,h,N))
        rect!(ctx,x,y,w/N,h/N, mod(i+j,2)==0 ? (0.1,0.1,0.1) : (1.0,1.0,1.0) )
    end
end
show(c)

```

There’s also an example of handling mouse clicks in the docs.

---

_[View the full topic](https://discourse.julialang.org/t/chess-game/16417)._
