本文整理匯總了Golang中image.RGBA.SetRGBA方法的典型用法代碼示例。如果您正苦於以下問題:Golang RGBA.SetRGBA方法的具體用法?Golang RGBA.SetRGBA怎麽用?Golang RGBA.SetRGBA使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類image.RGBA
的用法示例。
在下文中一共展示了RGBA.SetRGBA方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: polygon
// Polygon.
func (avatar *Avatar) polygon(img *image.RGBA, points []image.Point, c color.RGBA) {
// For each row
for j := 0; j <= avatar.Y; j++ {
// Build the list of Xs at which the row crosses a polygon edge
intersect := make([]int, 0, len(points))
adj := len(points) - 1
for i, p := range points {
q := points[adj]
if (j > p.Y && j <= q.Y) || (j > q.Y && j <= p.Y) {
x := int(float64(p.X) + (float64(j)-float64(p.Y))/(float64(q.Y)-float64(p.Y))*(float64(q.X)-float64(p.X)))
intersect = append(intersect, x)
}
adj = i
}
// Sort the list f Xs
sort.Ints(intersect)
// Fill the pixels between node pairs
for i := 0; i < len(intersect); i += 2 {
for k := intersect[i]; k < intersect[i+1]; k++ {
img.SetRGBA(k, j, c)
}
}
}
}
示例2: PaintBG
func PaintBG(avatar *image.RGBA, bgColor color.RGBA) {
for y := 0; y < AvatarSize; y++ {
for x := 0; x < AvatarSize; x++ {
avatar.SetRGBA(x, y, bgColor)
}
}
}
示例3: rectangle
// Rectangle.
func rectangle(img *image.RGBA, rect image.Rectangle, c color.RGBA) {
for i := rect.Min.X; i <= rect.Max.X; i++ {
for j := rect.Min.Y; j <= rect.Max.Y; j++ {
img.SetRGBA(i, j, c)
}
}
}
示例4: gradient
// Gradient.
func gradient(img *image.RGBA, from, to color.RGBA, x, y int, horizontal bool) {
s := [3]float32{
(float32(to.R) - float32(from.R)) / float32(x),
(float32(to.G) - float32(from.G)) / float32(x),
(float32(to.B) - float32(from.B)) / float32(x),
}
for i := 0; i < x; i++ {
for j := 0; j < y; j++ {
a, b := i, j
if horizontal {
a, b = j, i
}
img.SetRGBA(
a,
b,
color.RGBA{
uint8(float32(from.R) + float32(i)*s[0]),
uint8(float32(from.G) + float32(i)*s[1]),
uint8(float32(from.B) + float32(i)*s[2]),
255,
})
}
}
}
示例5: fillPixels
func fillPixels(avatar *image.RGBA, x, y int, pixelColor color.RGBA) {
for i := x; i < x+PixelSize; i++ {
for j := y; j < y+PixelSize; j++ {
avatar.SetRGBA(i, j, pixelColor)
}
}
}
示例6: drawGradient
func drawGradient(m *image.RGBA) {
b := m.Bounds()
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
if x%64 == 0 || y%64 == 0 {
m.SetRGBA(x, y, color.RGBA{0xff, 0xff, 0xff, 0xff})
} else if x%64 == 63 || y%64 == 63 {
m.SetRGBA(x, y, color.RGBA{0x00, 0x00, 0xff, 0xff})
} else {
m.SetRGBA(x, y, color.RGBA{uint8(x), uint8(y), 0x00, 0xff})
}
}
}
// Round off the corners.
const radius = 64
lox := b.Min.X + radius - 1
loy := b.Min.Y + radius - 1
hix := b.Max.X - radius
hiy := b.Max.Y - radius
for y := 0; y < radius; y++ {
for x := 0; x < radius; x++ {
if x*x+y*y <= radius*radius {
continue
}
m.SetRGBA(lox-x, loy-y, color.RGBA{})
m.SetRGBA(hix+x, loy-y, color.RGBA{})
m.SetRGBA(lox-x, hiy+y, color.RGBA{})
m.SetRGBA(hix+x, hiy+y, color.RGBA{})
}
}
}
示例7: connect
/*
draws pixels to connect a line
*/
func (line Line) connect(img *image.RGBA) {
points := line.generatePoints()
black := color.RGBA{0, 0, 0, 255}
for _, val := range points {
img.SetRGBA(val.X, val.Y, black)
}
}
示例8: DrawBasicCircle
//Taken from https://en.wikipedia.org/wiki/Midpoint_circle_algorithm
func DrawBasicCircle(myImage *image.RGBA, x_0, y_0, radius float64, colorGradient ColorGradient, isEdge bool) {
if radius < 0 {
return
}
x := radius
y := float64(0)
decisionOver2 := 1 - x
for y <= x {
for xM := float64(-1); xM < 2; xM += 2 {
for yM := float64(-1); yM < 2; yM += 2 {
if isEdge {
myImage.SetRGBA(int(x_0+x*xM), int(y_0+y*yM), colorGradient.BorderColor())
myImage.SetRGBA(int(x_0+y*xM), int(y_0+x*yM), colorGradient.BorderColor())
} else {
myImage.SetRGBA(int(x_0+x*xM), int(y_0+y*yM), colorGradient.GetColor(uint16(x_0+x*xM), uint16(y_0+y*yM)))
myImage.SetRGBA(int(x_0+y*xM), int(y_0+x*yM), colorGradient.GetColor(uint16(x_0+y*xM), uint16(y_0+x*yM)))
}
}
}
y++
if decisionOver2 <= 0 {
decisionOver2 += 2*y + 1
} else {
x--
decisionOver2 += 2*(y-x) + 1
}
}
}
示例9: drawGradient
func drawGradient(m *image.RGBA) {
b := m.Bounds()
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
m.SetRGBA(x, y, color.RGBA{uint8(x), uint8(y), 0x00, 0xff})
}
}
}
示例10: ellipse
// Ellipse.
func ellipse(img *image.RGBA, center, r image.Point, c color.RGBA) {
for i := center.X - r.X; i <= center.X+r.X; i++ {
for j := center.Y - r.Y; j <= center.Y+r.Y; j++ {
if math.Pow((float64(i)-float64(center.X))/float64(r.X), 2)+math.Pow((float64(j)-float64(center.Y))/float64(r.Y), 2) <= 1.1 {
img.SetRGBA(i, j, c)
}
}
}
}
示例11: circle
// Circle.
func circle(img *image.RGBA, center image.Point, r int, c color.RGBA) {
for i := center.X - r; i <= center.X+r; i++ {
for j := center.Y - r; j <= center.Y+r; j++ {
if math.Pow(float64(i)-float64(center.X), 2)+math.Pow(float64(j)-float64(center.Y), 2) <= math.Pow(float64(r), 2)+float64(r)*0.8 {
img.SetRGBA(i, j, c)
}
}
}
}
示例12: drawCross
func drawCross(m *image.RGBA, x, y int) {
c := color.RGBA{0xff, 0, 0, 0xff} // red
m.SetRGBA(x+0, y-2, c)
m.SetRGBA(x+0, y-1, c)
m.SetRGBA(x-2, y+0, c)
m.SetRGBA(x-1, y+0, c)
m.SetRGBA(x+0, y+0, c)
m.SetRGBA(x+1, y+0, c)
m.SetRGBA(x+2, y+0, c)
m.SetRGBA(x+0, y+1, c)
m.SetRGBA(x+0, y+2, c)
}
示例13: drawGradient
func drawGradient(m *image.RGBA) {
b := m.Bounds()
var scale = (b.Min.X - b.Max.X) / 2
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
if mandelbrot.Mbi(float64(-x-scale), float64(y+scale), float64(scale)) {
m.SetRGBA(x, y, color.RGBA{0xff, 0xff, 0xff, 0xff})
} else {
m.SetRGBA(x, y, color.RGBA{0x00, 0x00, 0xff, 0xff})
}
}
}
}
示例14: line
func line(m *image.RGBA, p, q image.Point, mode int) {
x := 0
y := 0
dx := q.X - p.X
dy := q.Y - p.Y
xsign := +1
ysign := +1
if dx < 0 {
xsign = -1
dx = -dx
}
if dy < 0 {
ysign = -1
dy = -dy
}
pt := func() {
switch mode {
case 0:
for dx := -2; dx <= 2; dx++ {
for dy := -2; dy <= 2; dy++ {
if dy*dx <= -4 || dy*dx >= 4 {
continue
}
m.SetRGBA(p.X+x*xsign+dx, p.Y+y*ysign+dy, color.RGBA{255, 192, 192, 255})
}
}
case 1:
m.SetRGBA(p.X+x*xsign, p.Y+y*ysign, color.RGBA{128, 0, 0, 255})
}
}
if dx > dy {
for x < dx || y < dy {
pt()
x++
if float64(x)*float64(dy)/float64(dx)-float64(y) > 0.5 {
y++
}
}
} else {
for x < dx || y < dy {
pt()
y++
if float64(y)*float64(dx)/float64(dy)-float64(x) > 0.5 {
x++
}
}
}
pt()
}
示例15: PaintItBlack
func PaintItBlack(m *image.RGBA) *image.RGBA {
pt := m.Rect.Size()
black := color.RGBA{
R: 0,
G: 0,
B: 0,
A: 255,
}
for i := 0; i < pt.X; i++ {
for j := 0; j < pt.Y; j++ {
m.SetRGBA(i, j, black)
}
}
return m
}