diff options
author | Francisco Souza <franciscossouza@gmail.com> | 2012-03-28 14:20:51 +1100 |
---|---|---|
committer | Nigel Tao <nigeltao@golang.org> | 2012-03-28 14:20:51 +1100 |
commit | 18f1a71dc282689f29eeb51e248e6f79a970965b (patch) | |
tree | dc0adea18602cd88f5015284f7cc44c52f9d85e4 /doc/progs | |
parent | 81dbec12c8ee01848c0f3edb93149ab56adefc79 (diff) | |
download | go-git-18f1a71dc282689f29eeb51e248e6f79a970965b.tar.gz |
doc: added The Go image package article
Orignally published on The Go Programming Language, September 21, 2011.
http://blog.golang.org/2011/09/go-image-package.html
Update #2547
R=adg, nigeltao
CC=golang-dev
https://golang.org/cl/5933049
Diffstat (limited to 'doc/progs')
-rw-r--r-- | doc/progs/image_package1.go | 15 | ||||
-rw-r--r-- | doc/progs/image_package2.go | 16 | ||||
-rw-r--r-- | doc/progs/image_package3.go | 15 | ||||
-rw-r--r-- | doc/progs/image_package4.go | 16 | ||||
-rw-r--r-- | doc/progs/image_package5.go | 17 | ||||
-rw-r--r-- | doc/progs/image_package6.go | 17 | ||||
-rwxr-xr-x | doc/progs/run | 19 |
7 files changed, 114 insertions, 1 deletions
diff --git a/doc/progs/image_package1.go b/doc/progs/image_package1.go new file mode 100644 index 0000000000..c4c401e729 --- /dev/null +++ b/doc/progs/image_package1.go @@ -0,0 +1,15 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "image" +) + +func main() { + p := image.Point{2, 1} + fmt.Println("X is", p.X, "Y is", p.Y) +} diff --git a/doc/progs/image_package2.go b/doc/progs/image_package2.go new file mode 100644 index 0000000000..fcb5d9fd03 --- /dev/null +++ b/doc/progs/image_package2.go @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "image" +) + +func main() { + r := image.Rect(2, 1, 5, 5) + // Dx and Dy return a rectangle's width and height. + fmt.Println(r.Dx(), r.Dy(), image.Pt(0, 0).In(r)) // prints 3 4 false +} diff --git a/doc/progs/image_package3.go b/doc/progs/image_package3.go new file mode 100644 index 0000000000..13d0f08079 --- /dev/null +++ b/doc/progs/image_package3.go @@ -0,0 +1,15 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "image" +) + +func main() { + r := image.Rect(2, 1, 5, 5).Add(image.Pt(-4, -2)) + fmt.Println(r.Dx(), r.Dy(), image.Pt(0, 0).In(r)) // prints 3 4 true +} diff --git a/doc/progs/image_package4.go b/doc/progs/image_package4.go new file mode 100644 index 0000000000..c46fddf07a --- /dev/null +++ b/doc/progs/image_package4.go @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "image" +) + +func main() { + r := image.Rect(0, 0, 4, 3).Intersect(image.Rect(2, 2, 5, 5)) + // Size returns a rectangle's width and height, as a Point. + fmt.Printf("%#v\n", r.Size()) // prints image.Point{X:2, Y:1} +} diff --git a/doc/progs/image_package5.go b/doc/progs/image_package5.go new file mode 100644 index 0000000000..0bb5c7608e --- /dev/null +++ b/doc/progs/image_package5.go @@ -0,0 +1,17 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "image" + "image/color" +) + +func main() { + m := image.NewRGBA(image.Rect(0, 0, 640, 480)) + m.Set(5, 5, color.RGBA{255, 0, 0, 255}) + fmt.Println(m.At(5, 5)) +} diff --git a/doc/progs/image_package6.go b/doc/progs/image_package6.go new file mode 100644 index 0000000000..62eeecdb92 --- /dev/null +++ b/doc/progs/image_package6.go @@ -0,0 +1,17 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "image" +) + +func main() { + m0 := image.NewRGBA(image.Rect(0, 0, 8, 5)) + m1 := m0.SubImage(image.Rect(1, 2, 5, 5)).(*image.RGBA) + fmt.Println(m0.Bounds().Dx(), m1.Bounds().Dx()) // prints 8, 4 + fmt.Println(m0.Stride == m1.Stride) // prints true +} diff --git a/doc/progs/run b/doc/progs/run index 8348a33e56..92c8da5cdc 100755 --- a/doc/progs/run +++ b/doc/progs/run @@ -59,7 +59,16 @@ json=" json5 " -all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json slices go1) +image_package=" + image_package1 + image_package2 + image_package3 + image_package4 + image_package5 + image_package6 +" + +all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json $image_package slices go1) for i in $all; do go build $i.go @@ -87,9 +96,17 @@ testit eff_sequence '^\[-1 2 6 16 44\]$' testit go1 '^Christmas is a holiday: true Sleeping for 0.123s.*go1.go already exists$' testit interface2 "^type: float64$" + testit json1 "^$" testit json2 "the reciprocal of i is" testit json3 "Age is int 6" testit json4 "^$" +testit image_package1 "^X is 2 Y is 1$" +testit image_package2 "^3 4 false$" +testit image_package3 "^3 4 true$" +testit image_package4 "^image.Point{X:2, Y:1}$" +testit image_package5 "^{255 0 0 255}$" +testit image_package6 "^8 4 true$" + rm -f $all "$TMPFILE" |