本文整理匯總了Golang中image.Point.Add方法的典型用法代碼示例。如果您正苦於以下問題:Golang Point.Add方法的具體用法?Golang Point.Add怎麽用?Golang Point.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類image.Point
的用法示例。
在下文中一共展示了Point.Add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: drawPoint
func drawPoint(point Point, dst *image.RGBA, src image.Image) {
p := image.Point{point.X, point.Y}
srcRect := src.Bounds()
size := srcRect.Size()
rect := image.Rectangle{p, p.Add(size)}
draw.Draw(dst, rect, src, srcRect.Min, draw.Src)
}
示例2: Set
func (i *imageSlice) Set(x, y int, c color.Color) {
p := image.Point{x, y}
if p.In(i.r) {
p = p.Add(i.p)
i.img.Set(p.X, p.Y, c)
}
}
示例3: verticalPosition
func (l *Label) verticalPosition(line int) {
textHeight := len(l.lines) * l.font.Height()
var topOffset, tail int
switch l.VAlign {
case Top:
topOffset = 0
case Middle:
topOffset = (l.Bounds().Dy() - textHeight) / 2
case Bottom:
topOffset = (l.Bounds().Dy() - textHeight)
}
totalHeight := textHeight + WRAP_GAP
if (textHeight > l.Dy()) && l.scroll {
if l.scrollPos > 0 {
l.scrollPos -= totalHeight
//l.scrollPos %= ( totalHeight + WRAP_GAP )
}
tail = l.scrollPos + totalHeight
if tail <= WRAP_GAP {
// There is only one copy on screen
l.scrollPos = tail
}
topLeft := image.Point{0, topOffset + l.scrollPos + (line * l.font.Height())}
l.graphics[line].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line].Bounds().Size())}
l.graphics[line+len(l.lines)].Rect = l.graphics[line].Rect.Add(image.Point{0, totalHeight})
} else {
topLeft := image.Point{0, topOffset + (line * l.font.Height())}
l.graphics[line].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line].Bounds().Size())}
l.graphics[line+len(l.lines)].Rect = l.graphics[line].Rect
}
}
示例4: RenderMultiline
func (c *Context) RenderMultiline(txt []string, size float64, bg, fg color.Color) (*image.RGBA, error) {
w, h := 0, 0
imgs := []*image.RGBA{}
for _, l := range txt {
i, err := c.Render(l, size, fg)
if err != nil {
return nil, err
}
if i.Bounds().Dx() > w {
w = i.Bounds().Dx()
}
h += i.Bounds().Dy()
imgs = append(imgs, i)
}
dst := image.NewRGBA(image.Rect(0, 0, w, h))
draw.Draw(dst, dst.Bounds(), image.NewUniform(bg), image.ZP, draw.Src)
y := 0
for _, src := range imgs {
sr := src.Bounds()
dp := image.Point{0, y}
r := image.Rectangle{dp, dp.Add(sr.Size())}
draw.Draw(dst, r, src, sr.Min, draw.Src)
y += sr.Dy()
}
return dst, nil
}
示例5: addPixel
func (b *bucket) addPixel(pixel image.Point) {
b.group.wire.pixels = append(b.group.wire.pixels, pixel)
b.group.wire.bounds = b.group.wire.bounds.Union(
image.Rectangle{
pixel,
pixel.Add(image.Point{1, 1})})
}
示例6: Draw
// Draw renders the given cpu cores on img.
func (app *App) Draw(img draw.Image, cpus []CPU) {
rect := img.Bounds()
bg := app.Background
if bg == nil {
bg = image.Black
}
draw.Draw(img, rect, bg, bg.Bounds().Min, draw.Over)
if len(cpus) == 0 {
return
}
cpuDx := rect.Dx() / len(cpus)
ptIncr := image.Point{X: cpuDx}
ptDelta := image.Point{}
rectDx := image.Rectangle{
Min: rect.Min,
Max: rect.Max,
}
rectDx.Max.X = rect.Min.X + cpuDx
for _, cpu := range cpus {
irect := image.Rectangle{
Min: rectDx.Min.Add(ptDelta),
Max: rectDx.Max.Add(ptDelta),
}
subimg := SubImage(img, irect)
app.renderCPU(subimg, cpu)
ptDelta = ptDelta.Add(ptIncr)
}
}
示例7: Adjust
// Adjust adjusts the two images aligning ther centers. The background
// of the smaller image is filled with FillColor. The returned images
// are of the same size.
func (c Centerer) Adjust(img1, img2 image.Image) (image.Image, image.Image) {
img1Rect := img1.Bounds()
img2Rect := img2.Bounds()
backgroundRect := img1Rect.Union(img2Rect)
dstImg1 := image.NewRGBA(backgroundRect)
dstImg2 := image.NewRGBA(backgroundRect)
// Fill destination images with FillColor
draw.Draw(dstImg1, dstImg1.Bounds(), &image.Uniform{c.FillColor}, image.ZP, draw.Src)
draw.Draw(dstImg2, dstImg2.Bounds(), &image.Uniform{c.FillColor}, image.ZP, draw.Src)
// Copy img1 to the center of dstImg1
dp := image.Point{
(backgroundRect.Max.X-backgroundRect.Min.X)/2 - (img1Rect.Max.X-img1Rect.Min.X)/2,
(backgroundRect.Max.Y-backgroundRect.Min.Y)/2 - (img1Rect.Max.Y-img1Rect.Min.Y)/2,
}
r := image.Rectangle{dp, dp.Add(img1Rect.Size())}
draw.Draw(dstImg1, r, img1, image.ZP, draw.Src)
// Copy img2 to the center of dstImg2
dp = image.Point{
(backgroundRect.Max.X-backgroundRect.Min.X)/2 - (img2Rect.Max.X-img2Rect.Min.X)/2,
(backgroundRect.Max.Y-backgroundRect.Min.Y)/2 - (img2Rect.Max.Y-img2Rect.Min.Y)/2,
}
r = image.Rectangle{dp, dp.Add(img2Rect.Size())}
draw.Draw(dstImg2, r, img2, image.ZP, draw.Src)
return dstImg1, dstImg2
}
示例8: At
func (i *imageSlice) At(x, y int) color.Color {
p := image.Point{x, y}
if p.In(i.r) {
p = p.Add(i.p)
return i.img.At(p.X, p.Y)
}
return color.RGBA{0, 0, 0, 0}
}
示例9: NewImage
// Image returns a new Image which will be drawn using img,
// with p giving the coordinate of the image's top left corner.
//
func NewImage(img image.Image, opaque bool, p image.Point) *Image {
obj := new(Image)
obj.Item = &obj.item
r := img.Bounds()
obj.item.R = image.Rectangle{p, p.Add(image.Pt(r.Dx(), r.Dy()))}
obj.item.Image = img
obj.item.IsOpaque = opaque
return obj
}
示例10: hasNeighbor
func hasNeighbor(p image.Point) bool {
for _, n := range n8 {
o := p.Add(n)
if o.In(g.Rect) && g.At(o.X, o.Y).(color.Gray).Y == frost {
return true
}
}
return false
}
示例11: SliceImage
// SliceImage returns an image which is a view onto a portion of img.
// The returned image has the specified width and height,
// but all draw operations are clipped to r.
// The origin of img is aligned with p. Where img
// overlaps with r, it will be used for drawing operations.
//
func SliceImage(width, height int, r image.Rectangle, img draw.Image, p image.Point) draw.Image {
// TODO: detect when img is itself a SliceImage and
// use the underlying image directly.
i := new(imageSlice)
i.img = img
i.r = r.Intersect(image.Rectangle{p, p.Add(img.Bounds().Size())})
//debugp("actual sliced rectangle %v\n", i.r)
i.p = p
return i
}
示例12: Rect
func Rect() {
dst := image.NewRGBA(image.Rect(0, 0, 640, 480))
sr := image.Rect(0, 0, 200, 200)
src := image.Black
dp := image.Point{100, 100}
// RECT OMIT
r := image.Rectangle{dp, dp.Add(sr.Size())}
draw.Draw(dst, r, src, sr.Min, draw.Src)
// STOP OMIT
}
示例13: MinInputSize
func MinInputSize(feat image.Point, conf Config) image.Point {
// One feature pixel on all sides.
feat = feat.Add(image.Pt(2, 2))
// Multiply by cell size to get pixels.
pix := feat.Mul(conf.CellSize)
// Add floor(half a cell) on all sides.
half := conf.CellSize / 2
pix = pix.Add(image.Pt(half, half).Mul(2))
// Leave one pixel to compute derivatives.
pix = pix.Add(image.Pt(1, 1).Mul(2))
return pix
}
示例14: Sprite
func (m *Mob) Sprite(offset image.Point) gfx.Sprite {
// XXX: Hacky way to pass adjust parameter to make big mobs get drawn by
// their frontmost point. Layer is assumed to be a delta, the view system
// will adjust it into the correct Z level.
layer := 0
if m.isBig {
layer += 2 * util.ViewLayersPerZ
}
return gfx.Sprite{
Layer: layer,
Offset: offset.Add(m.bob()),
Drawable: app.Cache().GetDrawable(m.icon)}
}
示例15: MouseDrag
// MouseDrag moves the mouse, clicks, and drags to a new position.
func (v *VNC) MouseDrag(p, d image.Point) error {
if err := v.MouseMove(p); err != nil {
return err
}
if err := v.conn.PointerEvent(vnclib.ButtonLeft, uint16(p.X), uint16(p.Y)); err != nil {
return err
}
p = p.Add(d) // Add delta.
if err := v.conn.PointerEvent(vnclib.ButtonLeft, uint16(p.X), uint16(p.Y)); err != nil {
return err
}
return v.conn.PointerEvent(vnclib.ButtonNone, uint16(p.X), uint16(p.Y))
}