本文整理汇总了Golang中exp/draw.Draw函数的典型用法代码示例。如果您正苦于以下问题:Golang Draw函数的具体用法?Golang Draw怎么用?Golang Draw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Draw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawsq
func drawsq(b draw.Image, p draw.Point, ptx int) {
var r draw.Rectangle
r.Min = p
r.Max.X = r.Min.X + pcsz
r.Max.Y = r.Min.Y + pcsz
draw.Draw(b, r, draw.Black, nil, draw.ZP)
draw.Draw(b, r.Inset(1), txpix[ptx], nil, draw.ZP)
}
示例2: drawsq
func drawsq(b draw.Image, p image.Point, ptx int) {
var r image.Rectangle
r.Min = p
r.Max.X = r.Min.X + pcsz
r.Max.Y = r.Min.Y + pcsz
draw.Draw(b, r, image.Black, image.ZP)
draw.Draw(b, r.Inset(1), txpix[ptx], image.ZP)
}
示例3: main
func main() {
urls := make(chan string, 4)
imgReady := make(chan *image.Image, 4)
go imagePuller(urls, imgReady)
go urlGen(urls)
xdisp, err := x11.NewWindow()
if err != nil {
log.Exit("X11 error: ", err)
}
screen := xdisp.Screen()
//2010/11/29 16:23:17 one tile is sized (0,0)-(256,256)
//2010/11/29 16:23:17 the screen is sized (0,0)-(800,600)
// log.Print("one tile is sized ", img.Bounds())
// log.Print("the screen is sized ", screen.Bounds())
tileHeight := 256
tileWidth := 256
numTiles := screen.Bounds().Dx()/tileWidth + 2
tileStrip := image.NewRGBA(numTiles*tileWidth, tileHeight)
// pre-load the tile strip
for i := 0; i < numTiles; i++ {
iptr := <-imgReady
img := *iptr
draw.Draw(tileStrip, image.Rect(i*tileWidth, 0, i*tileWidth+tileWidth, tileHeight), img, image.ZP)
}
topBlack := (screen.Bounds().Dy() - tileHeight) / 2
for {
for x := 0; x < tileWidth; x += 15 {
then := time.Nanoseconds()
draw.Draw(screen, image.Rect(0, topBlack, screen.Bounds().Dx(), topBlack+tileHeight), tileStrip, image.Pt(x, 0))
now := time.Nanoseconds()
frameTime := now - then
// a flush is just a write on a channel, so it takes negligible time
xdisp.FlushImage()
toSleep := 0.1*1e9 - frameTime
// log.Print("Took ", frameTime, " ns to draw, will sleep ", toSleep, " ns")
time.Sleep(toSleep)
processEvent(xdisp.EventChan())
}
// shift tiles in tileStrip and put in new last one
draw.Draw(tileStrip, image.Rect(0, 0, (numTiles-1)*tileWidth, tileHeight), tileStrip, image.Pt(tileWidth, 0))
iptr := <-imgReady
img := *iptr
draw.Draw(tileStrip, image.Rect((numTiles-1)*tileWidth, 0, numTiles*tileWidth, tileHeight), img, image.ZP)
}
}
示例4: horiz
func horiz() bool {
var lev [MAXN]int
h := 0
for i := 0; i < NY; i++ {
for j := 0; board[i][j] != 0; j++ {
if j == NX-1 {
lev[h] = i
h++
break
}
}
}
if h == 0 {
return false
}
r := rboard
newscreen = false
for j := 0; j < h; j++ {
r.Min.Y = rboard.Min.Y + lev[j]*pcsz
r.Max.Y = r.Min.Y + pcsz
draw.Draw(screen, r, draw.White, whitemask, draw.ZP)
display.FlushImage()
}
PlaySound(whoosh)
for i := 0; i < 3; i++ {
pause(250)
if newscreen {
drawboard()
break
}
for j := 0; j < h; j++ {
r.Min.Y = rboard.Min.Y + lev[j]*pcsz
r.Max.Y = r.Min.Y + pcsz
draw.Draw(screen, r, draw.White, whitemask, draw.ZP)
}
display.FlushImage()
}
r = rboard
for j := 0; j < h; j++ {
i := NY - lev[j] - 1
score(250 + 10*i*i)
r.Min.Y = rboard.Min.Y
r.Max.Y = rboard.Min.Y + lev[j]*pcsz
draw.Draw(screen, r.Add(draw.Pt(0, pcsz)), screen, nil, r.Min)
r.Max.Y = rboard.Min.Y + pcsz
draw.Draw(screen, r, draw.White, nil, draw.ZP)
for k := lev[j] - 1; k >= 0; k-- {
board[k+1] = board[k]
}
board[0] = [NX]byte{}
}
display.FlushImage()
return true
}
示例5: drawboard
func drawboard() {
draw.Border(screen, rboard.Inset(-2), 2, draw.Black, draw.ZP)
draw.Draw(screen, draw.Rect(rboard.Min.X, rboard.Min.Y-2, rboard.Max.X, rboard.Min.Y),
draw.White, nil, draw.ZP)
for i := 0; i < NY; i++ {
for j := 0; j < NX; j++ {
if board[i][j] != 0 {
drawsq(screen, draw.Pt(rboard.Min.X+j*pcsz, rboard.Min.Y+i*pcsz), int(board[i][j]-16))
}
}
}
score(0)
if suspended {
draw.Draw(screen, screenr, draw.White, whitemask, draw.ZP)
}
}
示例6: undrawpiece
func undrawpiece() {
var mask image.Image
if collider(pos, br.Max) {
mask = bbmask
}
draw.Draw(screen, br.Add(pos), draw.White, mask, bbr.Min)
}
示例7: rgba
func rgba(m image.Image) *image.RGBA {
if r, ok := m.(*image.RGBA); ok {
return r
}
b := m.Bounds()
r := image.NewRGBA(b.Dx(), b.Dy())
draw.Draw(r, b, m, image.ZP)
return r
}
示例8: setpiece
func setpiece(p *Piece) {
draw.Draw(bb, bbr, image.White, image.ZP)
draw.Draw(bbmask, bbr, image.Transparent, image.ZP)
br = image.Rect(0, 0, 0, 0)
br2 = br
piece = p
if p == nil {
return
}
var op image.Point
var r image.Rectangle
r.Min = bbr.Min
for i, pt := range p.d {
r.Min.X += pt.X * pcsz
r.Min.Y += pt.Y * pcsz
r.Max.X = r.Min.X + pcsz
r.Max.Y = r.Min.Y + pcsz
if i == 0 {
draw.Draw(bb, r, image.Black, image.ZP)
draw.Draw(bb, r.Inset(1), txpix[piece.tx], image.ZP)
draw.Draw(bbmask, r, image.Opaque, image.ZP)
op = r.Min
} else {
draw.Draw(bb, r, bb, op)
draw.Draw(bbmask, r, bbmask, op)
}
if br.Max.X < r.Max.X {
br.Max.X = r.Max.X
}
if br.Max.Y < r.Max.Y {
br.Max.Y = r.Max.Y
}
}
br.Max = br.Max.Sub(bbr.Min)
delta := image.Pt(0, DY)
br2.Max = br.Max.Add(delta)
r = br.Add(bb2r.Min)
r2 := br2.Add(bb2r.Min)
draw.Draw(bb2, r2, image.White, image.ZP)
draw.Draw(bb2, r.Add(delta), bb, bbr.Min)
draw.Draw(bb2mask, r2, image.Transparent, image.ZP)
draw.DrawMask(bb2mask, r, image.Opaque, bbr.Min, bbmask, image.ZP, draw.Over)
draw.DrawMask(bb2mask, r.Add(delta), image.Opaque, bbr.Min, bbmask, image.ZP, draw.Over)
}
示例9: movepiece
func movepiece() bool {
var mask image.Image
if collide(draw.Pt(pos.X, pos.Y+pcsz), piece) {
return false
}
if collider(pos, br2.Max) {
mask = bb2mask
}
draw.Draw(screen, br2.Add(pos), bb2, mask, bb2r.Min)
pos.Y += DY
display.FlushImage()
return true
}
示例10: redraw
func redraw(new bool) {
// if new && getwindow(display, Refmesg) < 0 {
// sysfatal("can't reattach to window");
// }
r := draw.Rect(0, 0, screen.Width(), screen.Height())
pos.X = (pos.X - rboard.Min.X) / pcsz
pos.Y = (pos.Y - rboard.Min.Y) / pcsz
dx := r.Max.X - r.Min.X
dy := r.Max.Y - r.Min.Y - 2*32
DY = dx / NX
if DY > dy/NY {
DY = dy / NY
}
DY /= 8
if DY > 4 {
DY = 4
}
pcsz = DY * 8
DMOUSE = pcsz / 3
if pcsz < 8 {
log.Exitf("screen too small: %d", pcsz)
}
rboard = screenr
rboard.Min.X += (dx - pcsz*NX) / 2
rboard.Min.Y += (dy-pcsz*NY)/2 + 32
rboard.Max.X = rboard.Min.X + NX*pcsz
rboard.Max.Y = rboard.Min.Y + NY*pcsz
pscore.X = rboard.Min.X + 8
pscore.Y = rboard.Min.Y - 32
// scoresz = stringsize(font, "000000");
pos.X = pos.X*pcsz + rboard.Min.X
pos.Y = pos.Y*pcsz + rboard.Min.Y
bbr = draw.Rect(0, 0, N*pcsz, N*pcsz)
bb = image.NewRGBA(bbr.Max.X, bbr.Max.Y)
bbmask = image.NewRGBA(bbr.Max.X, bbr.Max.Y) // actually just a bitmap
bb2r = draw.Rect(0, 0, N*pcsz, N*pcsz+DY)
bb2 = image.NewRGBA(bb2r.Dx(), bb2r.Dy())
bb2mask = image.NewRGBA(bb2r.Dx(), bb2r.Dy()) // actually just a bitmap
draw.Draw(screen, screenr, draw.White, nil, draw.ZP)
drawboard()
setpiece(piece)
if piece != nil {
drawpiece()
}
lastmx = movemouse()
newscreen = true
display.FlushImage()
}
示例11: NewTile
func NewTile(r draw.Rectangle, calc Fractal, img *image.RGBA, wait bool) *Tile {
t := new(Tile)
t.r = r
t.nrows = 0
if img == nil {
img = image.NewRGBA(image.Rect(0, 0, r.Dx(), r.Dy()))
}
t.calc = calc
t.image = img
if wait {
t.calculate(nil, nil)
t.nrows = img.Height()
} else {
// choose some vaguely appropriate colour
col := calc.At(centre(r))
draw.Draw(t.image, draw.Rect(0, 0, r.Dx(), r.Dy()), image.Uniform{col}, draw.ZP)
}
return t
}
示例12: main
func main() {
//ctxt, err := svga.NewScreen()
//if ctxt == nil {
// log.Exitf("no screen: %v", err)
//}
//screen := ctxt.Screen()
//img := screen.(*image.RGBA)
img := image.NewRGBA(640, 480)
draw.Draw(img, image.Rect(10, 10, 100, 100), image.White, image.ZP)
cr, cg, cb, ca := image.White.RGBA()
println("cr ", cr)
println("cg ", cg)
println("cb ", cb)
println("ca ", ca)
//ctxt.FlushImage()
print("done.")
}
示例13: app
func app(inContext draw.Context)
{
vl_screen := inContext.Screen();
screenr := draw.Rect(0, 0, vl_screen.Width(), vl_screen.Height());
draw.Draw(vl_screen, screenr, draw.White, nil, draw.ZP);
squareSize := 30;
var cell *SMazeCell = new(SMazeCell);
cell.draw(inContext, squareSize);
inContext.FlushImage();
fmt.Printf("Press the any key to exit.\n");
for
{
select
{
case r := <- inContext.KeyboardChan():
switch r
{
case 'q', 'Q', 0x04, 0x7F, 32 :
fmt.Printf("Exiting because of keyboard event %d\n", r);
os.Exit(0);
default :
fmt.Printf("Exiting because of keyboard event %d\n", r);
}
case <- inContext.MouseChan():
// No-op.
case <- inContext.ResizeChan():
// No-op.
case <- inContext.QuitChan():
fmt.Printf("Exiting because of QuitChan\n");
return;
}
}
}
示例14: Draw
func (cp *ControlPoint) Draw(dst draw.Image, clipr image.Rectangle) {
r := clipr.Intersect(cp.Bbox())
draw.Draw(dst, r, cp.col, image.ZP)
}
示例15: drawpiece
func drawpiece() {
draw.Draw(screen, br.Add(pos), bb, bbmask, bbr.Min)
if suspended {
draw.Draw(screen, br.Add(pos), draw.White, whitemask, draw.ZP)
}
}