선수로 산다, 때론 좋은 코치로

[golang] A Tour of Go - 60 연습 문제 본문

개발 관련/go

[golang] A Tour of Go - 60 연습 문제

godsman 2018. 2. 13. 18:00

[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)
}


Comments