New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/king133134/go-word-cloud

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/king133134/go-word-cloud

  • v0.0.5
  • Source
  • Go
  • Socket score

Version published
Created
Source
  • English简体中文

通过go来生成词云

使用

效果图

example

安装

go get -u github.com/king133134/go-word-cloud

Example

package main

import (
    "github.com/king133134/go-word-cloud"
    "golang.org/x/image/font/opentype"
    "log"
    "math/rand"
    "os"
)

func main() {
    custom()
}

func randSize() {
    cloud := wordcloud.NewWordCloud(800, 450)
    words := []string{"love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子", "love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子", "love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子", "love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子"}

    fontBytes, _ := os.ReadFile("./fonts/SmileySans.ttf")
    f, err := opentype.Parse(fontBytes)
    if err != nil {
        log.Fatalf("err: %v", err)
    }
    cloud.SetRotate(120, 5)
    cloud.SetFont(f)
    err = cloud.Render(wordcloud.NewWords(words), "test/out.png")
    if err != nil {
        log.Fatalf("err: %v", err)
    }
}

func custom() {
    cloud := wordcloud.NewWordCloud(800, 450)
    words := []string{"love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子", "love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子", "love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子", "love", "movie", "animation", "music", "分子", "电子", "松子", "离子", "绝绝子", "孙子", "孟子",
        "孔子", "老子", "原子", "质子", "中子", "上帝粒子"}

    w := make([]*wordcloud.Word, len(words))
    for i, word := range words {
        w[i] = wordcloud.NewWord(word, rand.Intn(45)+15, wordcloud.Color(wordcloud.NewRandColor()))
    }

    fontBytes, _ := os.ReadFile("./fonts/SmileySans.ttf")
    f, err := opentype.Parse(fontBytes)
    if err != nil {
        log.Fatalf("err: %v", err)
    }
    cloud.SetFont(f)
    cloud.SetRotate(120, 5)
    err = cloud.Render(w, "test/out.png")
    if err != nil {
        log.Fatalf("err: %v", err)
    }
}

许可

MIT

FAQs

Package last updated on 27 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc