當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Point.Y方法代碼示例

本文整理匯總了Golang中image.Point.Y方法的典型用法代碼示例。如果您正苦於以下問題:Golang Point.Y方法的具體用法?Golang Point.Y怎麽用?Golang Point.Y使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在image.Point的用法示例。


在下文中一共展示了Point.Y方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: imgHandle

// imgHandle serves images of the player's view.
func imgHandle(w http.ResponseWriter, r *http.Request) {
	quality, err := strconv.Atoi(r.FormValue("quality"))
	if err != nil || quality < 0 || quality > 100 {
		quality = 70
	}

	// Center Gopher in view if possible
	gpos := model.Gopher.Pos
	rect := image.Rect(0, 0, ViewWidth, ViewHeight).Add(image.Pt(int(gpos.X)-ViewWidth/2, int(gpos.Y)-ViewHeight/2))

	// But needs correction at the edges of the view (it can't be centered)
	corr := image.Point{}
	if rect.Min.X < 0 {
		corr.X = -rect.Min.X
	}
	if rect.Min.Y < 0 {
		corr.Y = -rect.Min.Y
	}
	if rect.Max.X > model.LabWidth {
		corr.X = model.LabWidth - rect.Max.X
	}
	if rect.Max.Y > model.LabHeight {
		corr.Y = model.LabHeight - rect.Max.Y
	}
	rect = rect.Add(corr)

	model.Mutex.Lock()
	jpeg.Encode(w, model.LabImg.SubImage(rect), &jpeg.Options{quality})
	model.Mutex.Unlock()

	// Store the new view's position:
	Pos = rect.Min
}
開發者ID:fun-alex-alex2006hw,項目名稱:golab,代碼行數:34,代碼來源:handlers.go

示例2: canfit

func canfit(p *Piece) bool {
	var dx = [...]int{0, -1, 1, -2, 2, -3, 3, 4, -4}
	j := N + 1
	if j >= 4 {
		j = p.sz.X
		if j < p.sz.Y {
			j = p.sz.Y
		}
		j = 2*j - 1
	}
	for i := 0; i < j; i++ {
		var z image.Point
		z.X = pos.X + dx[i]*pcsz
		z.Y = pos.Y
		if !collide(z, p) {
			z.Y = pos.Y + pcsz - 1
			if !collide(z, p) {
				undrawpiece()
				pos.X = z.X
				return true
			}
		}
	}
	return false
}
開發者ID:hualet,項目名稱:golang-workspace,代碼行數:25,代碼來源:xs.go

示例3: sourceRectTouchOriginalFromInside

func (self *Image) sourceRectTouchOriginalFromInside(width, height int, horAlign HorAlignment, verAlign VerAlignment) (r image.Rectangle) {
	var offset image.Point
	aspectRatio := float64(width) / float64(height)
	if aspectRatio > self.AspectRatio() {
		// Wider than original
		// so touchOriginalFromInside means
		// that the source rect is as wide as the original
		r.Max.X = self.Width()
		r.Max.Y = int(float64(self.Width()) / aspectRatio)
		switch verAlign {
		case VerCenter:
			offset.Y = (self.Height() - r.Max.Y) / 2
		case Bottom:
			offset.Y = self.Height() - r.Max.Y
		}
	} else {
		// Heigher than original,
		// so touchOriginalFromInside means
		// that the source rect is as high as the original
		r.Max.X = int(float64(self.Height()) * aspectRatio)
		r.Max.Y = self.Height()
		switch horAlign {
		case HorCenter:
			offset.X = (self.Width() - r.Max.X) / 2
		case Right:
			offset.X = self.Width() - r.Max.X
		}
	}
	return r.Add(offset)
}
開發者ID:SohoStudio,項目名稱:go-start,代碼行數:30,代碼來源:image.go

示例4: originTrans

// originTrans translates the origin with respect to the current image and the
// current canvas size. This makes sure we never incorrect position the image.
// (i.e., panning never goes too far, and whenever the canvas is bigger than
// the image, the origin is *always* (0, 0).
func originTrans(pt image.Point, win *window, img *vimage) image.Point {
	// If there's no valid image, then always return (0, 0).
	if img == nil {
		return image.Point{0, 0}
	}

	// Quick aliases.
	ww, wh := win.Geom.Width(), win.Geom.Height()
	dw := img.Bounds().Dx() - ww
	dh := img.Bounds().Dy() - wh

	// Set the allowable range of the origin point of the image.
	// i.e., never less than (0, 0) and never greater than the width/height
	// of the image that isn't viewable at any given point (which is determined
	// by the canvas size).
	pt.X = min(img.Bounds().Min.X+dw, max(pt.X, 0))
	pt.Y = min(img.Bounds().Min.Y+dh, max(pt.Y, 0))

	// Validate origin point. If the width/height of an image is smaller than
	// the canvas width/height, then the image origin cannot change in x/y
	// direction.
	if img.Bounds().Dx() < ww {
		pt.X = 0
	}
	if img.Bounds().Dy() < wh {
		pt.Y = 0
	}

	return pt
}
開發者ID:BurntSushi,項目名稱:imgv,代碼行數:34,代碼來源:canvas.go

示例5: grid

func (f *Frame) grid(p image.Point) image.Point {
	p.Y -= f.Rect.Min.Y
	p.Y -= p.Y % f.Font.Height
	p.Y += f.Rect.Min.Y
	if p.X > f.Rect.Max.X {
		p.X = f.Rect.Max.X
	}
	return p
}
開發者ID:rjkroege,項目名稱:acme,代碼行數:9,代碼來源:ptofchar.go

示例6: main

func main() {
	g = image.NewGray(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
	// off center seed position makes pleasingly asymetrical tree
	g.SetGray(w/3, h/3, color.Gray{frost})
generate:
	for a := 0; a < n; {
		// generate random position for new particle
		rp := image.Point{rand.Intn(w), rand.Intn(h)}
		if g.At(rp.X, rp.Y).(color.Gray).Y == frost {
			// position is already set.  find a nearby free position.
			for {
				rp.X += rand.Intn(3) - 1
				rp.Y += rand.Intn(3) - 1
				// execpt if we run out of bounds, consider the particle lost.
				if !rp.In(g.Rect) {
					continue generate
				}
				if g.At(rp.X, rp.Y).(color.Gray).Y != frost {
					break
				}
			}
		} else {
			// else particle is in free space.  let it wander
			// until it touches tree
			for !hasNeighbor(rp) {
				rp.X += rand.Intn(3) - 1
				rp.Y += rand.Intn(3) - 1
				// but again, if it wanders out of bounds consider it lost.
				if !rp.In(g.Rect) {
					continue generate
				}
			}
		}
		// x, y now specify a free position toucing the tree.
		g.SetGray(rp.X, rp.Y, color.Gray{frost})
		a++
		// progress indicator
		if a%100 == 0 {
			fmt.Println(a, "of", n)
		}
	}
	f, err := os.Create("tree.png")
	if err != nil {
		fmt.Println(err)
		return
	}
	err = png.Encode(f, g)
	if err != nil {
		fmt.Println(err)
	}
	f.Close()
}
開發者ID:travis1230,項目名稱:RosettaCodeData,代碼行數:52,代碼來源:brownian-tree-1.go

示例7: cklinewrap

func (f *Frame) cklinewrap(p *image.Point, b *frbox) {
	if b.Nrune < 0 {
		if b.Minwid > byte(f.Rect.Max.X-p.X) {
			p.X = f.Rect.Min.X
			p.Y += f.Font.Height
		}
	} else {
		if b.Wid > f.Rect.Max.X-p.X {
			p.X = f.Rect.Min.X
			p.Y += f.Font.Height
		}
	}
}
開發者ID:rjkroege,項目名稱:acme,代碼行數:13,代碼來源:util.go

示例8: warp

func warp(p image.Point, x int) int {
	if !suspended && piece != nil {
		x = pos.X + piece.sz.X*pcsz/2
		if p.Y < rboard.Min.Y {
			p.Y = rboard.Min.Y
		}
		if p.Y >= rboard.Max.Y {
			p.Y = rboard.Max.Y - 1
		}
		//mousectl.MoveTo(image.Pt(x, p.Y))
	}
	return x
}
開發者ID:hualet,項目名稱:golang-workspace,代碼行數:13,代碼來源:xs.go

示例9: collide

func collide(pt image.Point, p *Piece) bool {
	pt.X = (pt.X - rboard.Min.X) / pcsz
	pt.Y = (pt.Y - rboard.Min.Y) / pcsz
	for _, q := range p.d {
		pt.X += q.X
		pt.Y += q.Y
		if pt.X < 0 || pt.X >= NX || pt.Y < 0 || pt.Y >= NY {
			return true
		}
		if board[pt.Y][pt.X] != 0 {
			return true
		}
	}
	return false
}
開發者ID:hualet,項目名稱:golang-workspace,代碼行數:15,代碼來源:xs.go

示例10: _draw

func (f *Frame) _draw(pt image.Point) image.Point {
	for nb := 0; nb < f.nbox; nb++ {
		b := f.box[nb]
		f.cklinewrap0(&pt, b)
		if pt.Y == f.Rect.Max.Y {
			f.nchars -= f.strlen(nb)
			f.delbox(nb, f.nbox-1)
			break
		}

		if b.Nrune > 0 {
			n, fits := f.canfit(pt, b)
			if !fits {
				break
			}
			if n != b.Nrune {
				f.splitbox(uint64(nb), uint64(n))
				b = f.box[nb]
			}
			pt.X += b.Wid
		} else {
			if b.Bc == '\n' {
				pt.X = f.Rect.Min.X
				pt.Y += f.Font.Height
			} else {
				pt.X += f.newwid(pt, b)
			}
		}
	}
	return pt
}
開發者ID:rjkroege,項目名稱:acme,代碼行數:31,代碼來源:draw.go

示例11: main

func main() {
	bounds := image.Rect(0, 0, 100, 100)
	im := image.NewGray(bounds)
	gBlack := color.Gray{0}
	gWhite := color.Gray{255}
	draw.Draw(im, bounds, image.NewUniform(gWhite), image.ZP, draw.Src)
	pos := image.Point{50, 50}
	dir := up
	for pos.In(bounds) {
		switch im.At(pos.X, pos.Y).(color.Gray).Y {
		case gBlack.Y:
			im.SetGray(pos.X, pos.Y, gWhite)
			dir--
		case gWhite.Y:
			im.SetGray(pos.X, pos.Y, gBlack)
			dir++
		}
		if dir&1 == 1 {
			pos.X += 1 - dir&2
		} else {
			pos.Y -= 1 - dir&2
		}
	}
	f, err := os.Create("ant.png")
	if err != nil {
		fmt.Println(err)
		return
	}
	if err = png.Encode(f, im); err != nil {
		fmt.Println(err)
	}
	if err = f.Close(); err != nil {
		fmt.Println(err)
	}
}
開發者ID:travis1230,項目名稱:RosettaCodeData,代碼行數:35,代碼來源:langtons-ant.go

示例12: clamp

// Clamp a bound to inside the given bounds
func clamp(point image.Point, bounds image.Rectangle) image.Point {
	if point.X < bounds.Min.X {
		point.X = bounds.Min.X
	}
	if point.X >= bounds.Max.X {
		point.X -= bounds.Max.X - 1
	}
	if point.Y < bounds.Min.Y {
		point.Y = bounds.Min.Y
	}
	if point.Y >= bounds.Max.Y {
		point.Y = bounds.Max.Y - 1
	}

	return point
}
開發者ID:kvanbiesen,項目名稱:gocupi,代碼行數:17,代碼來源:image.go

示例13: anchor

func anchor(r image.Rectangle, flags Anchor, p image.Point) image.Rectangle {
	var dp image.Point
	switch flags & (E | W) {
	case E:
		dp.X = r.Dx()
	case E | W, 0:
		dp.X = r.Dx() / 2
	}
	switch flags & (N | S) {
	case S:
		dp.Y = r.Dy()
	case S | N, 0:
		dp.Y = r.Dy() / 2
	}
	return r.Add(p.Sub(r.Min).Sub(dp))
}
開發者ID:zenoss,項目名稱:rog-go,代碼行數:16,代碼來源:text.go

示例14: Thumbnail

// Thumbnail scales and crops src so it fits in dst.
func Thumbnail(dst draw.Image, src image.Image) error {
	// Scale down src in the dimension that is closer to dst.
	sb := src.Bounds()
	db := dst.Bounds()
	rx := float64(sb.Dx()) / float64(db.Dx())
	ry := float64(sb.Dy()) / float64(db.Dy())
	var b image.Rectangle
	if rx < ry {
		b = image.Rect(0, 0, db.Dx(), int(float64(sb.Dy())/rx))
	} else {
		b = image.Rect(0, 0, int(float64(sb.Dx())/ry), db.Dy())
	}

	buf := image.NewRGBA(b)
	if err := Scale(buf, src); err != nil {
		return err
	}

	// Crop.
	// TODO(crawshaw): improve on center-alignment.
	var pt image.Point
	if rx < ry {
		pt.Y = (b.Dy() - db.Dy()) / 2
	} else {
		pt.X = (b.Dx() - db.Dx()) / 2
	}
	draw.Draw(dst, db, buf, pt, draw.Src)
	return nil
}
開發者ID:sandbreaker,項目名稱:graphics-go,代碼行數:30,代碼來源:thumbnail.go

示例15: advance

func (f *Frame) advance(p *image.Point, b *frbox) {
	if b.Nrune < 0 && b.Bc == '\n' {
		p.X = f.Rect.Min.X
		p.Y += f.Font.Height
	} else {
		p.X += b.Wid
	}
}
開發者ID:rjkroege,項目名稱:acme,代碼行數:8,代碼來源:util.go


注:本文中的image.Point.Y方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。