wordcloud_go

package module
v0.0.0-...-a3d009a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

golang版本的文字云算法实现

项目链接

https://gitee.com/bangbaoshi/wordcloud

效果图
测试步骤如下
cd $GOPATH/src/gitee.com/bangbaoshi

git clone https://gitee.com/bangbaoshi/wordcloud.git

cd wordcloud

go run boot/main.go

通过以上四步即可在imgs目录中生成文字云图片(查看imgs/out.png)

目录介绍
  1. boot目录包含测试用例
  2. fonts目录包含若干种字体(非商业使用)
  3. imgs目录包含模板图片,文字云生成的效果图就是按照模板图片的样子来生成
使用说明

boot/main.go中已经简单介绍了使用方法

package main

import (
	"image/color"
	"gitee.com/bangbaoshi/wordcloud"
)

func renderNow() {
	//需要写入的文本数组
	textList := []string{"恭喜", "发财", "万事", "如意"}
	//文本角度数组
	angles := []int{0, 15, -15, 90}
	//文本颜色数组
	colors := []*color.RGBA{
		&color.RGBA{0x0, 0x60, 0x30, 0xff},
		&color.RGBA{0x60, 0x0, 0x0, 0xff},
		&color.RGBA{0x73, 0x73, 0x0, 0xff},
	}
	//设置对应的字体路径,和输出路径
	render := wordcloud_go.NewWordCloudRender(60, 8,
		"./fonts/xin_shi_gu_yin.ttf",
		"./imgs/tiger.png", textList, angles, colors, "./imgs/out.png")
	//开始渲染
	render.Render()
}

func main() {
	renderNow()
}


项目介绍
  1. 使用golang语言实现了文字云算法
  2. 用golang实现一些有趣的想法

Documentation

Index

Constants

View Source
const (
	IS_NOT_FIT = 1
	IS_FIT     = 2
	OUT_INDEX  = 3
	DEGREE_360 = 360
	DEGREE_180 = 180
	IS_EMPTY   = 0
	XUNIT      = 2
	YUNIT      = 2
)

Variables

This section is empty.

Functions

func Angle2Pi

func Angle2Pi(angle float64) float64

func CeilT

func CeilT(value float64) float64

func Clear

func Clear(dc *gg.Context)

*先设置清空颜色,再进行清空

func CosT

func CosT(angle float64) float64

func DrawText

func DrawText(dc *gg.Context, text string, xpos, ypos, rotation float64)

func GetTextBound

func GetTextBound(measureDc *gg.Context, text string) (w, h, xdiff, ydiff float64)

func Rotate

func Rotate(grid *Grid, angle float64, centerX, centerY int)

func SinT

func SinT(angle float64) float64

Types

type CheckResult

type CheckResult struct {
	Angle          int
	Xpos           int
	Ypos           int
	LastCheckAngle int
}

type Grid

type Grid struct {
	Width  int
	Height int

	XScale int
	YScale int
	// contains filtered or unexported fields
}

func (*Grid) Fill

func (this *Grid) Fill(gridIntArrayWidth, gridIntArrayHeight int, gridIntArray []int)

func (*Grid) IsFit

func (this *Grid) IsFit(xIncrement, yIncrement, width, height int, gridIntArray []int) int

func (*Grid) SetCollisionMap

func (this *Grid) SetCollisionMap(collisionMap []int, width, height int)

type Position

type Position struct {
	Xpos   int
	Ypos   int
	Value  int
	XLeiji int
	YLeiji int
}

func NewPosition

func NewPosition(xpos, ypos, value, xleiji, yleiji int) *Position

func TwoByBlock

func TwoByBlock(width, height int) ([]*Position, int, int)

type WordCloudRender

type WordCloudRender struct {
	MaxFontSize    float64
	MinFontSize    float64
	FontPath       string
	OutlineImgPath string
	MeasureDc      *gg.Context
	DrawDc         *gg.Context
	TextList       []string
	Angles         []int
	Colors         []*color.RGBA
	OutImgPath     string
	// contains filtered or unexported fields
}

func NewWordCloudRender

func NewWordCloudRender(maxFontSize, minFontSize float64, fontPath string,
	imgPath string, textList []string,
	angles []int, colors []*color.RGBA,
	outImgPath string) *WordCloudRender

func (*WordCloudRender) Render

func (this *WordCloudRender) Render()

func (*WordCloudRender) ResetMeasureDc

func (this *WordCloudRender) ResetMeasureDc(fontSize float64)

func (*WordCloudRender) UpdateFontSize

func (this *WordCloudRender) UpdateFontSize(fontSize float64)

type WorldMap

type WorldMap struct {
	Width           int
	Height          int
	CollisionMap    []int
	RealImageWidth  int
	RealImageHeight int
}

func TwoByBitmap

func TwoByBitmap(imgpath string) *WorldMap

func (*WorldMap) PrintMap

func (this *WorldMap) PrintMap()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL