예제 #1
0
func (si *subimage) At(x, y int) color.Color {
	p := image.Point{x + si.bounds.Min.X, y + si.bounds.Min.Y}
	if !p.In(si.Bounds()) {
		return color.Black
	}
	return si.Image.At(p.X, p.Y)
}
예제 #2
0
func (si *subimage) Set(x, y int, c color.Color) {
	p := image.Point{x, y}
	if !p.In(si.Bounds()) {
		return
	}
	si.Image.Set(x, y, c)
}
예제 #3
0
파일: main.go 프로젝트: hemaolong/Rabbit
func parseImgBoundary(img image.Image) {
	minX, maxX := img.Bounds().Min.X, img.Bounds().Max.X
	minY, maxY := img.Bounds().Min.Y, img.Bounds().Max.Y
	for i := minX; i < maxX; i++ {
		for j := minY; j < maxY; j++ {
			_, _, _, a := img.At(i, j).RGBA()
			if a != 0 {
				if boundary.Empty() && boundary.Min.X == -1 {
					boundary = image.Rect(i, j, i, j)
				} else {
					_p := image.Point{i, j}
					if !_p.In(boundary) {
						boundary = boundary.Union(image.Rect(i, j, i, j))
					}
				}
			}
		}
	}

	// Should Make the midline of boundary and the img
	l := boundary.Min.X
	r := imageW - boundary.Max.X
	if l > r {
		boundary.Min.X = r
	} else if l < r {
		boundary.Max.X = imageW - l
	}
}
예제 #4
0
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)
	}
}
예제 #5
0
func (si *subimage) At(x, y int) color.Color {
	p := image.Point{x, y}
	if !p.In(si.Bounds()) {
		return color.Black
	}
	return si.Image.At(x, y)
}
예제 #6
0
func (d *dimensionChanger) At(x, y int) color.Color {
	p := image.Point{x, y}
	if !p.In(d.bounds) {
		return nil
	}
	return d.Image.At(x*d.pixel.Dx()+d.Image.Bounds().Canon().Min.X, y*d.pixel.Dy()+d.Image.Bounds().Canon().Min.Y)
}
예제 #7
0
func (d *dimensionChanger) Set(x, y int, c color.Color) {
	p := image.Point{x, y}
	if !p.In(d.bounds) {
		return
	}
	draw.Draw(d.Image, d.pixel.Add(image.Point{x * d.pixel.Dx(), y * d.pixel.Dy()}).Add(d.Image.Bounds().Canon().Min), &image.Uniform{c}, image.Point{0, 0}, draw.Over)
}
예제 #8
0
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)
	}
}
예제 #9
0
func (si *subimage) Set(x, y int, c color.Color) {
	p := image.Point{x + si.bounds.Min.X, y + si.bounds.Min.Y}
	if !p.In(si.Bounds()) {
		return
	}
	si.Image.Set(p.X, p.Y, c)
}
예제 #10
0
func addPortal(p image.Point) {
	for _, portal := range portals {
		if p.In(portal) {
			return
		}
	}
	portals = append(portals, image.Rect(p.X-7, p.Y, p.X+9, p.Y+16))
}
예제 #11
0
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}
}
예제 #12
0
파일: text.go 프로젝트: MobRulesGames/glop
func (p *packedImage) At(x, y int) color.Color {
	point := image.Point{x, y}
	for i := range p.ims {
		if point.In(p.ims[i].Bounds().Add(p.off[i])) {
			return p.ims[i].At(x-p.off[i].X, y-p.off[i].Y)
		}
	}
	return transparent{}
}
예제 #13
0
파일: pixlist.go 프로젝트: js-arias/jdh
// At returns the value of the indicated point.
func (p *PixList) At(pt image.Point) int {
	if !pt.In(p.Rect) {
		return 0
	}
	for _, px := range p.Pixel {
		if px.Eq(pt) {
			return px.Value
		}
	}
	return 0
}
예제 #14
0
파일: view.go 프로젝트: james4k/exp
func (b *Box) hitTest(pt image.Point) *Box {
	if pt.In(b.bounds) {
		for _, k := range b.kids {
			target := k.box().hitTest(pt)
			if target != nil {
				return target
			}
		}
		return b
	}
	return nil
}
예제 #15
0
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()
}
예제 #16
0
func (root *Widget) GetTop(point image.Point) *Widget {
	for _, w := range root.Widgets {
		if w.GetTop(point) != nil {
			return w
		}
	}

	if point.In(root.Rect) {
		return root
	}

	return nil
}
예제 #17
0
파일: run.go 프로젝트: js-arias/sparta
func propagateWheel(w sparta.Widget, pt image.Point) sparta.Widget {
	rect := w.Property(sparta.Geometry).(image.Rectangle)
	childs := w.Property(sparta.Childs)
	if childs == nil {
		return w
	}
	for _, ch := range childs.([]sparta.Widget) {
		rect = ch.Property(sparta.Geometry).(image.Rectangle)
		if pt.In(rect) {
			return propagateWheel(ch, pt.Add(rect.Min))
		}
	}
	return w
}
예제 #18
0
파일: image.go 프로젝트: hanslovsky/dvid
// DataPtr returns a slice of bytes corresponding to the value at point (x,y) in image.
func (img *Image) DataPtr(x, y int32) ([]byte, error) {
	if img == nil {
		return nil, fmt.Errorf("Can't get DataPtr for nil dvid.Image")
	}
	var bytesPerPixel int
	var rect image.Rectangle
	var src []uint8
	var pixOffset func(x, y int) int

	switch img.Which {
	case 0:
		rect = img.Gray.Rect
		bytesPerPixel = 1
		src = img.Gray.Pix
		pixOffset = img.Gray.PixOffset

	case 1:
		rect = img.Gray16.Rect
		bytesPerPixel = 2
		src = img.Gray16.Pix
		pixOffset = img.Gray16.PixOffset

	case 2:
		rect = img.NRGBA.Rect
		bytesPerPixel = 4
		src = img.NRGBA.Pix
		pixOffset = img.NRGBA.PixOffset

	case 3:
		rect = img.NRGBA64.Rect
		bytesPerPixel = 8
		src = img.NRGBA64.Pix
		pixOffset = img.NRGBA64.PixOffset
	}

	pt := image.Point{int(x), int(y)}
	if !pt.In(rect) {
		return nil, fmt.Errorf("Point (%d, %d) not in %d x %d image", x, y, rect.Dx(), rect.Dy())
	}
	pix := make([]uint8, bytesPerPixel)
	i := pixOffset(int(x), int(y))
	copy(pix, src[i:i+bytesPerPixel])
	return pix, nil
}
예제 #19
0
파일: draw.go 프로젝트: rjkroege/acme
func (f *Frame) _tick(pt image.Point, ticked bool) {
	if f.ticked == ticked || f.tick == nil || !pt.In(f.Rect) {
		return
	}

	pt.X -= f.tickscale
	r := image.Rect(pt.X, pt.Y, pt.X+frtickw*f.tickscale, pt.Y+f.Font.Height)

	if r.Max.X > f.Rect.Max.X {
		r.Max.X = f.Rect.Max.X
	}
	if ticked {
		f.tickback.Draw(f.tickback.R, f.Background, nil, pt)
		f.Background.Draw(r, f.tick, nil, image.ZP)
	} else {
		f.Background.Draw(r, f.tickback, nil, image.ZP)
	}
	f.ticked = ticked
}
예제 #20
0
// return true if the map chunk has a cell with coordinates v.X, v.Y
func (mc *MapChunk) HasCell(pt image.Point) bool {
	return pt.In(mc.Rect)
}
예제 #21
0
// check if world tile pt is inside camera bounds c.Rect
// FIXME
func (c *Camera) ContainsWorldPoint(pt image.Point) bool {
	return pt.In(c.Rect)
}
예제 #22
0
파일: logic.go 프로젝트: james4k/exp
func (rectHitTester) HitTest(ctl *Control, pt image.Point) bool {
	return pt.In(ctl.Rect())
}
예제 #23
0
파일: sample.go 프로젝트: jvlmdr/go-cv
func Black(im image.Image, p image.Point) color.Color {
	if p.In(im.Bounds()) {
		return im.At(p.X, p.Y)
	}
	return color.Black
}
예제 #24
0
파일: pixlist.go 프로젝트: js-arias/jdh
// Set sets the value of the indicated point.
func (p *PixList) Set(pt image.Point, val int) {
	if val == 0 {
		if len(p.Pixel) == 0 {
			return
		}
		if !pt.In(p.Rect) {
			return
		}
		isIn := false
		for i, px := range p.Pixel {
			if px.Eq(pt) {
				p.Pixel[i] = p.Pixel[len(p.Pixel)-1]
				p.Pixel[len(p.Pixel)-1] = Pixel{}
				p.Pixel = p.Pixel[:len(p.Pixel)-1]
				isIn = true
				break
			}
		}
		if !isIn {
			return
		}
		if len(p.Pixel) == 0 {
			p.Rect = image.Rectangle{}
			return
		}
		if len(p.Pixel) == 1 {
			p.Rect.Min.X, p.Rect.Min.Y = p.Pixel[0].X, p.Pixel[0].Y
			p.Rect.Max.X, p.Rect.Max.Y = p.Pixel[0].X, p.Pixel[0].Y
			return
		}
		if (pt.X == p.Rect.Min.X) || (pt.X == p.Rect.Max.X) || (pt.Y == p.Rect.Min.Y) || (pt.Y == p.Rect.Max.Y) {
			minX, maxX := p.Rect.Max.X, p.Rect.Min.X
			minY, maxY := p.Rect.Max.Y, p.Rect.Min.Y
			for _, px := range p.Pixel {
				if px.X > maxX {
					maxX = px.X + 1
				}
				if px.X < minX {
					minX = px.X
				}
				if px.Y > maxY {
					maxY = px.Y + 1
				}
				if px.Y < minY {
					minY = px.Y
				}
			}
			p.Rect = image.Rect(minX, minY, maxX, maxY)
		}
		return
	}
	if !pt.In(p.Rect) {
		p.Pixel = append(p.Pixel, Pixel{image.Point{X: pt.X, Y: pt.Y}, val})
		if len(p.Pixel) == 1 {
			p.Rect.Min.X, p.Rect.Min.Y = p.Pixel[0].X, p.Pixel[0].Y
			p.Rect.Max.X, p.Rect.Max.Y = p.Pixel[0].X, p.Pixel[0].Y
			return
		}
		minX, maxX := p.Rect.Max.X, p.Rect.Min.X
		minY, maxY := p.Rect.Max.Y, p.Rect.Min.Y
		for _, px := range p.Pixel {
			if px.X > maxX {
				maxX = px.X + 1
			}
			if px.X < minX {
				minX = px.X
			}
			if px.Y > maxY {
				maxY = px.Y + 1
			}
			if px.Y < minY {
				minY = px.Y
			}
		}
		p.Rect = image.Rect(minX, minY, maxX, maxY)
		return
	}
	for _, px := range p.Pixel {
		if px.Eq(pt) {
			px.Value = val
			return
		}
	}
	p.Pixel = append(p.Pixel, Pixel{image.Point{X: pt.X, Y: pt.Y}, val})
}
예제 #25
0
파일: sample.go 프로젝트: jvlmdr/go-cv
func White(im image.Image, p image.Point) color.Color {
	if p.In(im.Bounds()) {
		return im.At(p.X, p.Y)
	}
	return color.White
}
예제 #26
0
파일: objects.go 프로젝트: zenoss/rog-go
func (obj *ImageItem) HitTest(p image.Point) bool {
	return p.In(obj.R)
}