Source file tour/solutions/image.go

     1  // Copyright 2012 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build ignore
     6  
     7  package main
     8  
     9  import (
    10  	"image"
    11  	"image/color"
    12  
    13  	"golang.org/x/tour/pic"
    14  )
    15  
    16  type Image struct {
    17  	Height, Width int
    18  }
    19  
    20  func (m Image) ColorModel() color.Model {
    21  	return color.RGBAModel
    22  }
    23  
    24  func (m Image) Bounds() image.Rectangle {
    25  	return image.Rect(0, 0, m.Height, m.Width)
    26  }
    27  
    28  func (m Image) At(x, y int) color.Color {
    29  	c := uint8(x ^ y)
    30  	return color.RGBA{c, c, 255, 255}
    31  }
    32  
    33  func main() {
    34  	m := Image{256, 256}
    35  	pic.ShowImage(m)
    36  }
    37  

View as plain text