Golang Introduction--A 2D graphics library learning

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

This library is called GG, source code on GitHub.

1. Get the source code and install it locally:

First install git (portal): https://git-scm.com/download/

You can then get the source code from git and install it via the Go Get command (this is where go is installed by default): Go to the Gopath directory in cmd and enter: Go get github.com/fogleman/gg

After a while you can see that Gopath has the source of GG, and by the way GG's reliance on third-party libraries also downloaded.

2. The Src\github.com\fogleman\gg\examples catalogue is an example written by GG authors. Here, pick one out to practice practiced hand:

Package main    Import (      "Github.com/fogleman/gg" "      Math/rand"  )    func main () {        Const W = 1024      Const H = 1024x768      DC: = GG. Newcontext (W, H)//context, with long and wide      DC. Setrgb (0, 0, 0)        //Set current color      DC. Clear ()                //Clear the context and start drawing below for        I: = 0; I < i++ {//Draw 1000 lines, random position, length, color and transparency          x1: = Rand. Float64 () * W          y1: = Rand. Float64 () * H          x2: = Rand. Float64 () * W          y2: = Rand. Float64 () * H            r: = Rand. Float64 ()          g: = Rand. Float64 ()          b: = Rand. Float64 ()          A: = Rand. Float64 () *0.5 + 0.5          w: = Rand. Float64 () + 1          DC. Setrgba (R, G, B, a)          DC. Setlinewidth (w)          DC. DrawLine (x1, y1, x2, y2)//Draw line          DC. Stroke ()                 //No This sentence is not the final drawing of the line of the      }      DC. Savepng ("lines.png")//save context as a picture  }  

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.