• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang fixed.P函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/image/math/fixed.P函数的典型用法代码示例。如果您正苦于以下问题:Golang P函数的具体用法?Golang P怎么用?Golang P使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了P函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: drawPerimeterNumber

func drawPerimeterNumber(dst draw.Image, pt image.Point, number string) {
	dot := fixed.P(pt.X, pt.Y)
	d := font.Drawer{
		Dst:  dst,
		Src:  image.NewUniform(color.RGBA{B: 0xFF, A: 0xFF}),
		Face: basicfont.Face7x13,
		Dot:  dot,
	}
	d.DrawString(number)
}
开发者ID:jnjackins,项目名称:slice,代码行数:10,代码来源:draw.go


示例2: Render

func (c *Context) Render(txt string, size float64, col color.Color) (*image.RGBA, error) {
	bnd := c.fnt.Bounds(fixed.I(int(size + 0.5)))
	lh := int26_6ToFloat64(bnd.Max.Y) - int26_6ToFloat64(bnd.Min.Y) - 0.5

	c.ft.SetSrc(image.NewUniform(col))
	c.ft.SetFontSize(size)

	/* Render image to temporary buffer to determine final size */
	tmp := nullImage{}
	c.ft.SetDst(tmp)
	c.ft.SetClip(tmp.Bounds())
	p, err := c.ft.DrawString(txt, fixed.P(0, int(lh)))
	if err != nil {
		return nil, err
	}

	dst := image.NewRGBA(image.Rect(0, 0, int(int26_6ToFloat64(p.X)+0.5), int(lh)))
	draw.Draw(dst, dst.Bounds(), image.NewUniform(color.RGBA{}), image.ZP, draw.Src)
	c.ft.SetDst(dst)
	c.ft.SetClip(dst.Bounds())

	p, err = c.ft.DrawString(txt, fixed.P(0, int(size)))
	if err != nil {
		return nil, err
	}

	return dst, nil
}
开发者ID:farhaven,项目名称:universe,代码行数:28,代码来源:text.go


示例3: main

func main() {
	const (
		w = 400
		h = 400
	)
	r := raster.NewRasterizer(w, h)
	r.UseNonZeroWinding = true

	cjs := []struct {
		c raster.Capper
		j raster.Joiner
	}{
		{raster.RoundCapper, raster.RoundJoiner},
		{raster.ButtCapper, raster.BevelJoiner},
		{raster.SquareCapper, raster.BevelJoiner},
	}

	for i, cj := range cjs {
		var path raster.Path
		path.Start(fixed.P(30+100*i, 30+120*i))
		path.Add1(fixed.P(180+100*i, 80+120*i))
		path.Add1(fixed.P(50+100*i, 130+120*i))
		raster.Stroke(r, path, fixed.I(20), cj.c, cj.j)
	}

	rgba := image.NewRGBA(image.Rect(0, 0, w, h))
	draw.Draw(rgba, rgba.Bounds(), image.Black, image.Point{}, draw.Src)
	p := raster.NewRGBAPainter(rgba)
	p.SetColor(color.RGBA{0x7f, 0x7f, 0x7f, 0xff})
	r.Rasterize(p)

	white := color.RGBA{0xff, 0xff, 0xff, 0xff}
	for i := range cjs {
		rgba.SetRGBA(30+100*i, 30+120*i, white)
		rgba.SetRGBA(180+100*i, 80+120*i, white)
		rgba.SetRGBA(50+100*i, 130+120*i, white)
	}

	// Save that RGBA image to disk.
	outFile, err := os.Create("out.png")
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	defer outFile.Close()
	b := bufio.NewWriter(outFile)
	err = png.Encode(b, rgba)
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	err = b.Flush()
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	fmt.Println("Wrote out.png OK.")
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:58,代码来源:main.go


示例4: TestHorizontalLayout

func TestHorizontalLayout(t *testing.T) {
	layout := NewHorizontalLayout(fixed.P(10, 10), fixed.P(100, 100))

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the horizontal layout")
	} else if r != fixed.R(10, 10, 110, 110) {
		t.Error("invalid bounds returned by the horizontal layout:", r)
	}

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the horizontal layout")
	} else if r != fixed.R(110, 10, 210, 110) {
		t.Error("invalid bounds returned by the horizontal layout:", r)
	}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:15,代码来源:layout_test.go


示例5: BenchmarkDrawString

func BenchmarkDrawString(b *testing.B) {
	data, err := ioutil.ReadFile("../licenses/gpl.txt")
	if err != nil {
		b.Fatal(err)
	}
	lines := strings.Split(string(data), "\n")
	data, err = ioutil.ReadFile("../testdata/luxisr.ttf")
	if err != nil {
		b.Fatal(err)
	}
	f, err := Parse(data)
	if err != nil {
		b.Fatal(err)
	}
	dst := image.NewRGBA(image.Rect(0, 0, 800, 600))
	draw.Draw(dst, dst.Bounds(), image.White, image.ZP, draw.Src)
	d := &font.Drawer{
		Dst:  dst,
		Src:  image.Black,
		Face: NewFace(f, nil),
	}
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		for j, line := range lines {
			d.Dot = fixed.P(0, (j*16)%600)
			d.DrawString(line)
		}
	}
}
开发者ID:Rudloff,项目名称:platform,代码行数:30,代码来源:face_test.go


示例6: TestDrawView

func TestDrawView(t *testing.T) {
	const str = "Hello World!\nHow are you doing?"

	f1 := truetype.NewFace(clearSans, &truetype.Options{DPI: 144})
	f2 := truetype.NewFace(clearSansBoldItalic, &truetype.Options{DPI: 144})

	red := image.NewUniform(color.RGBA{255, 0, 0, 255})
	yellow := image.NewUniform(color.RGBA{255, 255, 0, 255})

	view, _ := Render(
		NewReader(
			strings.NewReader("Hello World!\nHow are you doing?"),
			Style{Offset: 0, Face: f1, Foreground: image.Black, Background: yellow},
			Style{Offset: 10, Face: f2, Foreground: red, Background: yellow},
			Style{Offset: 20, Face: f1, Foreground: image.Black, Background: image.White},
		),
		NewNaturalLayout(fixed.P(0, 0)),
	)

	size := view.Bounds.Max.Sub(view.Bounds.Min)

	for _, a := range []Alignment{Left, Right, Center, Justify} {
		dst := image.NewRGBA(image.Rect(0, 0, int(size.X>>6)+1, int(size.Y>>6)+1))
		view.Align(a)
		view.Draw(dst, LeftToRight)
		saveTest(t, dst, "text.View.Draw_"+a.(fmt.Stringer).String()+".png")
	}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:28,代码来源:draw_test.go


示例7: newTextTexture

func (l *Label) newTextTexture(eng sprite.Engine) sprite.SubTex {

	fg, bg := image.Black, image.White
	draw.Draw(l.rgba, l.rgba.Bounds(), bg, image.ZP, draw.Src)
	d := &sfont.Drawer{
		Dst: l.rgba,
		Src: fg,
		Face: truetype.NewFace(l.font, truetype.Options{
			Size:    l.fontSize,
			DPI:     72,
			Hinting: sfont.HintingFull,
		}),
	}

	spacing := 1.5
	dy := int(math.Ceil(l.fontSize * spacing))
	for i, s := range strings.Split(l.Text, "\n") {
		d.Dot = fixed.P(0, int(l.fontSize*0.8)+dy*i)
		d.DrawString(s)
	}

	t, err := eng.LoadTexture(l.rgba)
	if err != nil {
		log.Fatal(err)
	}

	return sprite.SubTex{t, l.rgba.Bounds()}
}
开发者ID:tenntenn,项目名称:gomoxy,代码行数:28,代码来源:label.go


示例8: drawLayerNumber

func drawLayerNumber(dst draw.Image, n int) {
	d := font.Drawer{
		Dst:  dst,
		Src:  image.Black,
		Face: basicfont.Face7x13,
		Dot:  fixed.P(2, 13),
	}
	d.DrawString(fmt.Sprintf("Layer %03d", n))
}
开发者ID:jnjackins,项目名称:slice,代码行数:9,代码来源:main.go


示例9: TestVerticalLayout

func TestVerticalLayout(t *testing.T) {
	layout := NewVerticalLayout(fixed.P(10, 10), fixed.I(100))

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the vertical layout")
	} else if r != fixed.R(10, 10, 110, 33554431) {
		t.Error("invalid bounds returned by the vertical layout:", r)
	}

	if _, ok := layout.NextBounds(); ok {
		t.Error("incomplete vertical layout")
	}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:13,代码来源:layout_test.go


示例10: RenderNRGBA

func (f *Font) RenderNRGBA(text string) *image.NRGBA {
	width, height, yBearing := f.TextDimensions(text)
	font := f.TTF
	size := f.Size

	if size <= 0 {
		panic("Font size cannot be <= 0")
	}

	// Default colors
	if f.FG == nil {
		f.FG = color.NRGBA{0, 0, 0, 0}
	}
	if f.BG == nil {
		f.BG = color.NRGBA{0, 0, 0, 0}
	}

	// Colors
	fg := image.NewUniform(f.FG)
	bg := image.NewUniform(f.BG)

	// Create the font context
	c := freetype.NewContext()

	nrgba := image.NewNRGBA(image.Rect(0, 0, width, height))
	draw.Draw(nrgba, nrgba.Bounds(), bg, image.ZP, draw.Src)

	c.SetDPI(dpi)
	c.SetFont(font)
	c.SetFontSize(size)
	c.SetClip(nrgba.Bounds())
	c.SetDst(nrgba)
	c.SetSrc(fg)

	// Draw the text.
	pt := fixed.P(0, int(yBearing))
	_, err := c.DrawString(text, pt)
	if err != nil {
		log.Println(err)
		return nil
	}

	return nrgba
}
开发者ID:matiwinnetou,项目名称:engi,代码行数:44,代码来源:font.go


示例11: TestCharAtSuccess

func TestCharAtSuccess(t *testing.T) {
	f := truetype.NewFace(clearSans, nil)
	defer f.Close()

	c := NewReader(strings.NewReader("Hello World!\n"),
		Style{Offset: 0, Face: f, Foreground: image.Black, Background: image.White},
	)

	view, err := Render(c, NewNaturalLayout(fixed.P(1, 1)))

	if err != nil {
		t.Error(err)
		return
	}

	char, bounds, ok := view.CharAt(fixed.Point26_6{
		X: int26_6(31, 0),
		Y: int26_6(5, 0),
	}, LeftToRight)

	if !ok {
		t.Error("no char found")
		return
	}

	if char != (Char{
		Offset:     5,
		Rune:       ' ',
		Face:       f,
		Foreground: image.Black,
		Background: image.White,
	}) {
		t.Error("invalid char found:", char)
	}

	if bounds != (fixed.Rectangle26_6{
		Min: fixed.Point26_6{X: int26_6(28, 37), Y: int26_6(1, 0)},
		Max: fixed.Point26_6{X: int26_6(31, 35), Y: int26_6(15, 5)},
	}) {
		t.Error("invalid char bounds:", bounds)
	}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:42,代码来源:view_test.go


示例12: Create

func (t *TextTexture) Create(eng sprite.Engine, text string) (sprite.SubTex, error) {
	draw.Draw(t.rgba, t.rgba.Bounds(), t.bg, image.ZP, draw.Src)
	d := &sfont.Drawer{
		Dst:  t.rgba,
		Src:  t.fg,
		Face: t.Face,
	}

	dy := int(math.Ceil(t.Face.Size * t.Spacing))
	for i, s := range strings.Split(text, "\n") {
		d.Dot = fixed.P(0, int(t.Face.Size*0.8)+dy*i)
		d.DrawString(s)
	}

	tex, err := eng.LoadTexture(t.rgba)
	if err != nil {
		return sprite.SubTex{}, err
	}

	return sprite.SubTex{tex, t.rgba.Bounds()}, nil
}
开发者ID:tenntenn,项目名称:gomui,代码行数:21,代码来源:text.go


示例13: Render

func (f *Font) Render(text string, width, height float32, color Color) *Texture {
	/* Set color */
	f.drawer.Src = image.NewUniform(color.RGBA())

	line := math.Ceil(f.Size * f.DPI / 72)
	//height := int(f.Spacing * line)
	//width := int(float64(f.drawer.MeasureString(text)) / f.Size)

	/* Create and attach destination image */
	rgba := image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
	f.drawer.Dst = rgba

	/* Draw text */
	f.drawer.Dot = fixed.P(0, int(line))
	f.drawer.DrawString(text)

	fmt.Println("Font texture size W:", width, "H:", height)
	tx := CreateTexture(int32(width), int32(height))
	tx.Buffer(rgba)
	return tx
}
开发者ID:johanhenriksson,项目名称:goworld,代码行数:21,代码来源:font.go


示例14: TestCharAtFailure

func TestCharAtFailure(t *testing.T) {
	f := truetype.NewFace(clearSans, nil)
	defer f.Close()

	c := NewReader(strings.NewReader("Hello World!\n"),
		Style{Offset: 0, Face: f, Foreground: image.Black, Background: image.White},
	)

	view, err := Render(c, NewNaturalLayout(fixed.P(1, 1)))

	if err != nil {
		t.Error(err)
		return
	}

	char, bounds, ok := view.CharAt(fixed.Point26_6{}, LeftToRight)

	if char != (Char{}) || bounds != (fixed.Rectangle26_6{}) || ok {
		t.Error("not char should have been found at (0, 0) but we got", char, bounds, ok)
	}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:21,代码来源:view_test.go


示例15: drawText

func (app *App) drawText(img draw.Image, metrics *battery.Metrics, f battery.MetricFormatter) error {
	// measure the text so that it can be centered within the text area.  if f
	// is a MaxMetricFormatter use it's MaxFormattedWidth method to determine
	// the appropriate centering position so that a change in metric values
	// (but not formatter) will have a smooth transition in the ui.
	app.font.Dst = img
	text := f.Format(metrics)
	measuretext := text
	if fmax, ok := f.(battery.MaxMetricFormatter); ok {
		measuretext = fmax.MaxFormattedWidth()
	}
	xoffset := app.font.MeasureString(measuretext)
	ttwidth := int(xoffset >> 6)
	ttheight := int(app.tt.PointToFixed(app.Layout.fontSize) >> 6)
	padleft := (app.Layout.textRect.Size().X - ttwidth) / 2
	padtop := (app.Layout.textRect.Size().Y - ttheight) / 2
	x := app.Layout.textRect.Min.X + padleft
	y := app.Layout.textRect.Max.Y - padtop
	app.font.Dot = fixed.P(x, y)
	app.font.DrawString(text)
	return nil
}
开发者ID:bmatsuo,项目名称:dockapp-go,代码行数:22,代码来源:main.go


示例16: parseFont

func parseFont() error {
	f, err := ebitenutil.OpenFile("_resources/fonts/mplus-1p-regular.ttf")
	if err != nil {
		return err
	}
	defer func() {
		_ = f.Close()
	}()
	b, err := ioutil.ReadAll(f)
	if err != nil {
		return err
	}
	tt, err := truetype.Parse(b)
	if err != nil {
		return err
	}
	w, h := textImage.Size()
	dst := image.NewRGBA(image.Rect(0, 0, w, h))
	const size = 24
	const dpi = 72
	d := &font.Drawer{
		Dst: dst,
		Src: image.White,
		Face: truetype.NewFace(tt, &truetype.Options{
			Size:    size,
			DPI:     dpi,
			Hinting: font.HintingFull,
		}),
	}
	y := size
	for _, s := range text {
		d.Dot = fixed.P(0, y)
		d.DrawString(s)
		y += size
	}
	return textImage.ReplacePixels(dst.Pix)
}
开发者ID:hajimehoshi,项目名称:ebiten,代码行数:37,代码来源:main.go


示例17: loadGlyph

func (atlas *FontAtlas) loadGlyph(r rune) {
	if _, ok := atlas.Rendered[r]; ok {
		return
	}
	atlas.Dirty = true

	glyph := Glyph{}
	glyph.Rune = r

	bounds, advance, _ := atlas.Face.GlyphBounds(r)
	glyph.Bounds = bounds
	glyph.Advance = advance

	width := ceilPx(bounds.Max.X-bounds.Min.X) + glyphPadding*2
	height := ceilPx(bounds.Max.Y-bounds.Min.Y) + glyphPadding*2

	if atlas.CursorX+glyphMargin+width+glyphMargin > atlas.Image.Bounds().Dx() {
		atlas.CursorX = 0
		atlas.CursorY += glyphMargin + atlas.maxGlyphInRow
	}

	x := atlas.CursorX + glyphMargin
	y := atlas.CursorY + glyphMargin

	glyph.Loc = image.Rect(x, y, x+width, y+height)
	glyph.RelLoc = RelBounds(glyph.Loc, atlas.Image.Bounds())

	pt := fixed.P(x+glyphPadding, y+glyphPadding).Sub(bounds.Min)
	atlas.Context.DrawString(string(r), pt)

	if height > atlas.maxGlyphInRow {
		atlas.maxGlyphInRow = height
	}
	atlas.CursorX += glyphMargin + width + glyphMargin

	atlas.Rendered[r] = glyph
}
开发者ID:egonelbre,项目名称:spector,代码行数:37,代码来源:fontatlas.go


示例18: Draw

func (atlas *FontAtlas) Draw(text string, b Bounds) {
	m := atlas.Face.Metrics()
	w := pow2(font.MeasureString(atlas.Face, text).Ceil())
	h := pow2(m.Ascent.Ceil() + m.Descent.Ceil())
	if w > 2048 {
		w = 2048
	}
	if h > 2048 {
		h = 2048
	}
	b.Max.X = b.Min.X + float32(w)
	b.Max.Y = b.Min.Y + float32(h)

	rendered := image.NewRGBA(image.Rect(0, 0, w, h))
	drawer := font.Drawer{
		Dst:  rendered,
		Src:  image.Black,
		Face: atlas.Face,
	}
	drawer.Dot = fixed.P(0, m.Ascent.Ceil())
	drawer.DrawString(text)

	atlas.draw(rendered, b)
}
开发者ID:egonelbre,项目名称:spector,代码行数:24,代码来源:fontatlas_slow.go


示例19: main

func main() {
	flag.Parse()

	if *flagFontfile == "" || *flagOutdir == "" || *flagPkgname == "" {
		flag.Usage()
		return
	}

	if *flagScale < 1 {
		log.Println("scale must be >= 1")
		return
	}

	bin, err := ioutil.ReadFile(*flagFontfile)
	if err != nil {
		log.Println(err)
		return
	}
	f, err := truetype.Parse(bin)
	if err != nil {
		log.Println(err)
		return
	}

	sdf := NewSDF(*flagTSize, *flagFSize, *flagPad, *flagScale)
	d := &font.Drawer{
		Dst: sdf.src,
		Src: image.Black,
		Face: truetype.NewFace(f, &truetype.Options{
			Size:    sdf.fsize,
			Hinting: font.HintingNone,
		}),
	}

	var glyphs []*glyph
	if *flagAscii {
		glyphs = fromString(ascii, d.Face)
	} else {
		glyphs = enumerate(f, d.Face)
	}
	if len(glyphs) == 0 {
		log.Fatalf("sdf: failed to enumerate glyphs from %s\n", *flagFontfile)
	}
	if a := area(glyphs, sdf.pad); a > sdf.tsize*sdf.tsize {
		asq := math.Sqrt(float64(a))
		log.Fatalf("sdf: glyphs area %[1]v ~= %.2[2]fx%.2[2]f greater than texture area %[3]vx%[3]v\n", a, asq, sdf.tsize)
	}
	sort.Sort(byHeight(glyphs))

	x, y, dy := 0, 0, glyphs[0].height()+sdf.pad*2
	var wg sync.WaitGroup
	for _, g := range glyphs {
		adx, ady := g.width()+sdf.pad*2, g.height()+sdf.pad*2
		if x+adx > sdf.tsize {
			x = 0
			y += dy
			dy = ady
		}

		g.tc = [4]float32{
			float32(x+sdf.pad) / float32(sdf.tsize),
			float32(y+sdf.pad) / float32(sdf.tsize),
			float32(g.width()) / float32(sdf.tsize),
			float32(g.height()) / float32(sdf.tsize),
		}

		d.Dot = fixed.P(x+sdf.pad-int(g.b.Min.X>>6), y+sdf.pad-g.b.Min.Y.Ceil())
		d.DrawString(string(g.r))

		wg.Add(1)
		go func(m image.Image) {
			sdf.calc(m)
			wg.Done()
		}(sdf.src.SubImage(image.Rect(x, y, x+adx, y+ady)))

		x += adx
	}
	wg.Wait()

	sdf.writeSrc()
	sdf.writeDst()
	sdf.writeOut()

	// generate source file to accompany out.png
	buf := new(bytes.Buffer)
	buf.WriteString("// generated by gen.go; DO NOT EDIT\n")
	fmt.Fprintf(buf, "package %s\n\n", *flagPkgname)

	ascent := float32(d.Face.Metrics().Ascent.Ceil())
	descent := float32(d.Face.Metrics().Descent.Floor())
	scale := float32(sdf.fsize) / (ascent + descent)
	fmt.Fprintf(buf, "const AscentUnit = %v\n", (ascent*scale)/float32(sdf.fsize))
	fmt.Fprintf(buf, "const DescentUnit = %v\n", (descent*scale)/float32(sdf.fsize))
	fmt.Fprintf(buf, "const TextureSize = %v\n", *flagTSize)
	fmt.Fprintf(buf, "const FontSize = %v\n", *flagFSize)
	fmt.Fprintf(buf, "const Pad = %v\n\n", *flagPad)

	buf.WriteString("var Texcoords = map[rune][4]float32{\n")
	for _, g := range glyphs {
		s := string(g.r)
//.........这里部分代码省略.........
开发者ID:dskinner,项目名称:material,代码行数:101,代码来源:gen.go


示例20: ExampleParseFont

func ExampleParseFont() {
	readFile := func(name string) ([]byte, error) {
		return ioutil.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
	}
	fontData, err := readFile("unicode.7x13.font")
	if err != nil {
		log.Fatal(err)
	}
	face, err := plan9font.ParseFont(fontData, readFile)
	if err != nil {
		log.Fatal(err)
	}
	// TODO: derive the ascent from the face's metrics.
	const ascent = 11

	dst := image.NewRGBA(image.Rect(0, 0, 4*7, 13))
	draw.Draw(dst, dst.Bounds(), image.Black, image.Point{}, draw.Src)
	d := &font.Drawer{
		Dst:  dst,
		Src:  image.White,
		Face: face,
		Dot:  fixed.P(0, ascent),
	}
	// Draw:
	// 	- U+0053 LATIN CAPITAL LETTER S
	//	- U+03A3 GREEK CAPITAL LETTER SIGMA
	//	- U+222B INTEGRAL
	//	- U+3055 HIRAGANA LETTER SA
	// The testdata does not contain the CJK subfont files, so U+3055 HIRAGANA
	// LETTER SA (さ) should be rendered as U+FFFD REPLACEMENT CHARACTER (�).
	//
	// The missing subfont file will trigger an "open
	// ../testdata/shinonome/k12.3000: no such file or directory" log message.
	// This is expected and can be ignored.
	d.DrawString("SΣ∫さ")

	// Convert the dst image to ASCII art.
	var out []byte
	b := dst.Bounds()
	for y := b.Min.Y; y < b.Max.Y; y++ {
		out = append(out, '0'+byte(y%10), ' ')
		for x := b.Min.X; x < b.Max.X; x++ {
			if dst.RGBAAt(x, y).R > 0 {
				out = append(out, 'X')
			} else {
				out = append(out, '.')
			}
		}
		// Highlight the last row before the baseline. Glyphs like 'S' without
		// descenders should not affect any pixels whose Y coordinate is >= the
		// baseline.
		if y == ascent-1 {
			out = append(out, '_')
		}
		out = append(out, '\n')
	}
	os.Stdout.Write(out)

	// Output:
	// 0 ..................X.........
	// 1 .................X.X........
	// 2 .XXXX..XXXXXX....X.....XXX..
	// 3 X....X.X.........X....XX.XX.
	// 4 X.......X........X....X.X.X.
	// 5 X........X.......X....XXX.X.
	// 6 .XXXX.....X......X....XX.XX.
	// 7 .....X...X.......X....XX.XX.
	// 8 .....X..X........X....XXXXX.
	// 9 X....X.X.........X....XX.XX.
	// 0 .XXXX..XXXXXX....X.....XXX.._
	// 1 ...............X.X..........
	// 2 ................X...........
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:73,代码来源:example_test.go



注:本文中的golang.org/x/image/math/fixed.P函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang fixed.Point26_6类代码示例发布时间:2022-05-28
下一篇:
Golang fixed.Int26_6函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap