Skip to content

Ascii art for Go lovers

March 19, 2013

Steps
1) Go to page http://tour.golang.org/#35
2) Clear the existing code in the window
3) Copy and paste the following code (between ‘Begin’ and ‘End’ lines):

// === BEGIN ===
package main

import (
    //"fmt"
    "math"
    "code.google.com/p/go-tour/pic")

func Pic(dx, dy int) [][]uint8 {
        try_slice := make([][]uint8, dy)
        for i:=0; i<dy; i++{
        try_slice[i] = make([]uint8, dx)

        for j:=0; j<dx; j++ {

            // initialization to light color 
        // Note: 255 is light and 0 is the darkest
            try_slice[i][j] = 230

            // Printing of 'I'
            if i > (dy/2-40) && i < (dy/2 - 10) && j>=20 && j<23{
              try_slice[i][j] = 0
            }

            // Printing of 'heart'
            // Thanks to http://www.intmath.com/blog/i-heart-math/5179

            x:= float64(j - dx/2)/float64(dx/4)
            y:= float64(dy - i - dy/2)/float64(dy/4)

            if math.Pow(float64(x*x + y*y - 1 ), float64(3)) <= x*x*y*y*y {
                try_slice[i][j] = 0
            } 

            // Printing of G'
            if  i > (dy/2-40) && i < (dy/2 - 36)  && j>= dx-40 && j<dx-27{
              try_slice[i][j] = 0
            }
            if  i > (dy/2-40) && i < (dy/2 - 10)  && j>= dx-43 && j<dx-40{
              try_slice[i][j] = 0
            }
            if  i > (dy/2-14) && i < (dy/2 - 10)  && j>= dx-40 && j<dx-30{
              try_slice[i][j] = 0
            }
            if  i > (dy/2-25) && i < (dy/2 - 10)  && j>= dx-30 && j<dx-27{
              try_slice[i][j] = 0
            }
            if  i > (dy/2-25) && i < (dy/2 - 21)  && j>= dx-36 && j<dx-30{
              try_slice[i][j] = 0
            }

            // Printing of 'o'
            if  i > (dy/2-25) && i < (dy/2 - 21)  && j>= dx-21 && j<dx-15{
              try_slice[i][j] = 0
            }
            if  i > (dy/2-25) && i < (dy/2 - 10)  && j>= dx-24 && j<dx-21{
              try_slice[i][j] = 0
            }            
            if  i > (dy/2-14) && i < (dy/2 - 10)  && j>= dx-21 && j<dx-15{
              try_slice[i][j] = 0
            }
            if  i > (dy/2-25) && i < (dy/2 - 10)  && j>= dx-15 && j<dx-12{
              try_slice[i][j] = 0
            }

        }
    }

    //fmt.Printf("%v\n", try_slice)

    return try_slice
}

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

// === END   ===

4) Click Run

Yeah kiddish stuff but fun 🙂

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: