// Fills a rectangle in the specified rgba with the given color. func fillRect(rgba *image.RGBA, rect image.Rectangle, color color.Color) { for x := rect.Min.X; x <= rect.Max.X; x++ { for y := rect.Min.Y; y <= rect.Max.Y; y++ { rgba.Set(x, y, color) } } }
/* * Go-Portierung des unter * http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm * in C beschriebenen Bresenham-Algorithmus zur Darstellung gerasterter * Linien */ func drawLine(img image.RGBA, a, b Point, c image.RGBAColor) { // Go-Portierung des Bresenham-Algoritmus x0, x1, y0, y1 := a.x, b.x, a.y, b.y steep := abs(y1-y0) > abs(x1-x0) if steep { x0, x1, y0, y1 = y0, y1, x0, x1 } if x0 > x1 { x0, y0, x1, y1 = x1, y1, x0, y0 } deltax := x1 - x0 deltay := abs(y1 - y0) error := deltax / 2 y := y0 var ystep int if y0 < y1 { ystep = 1 } else { ystep = -1 } for x := x0; x <= x1; x++ { if steep { img.Set(y, x, c) } else { img.Set(x, y, c) } error = error - deltay if error < 0 { y += ystep error += deltax } } }
func renderWithSupersampling(img *image.RGBA) { const samplings = 4 dy := [samplings]float64{+0.25, +0.25, -0.25, -0.25} dx := [samplings]float64{+0.25, -0.25, +0.25, -0.25} for py := 0; py < height; py++ { for px := 0; px < width; px++ { r, g, b, a := 0, 0, 0, 0 for i := 0; i < samplings; i++ { sy := (dy[i]+float64(py))/height*(ymax-ymin) + ymin sx := (dx[i]+float64(px))/width*(xmax-xmin) + xmin sc := mandelbrot(complex(sx, sy)) mr, mg, mb, ma := sc.RGBA() r += int(mr) g += int(mg) b += int(mb) a += int(ma) } c := color.RGBA{ uint8((r >> 8) / samplings), uint8((g >> 8) / samplings), uint8((b >> 8) / samplings), uint8((a >> 8) / samplings), } img.Set(px, py, c) } } }
// Image builds an image.RGBA type with 6 by 6 quadrants of alternate colors. func Image(m *image.RGBA, key string, colors []color.RGBA) { size := m.Bounds().Size() squares := 6 quad := size.X / squares middle := math.Ceil(float64(squares) / float64(2)) colorMap := make(map[int]color.RGBA) var currentYQuadrand = 0 for y := 0; y < size.Y; y++ { yQuadrant := y / quad if yQuadrant != currentYQuadrand { // when y quadrant changes, clear map colorMap = make(map[int]color.RGBA) currentYQuadrand = yQuadrant } for x := 0; x < size.X; x++ { xQuadrant := x / quad if _, ok := colorMap[xQuadrant]; !ok { if float64(xQuadrant) < middle { colorMap[xQuadrant] = draw.PickColor(key, colors, xQuadrant+3*yQuadrant) } else if xQuadrant < squares { colorMap[xQuadrant] = colorMap[squares-xQuadrant-1] } else { colorMap[xQuadrant] = colorMap[0] } } m.Set(x, y, colorMap[xQuadrant]) } } }
func renderFloat(img *image.RGBA) { var yminF, ymaxMinF, heightF big.Float yminF.SetInt64(ymin) ymaxMinF.SetInt64(ymax - ymin) heightF.SetInt64(height) var xminF, xmaxMinF, widthF big.Float xminF.SetInt64(xmin) xmaxMinF.SetInt64(xmax - xmin) widthF.SetInt64(width) var y, x big.Float for py := int64(0); py < height; py++ { // y := float64(py)/height*(ymax-ymin) + ymin y.SetInt64(py) y.Quo(&y, &heightF) y.Mul(&y, &ymaxMinF) y.Add(&y, &yminF) for px := int64(0); px < width; px++ { // x := float64(px)/width*(xmax-xmin) + xmin x.SetInt64(px) x.Quo(&x, &widthF) x.Mul(&x, &xmaxMinF) x.Add(&x, &xminF) c := mandelbrotFloat(&x, &y) if c == nil { c = color.Black } img.Set(int(px), int(py), c) } } }
func FillColumn(imagem *image.RGBA, x, y int) { preto := color.RGBA{0, 0, 0, 255} for h := y; h <= 513; h++ { imagem.Set(x, h, preto) } }
func calculateTile( yDelta, xDelta float64, py, px int, subsampleF int, img *image.RGBA, algo algos.AlgoFunc, ) { var offset float64 if subsampleF > 1 { offset = 0.5 } yBase := (float64(py)-offset)*yDelta + constants.YMin xBase := (float64(px)-offset)*xDelta + constants.XMin for iY := 0; iY < constants.TileSize; iY++ { for iX := 0; iX < constants.TileSize; iX++ { var blue, red uint8 y := yBase + yDelta*float64(iY) x := xBase + xDelta*float64(iX) if subsampleF > 1 { blue, red = calculateSupersampledPoint(subsampleF, y, x, yDelta, xDelta, algo) } else { blue, red = algo(x, y) } img.Set(px+iX, py+iY, color.YCbCr{128, blue, red}) } } }
func fillpoint(c compl, img *image.RGBA, imagelength, imagewidth float64, fromc, toc compl) { transformedxcoord := int((imagelength * (c.re - fromc.re) / (toc.re - fromc.re))) transformedycoord := int(imagewidth - (imagewidth*(c.im-fromc.im))/(toc.im-fromc.im)) col := colorFromEscapeTime(getEscapeTime(c)) img.Set(transformedxcoord, transformedycoord, col) }
func render(xx, yy int, img *image.RGBA) { defer wg.Done() y := float64(yy)/float64(height)*(ymax-ymin) + ymin x := float64(xx)/float64(width)*(xmax-xmin) + xmin z := complex(x, y) // Image point (px, py) represents complex value z. img.Set(xx, yy, mandelbrot(z)) }
func drawRect(img *image.RGBA, col color.RGBA, x1, y1, x2, y2 int) { for ; x1 <= x2; x1++ { j := y1 for ; j <= y2; j++ { img.Set(x1, j, col) } } }
func echoService(src image.Image, dst image.RGBA) error { orig := src.Bounds() for x := orig.Min.X; x < orig.Max.X; x++ { for y := orig.Min.Y; y < orig.Max.Y; y++ { dst.Set(x, y, src.At(x, y)) } } return nil }
func drawPoint(m *image.RGBA, x float32, y float32) { b := m.Bounds() height := float32(b.Max.Y) width := float32(b.Max.X) scale := float32(height / 11) y = (height - 25) - (scale * y) x = (width / 2) + (scale * x) m.Set(int(x), int(y), color.RGBA{0, 255, 0, 255}) }
func colorize(img *image.RGBA, centroids []*point) { p := point{} for y := img.Rect.Min.Y; y < img.Rect.Max.Y; y++ { for x := img.Rect.Min.X; x < img.Rect.Max.X; x++ { p.x = x p.y = y img.Set(x, y, nearestCentroidColor(p, centroids)) } } }
func renderComplex128(img *image.RGBA) { for py := 0; py < height; py++ { y := float64(py)/height*(ymax-ymin) + ymin for px := 0; px < width; px++ { x := float64(px)/width*(xmax-xmin) + xmin z := complex(x, y) img.Set(px, py, mandelbrotComplex128(z)) } } }
func DrawTopRightPattern(avatar *image.RGBA) { // Mirror top left quadrant to right top quadrant for y := 0; y < AvatarSize; y++ { for x := 0; x < AvatarSize; x++ { if x < AvatarSize/2 { avatar.Set(AvatarSize-x-1, y, avatar.At(x, y)) } } } }
func marker(i *image.RGBA, x, y int) { red := color.RGBA{0xff, 0x00, 0x00, 0xff} n := 15 for xx := x - n; xx <= x+n; xx++ { i.Set(xx, y, red) } for yy := y - n; yy <= y+n; yy++ { i.Set(x, yy, red) } }
func DrawBottomRightPattern(avatar *image.RGBA) { // Mirror bottom left quadrant to right bottom quadrant for y := AvatarSize / 2; y < AvatarSize; y++ { for x := 0; x < AvatarSize; x++ { if x < AvatarSize/2 { avatar.Set(AvatarSize-x-1, y, avatar.At(x, y)) } } } }
// Palette builds an JPEG image with all the colors present in the theme color array. func Palette(m *image.RGBA, theme []color.RGBA) { size := m.Bounds().Size() numColors := len(theme) quadrant := size.X / numColors for x := 0; x < size.X; x++ { currentQuadrant := (x / quadrant) % numColors for y := 0; y < size.Y; y++ { m.Set(x, y, theme[currentQuadrant]) } } }
func Raytracer(scene *Scene, img *image.RGBA) { var c color.RGBA b := img.Bounds() for y := b.Min.Y; y < b.Max.Y; y++ { for x := b.Min.X; x < b.Max.X; x++ { c = calc(x, y) img.Set(x, y, c) } } }
func render(img *image.RGBA) { for py := 0; py < height; py++ { y := float64(py)/height*(ymax-ymin) + ymin for px := 0; px < width; px++ { x := float64(px)/width*(xmax-xmin) + xmin z := complex(x, y) // Image point (px, py) represents complex value z. img.Set(px, py, mandelbrot(z)) } } }
func ApplyToImage(i *image.RGBA, f FilterTripleProvider) { w, h := i.Rect.Max.X, i.Rect.Max.Y filter := Pipeline(16, true, Chain(f, Clamp{0, 1})).GetTriple() for x := 0; x < w; x++ { for y := 0; y < h; y++ { r, g, b, _ := i.At(x, y).RGBA() i.Set(x, y, filter(RGB{float64(r), float64(g), float64(b)}).(RGB)) } } }
// Rotates an image 90deg to the left. func rotate(m image.Image, dst image.RGBA) { orig := m.Bounds() for x := orig.Min.X; x < orig.Max.X; x++ { for y := orig.Min.Y; y < orig.Max.Y; y++ { dst.Set(y, orig.Max.Y-x+1, m.At(x, y)) } } }
func render(xx, yy, w, h int, img *image.RGBA) { defer wg.Done() for py := yy; py < h; py++ { y := float64(py)/float64(height)*(ymax-ymin) + ymin for px := xx; px < w; px++ { x := float64(px)/float64(width)*(xmax-xmin) + xmin z := complex(x, y) // Image point (px, py) represents complex value z. img.Set(px, py, mandelbrot(z)) } } }
func drawGradient(m image.RGBA) { size := m.Bounds().Size() for x := 0; x < size.X; x++ { for y := 0; y < size.Y; y++ { color := color.RGBA{ uint8(255 * x / size.X), uint8(255 * y / size.Y), 55, 255} m.Set(x, y, color) } } }
//srcImgのsrcRectを dstImgのdstRectにコピ- func clipAfromB(srcImg *image.RGBA, srcRect image.Rectangle, dstImg *image.RGBA, dstRect image.Rectangle) { for x := 0; x < srcRect.Max.X; x++ { for y := 0; y < srcRect.Max.Y; y++ { srcRGBA := srcImg.At(x, y) _, _, _, a := srcRGBA.RGBA() if a == 0 { //0は透明 continue } dstImg.Set(dstRect.Min.X+x, dstRect.Min.Y+y, srcRGBA) } } }
func plot(img *image.RGBA, x, y int, c *color.RGBA) { r0, g0, b0, a0 := img.At(x, y).RGBA() // background color r1, g1, b1, a1 := c.RGBA() // foreground color var alpha0 float64 = float64(a0) / float64(0xff) // background alpha var alpha1 float64 = float64(a1) / float64(0xff) // foreground alpha // resulting colors var r uint8 = uint8(alpha1*float64(r1) + (1.0-alpha1)*float64(r0)) var g uint8 = uint8(alpha1*float64(g1) + (1.0-alpha1)*float64(g0)) var b uint8 = uint8(alpha1*float64(b1) + (1.0-alpha1)*float64(b0)) var a uint8 = uint8(0xff * (alpha1 + alpha0*(1.0-alpha1))) pxl := color.RGBA{r, g, b, a} // resulting pixel img.Set(x, y, pxl) }
func drawCircle(img *image.RGBA, x, y, r float64, c color.Color) { fmt.Printf("drawCircle(x=%f, y=%f, r=%f, c=%v)\n", x, y, r, c) x0 := int(x - r) y0 := int(y - r) x1 := int(x + r) y1 := int(y + r) for cy := y0; cy <= y1; cy++ { for cx := x0; cx <= x1; cx++ { if inside(x, y, r, float64(cx), float64(cy)) { img.Set(cx, cy, c) } } } }
func render(g world, rgba *image.RGBA) error { b := V3d{0, 1, 0} r := rgba.Bounds() w := float64(r.Max.X - r.Min.X) h := float64(r.Max.Y - r.Min.Y) for y := r.Min.Y; y < r.Max.Y; y += 1 { for x := r.Min.X; x < r.Max.X; x += 1 { d := V3d{(float64(x) - w/2) / w, (h/2 - float64(y)) / h, 1} c := trace_ray(g, b, d, 1, g.big, 2) rgba.Set(x, y, &c) } } return nil }
// drawTree is a helper function to draw a quadtree onto an image. Used for // debugging purposes. func drawTree(t *quadtree.Tree, m *image.RGBA, c color.Color) { if t == nil { return } b := t.Extents for x := b.Min.X; x < b.Max.X; x++ { m.Set(x, b.Min.Y, c) } for x := b.Min.X; x < b.Max.X; x++ { m.Set(x, b.Max.Y-1, c) } for y := b.Min.Y; y < b.Max.Y; y++ { m.Set(b.Min.X, y, c) } for y := b.Min.Y; y < b.Max.Y; y++ { m.Set(b.Max.X-1, y, c) } drawTree(t.NorthWest, m, c) drawTree(t.NorthEast, m, c) drawTree(t.SouthWest, m, c) drawTree(t.SouthEast, m, c) }
func flipRGBA(src *image.RGBA) { srcCopy := image.NewRGBA(src.Bounds()) for y := 0; y < src.Bounds().Max.Y-src.Bounds().Min.Y; y++ { for x := 0; x < src.Bounds().Max.X-src.Bounds().Min.X; x++ { srcCopy.Set(x, y, src.At(x, y)) } } for y := 0; y < src.Bounds().Max.Y-src.Bounds().Min.Y; y++ { for x := 0; x < src.Bounds().Max.X-src.Bounds().Min.X; x++ { src.Set(x, y, srcCopy.At(x, (src.Bounds().Max.Y-src.Bounds().Min.Y)-1-y)) } } }