Exemple #1
0
func saneRectangle(rect image.Rectangle) image.Rectangle {
	rect = rect.Canon()
	width, height := rect.Dx(), rect.Dy()
	if width < 1 || width > 4096 || height < 1 || height > 4096 {
		return image.Rect(0, 0, 16, 16)
	}
	return rect
}
Exemple #2
0
func convertRect(rect image.Rectangle) C.SDL_Rect {
	rect = rect.Canon()
	return C.SDL_Rect{
		C.Sint16(rect.Min.X),
		C.Sint16(rect.Min.Y),
		C.Uint16(rect.Max.X - rect.Min.X),
		C.Uint16(rect.Max.Y - rect.Min.Y),
	}
}
Exemple #3
0
// Draw creates an image of the function in the domain.
func Draw(fnc ColorMap, size image.Rectangle, domain *ComplexRect) image.Image {
	size = size.Canon()
	// Clever vector hack to move the Min corner to 0,0
	size = size.Sub(size.Min)
	// For now, use RGBA as image type
	img := image.NewRGBA(size)
	// max x and y guaranteed to be size of rectangle
	x := size.Dx()
	y := size.Dy()
	dx := domain.dx() / float64(x)
	dy := domain.dy() / float64(y)
	// Get the initial x vals
	base_x := domain.left()
	base_y := domain.bottom()
	for i := 0; i <= x; i++ {
		for j := 0; j <= y; j++ {
			point := complex(base_x+float64(i)*dx, base_y+float64(j)*dy)
			img.Set(i, j, fnc(point))
		}
	}
	return img
}
Exemple #4
0
func DonutCoords(x, y int, r image.Rectangle) (int, int) {
	r = r.Canon()
	x = (int(math.Mod(float64(x), float64(r.Dx())))+r.Dx())%r.Dx() + r.Min.X
	y = (int(math.Mod(float64(y), float64(r.Dy())))+r.Dy())%r.Dy() + r.Min.Y
	return x, y
}
Exemple #5
0
// SubImage extracts a rectangular subset of draw.Image as a separate draw.Image
// with a translated origin to the rectangles canonicalized Min point.
func SubImage(img draw.Image, r image.Rectangle) draw.Image {
	return &subimage{
		Image:  img,
		bounds: img.Bounds().Intersect(r.Canon()),
	}
}