Skip to content

Instantly share code, notes, and snippets.

@intel352
Forked from tetsuok/answer_pic.go
Created September 17, 2012 14:45

Revisions

  1. intel352 revised this gist Sep 17, 2012. 1 changed file with 8 additions and 20 deletions.
    28 changes: 8 additions & 20 deletions answer_pic.go
    Original file line number Diff line number Diff line change
    @@ -3,28 +3,16 @@ package main
    import "code.google.com/p/go-tour/pic"

    func Pic(dx, dy int) [][]uint8 {
    // Allocate two-dimensioanl array.
    a := make([][]uint8, dy)
    for i := 0; i < dy; i++ {
    a[i] = make([]uint8, dx)
    }
    x := make([]uint8, dx)
    y := make([][]uint8, dy)

    // Do something.
    for i := 0; i < dy; i++ {
    for j := 0; j < dx; j++ {
    switch {
    case j % 15 == 0:
    a[i][j] = 240
    case j % 3 == 0:
    a[i][j] = 120
    case j % 5 == 0:
    a[i][j] = 150
    default:
    a[i][j] = 100
    }
    for n := range y {
    y[n] = x
    for m := range x {
    y[n][m] = uint8((n+m)/2)
    }
    }
    return a
    }
    return y
    }

    func main() {
  2. Tetsuo Kiso revised this gist Apr 2, 2012. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions answer_pic.go
    Original file line number Diff line number Diff line change
    @@ -12,18 +12,18 @@ func Pic(dx, dy int) [][]uint8 {
    // Do something.
    for i := 0; i < dy; i++ {
    for j := 0; j < dx; j++ {
    if j % 15 == 0 {
    switch {
    case j % 15 == 0:
    a[i][j] = 240
    } else if j % 3 == 0 {
    case j % 3 == 0:
    a[i][j] = 120
    } else if j % 5 == 0 {
    case j % 5 == 0:
    a[i][j] = 150
    } else {
    default:
    a[i][j] = 100
    }
    }
    }

    }
    return a
    }

  3. Tetsuo Kiso created this gist Apr 2, 2012.
    32 changes: 32 additions & 0 deletions answer_pic.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    package main

    import "code.google.com/p/go-tour/pic"

    func Pic(dx, dy int) [][]uint8 {
    // Allocate two-dimensioanl array.
    a := make([][]uint8, dy)
    for i := 0; i < dy; i++ {
    a[i] = make([]uint8, dx)
    }

    // Do something.
    for i := 0; i < dy; i++ {
    for j := 0; j < dx; j++ {
    if j % 15 == 0 {
    a[i][j] = 240
    } else if j % 3 == 0 {
    a[i][j] = 120
    } else if j % 5 == 0 {
    a[i][j] = 150
    } else {
    a[i][j] = 100
    }
    }
    }

    return a
    }

    func main() {
    pic.Show(Pic)
    }