선수로 산다, 때론 좋은 코치로
[golang] A Tour of Go - 60 연습 문제 본문
[golang] A Tour of Go - 60 연습 문제
https://go-tour-kr.appspot.com/#60
package main
import (
"code.google.com/p/go-tour/pic"
"image"
)
type Image struct{}
func main() {
m := Image{}
pic.ShowImage(m)
}
import package 변경 - "golang.org/x/tour/pic"
x, y 멤버를 갖는 구조체 Image 생성
Image에 ColorModel() 메서드, Bound 메서드, Rectagle 메서드 붙임
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct{
w int
h int
}
func (img *Image) ColorModel() color.Model {
return color.RGBAModel
}
func (img *Image) Bounds() image.Rectangle {
return image.Rect(0, 0, img.w , img.h)
}
func (img *Image) At(x, y int) color.Color {
return color.RGBA{uint8(x), uint8(y), 255, 255}
}
func main() {
m := &Image{256, 256}
pic.ShowImage(m)
}
'개발 관련 > go' 카테고리의 다른 글
[golang] 엘라스틱서치로 우리은행 거래내역 분석하기-엑셀파일 읽기 (0) | 2018.02.19 |
---|---|
[golang] A Tour of Go - 61 연습 문제 (0) | 2018.02.13 |
[golang] A Tour of Go - 58 연습 문제 (0) | 2018.02.12 |
[golang] A Tour of Go - 56 연습 문제 (0) | 2018.02.12 |
[golang] A Tour of Go - 48 연습 문제 (0) | 2018.02.12 |
Comments