Esempio n. 1
0
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)
}
Esempio n. 2
0
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)
}
Esempio n. 3
0
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)
	}
}
Esempio n. 4
0
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
}
Esempio n. 5
0
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)
	}
}
Esempio n. 6
0
func undrawpiece() {
	var mask image.Image
	if collider(pos, br.Max) {
		mask = bbmask
	}
	draw.Draw(screen, br.Add(pos), draw.White, mask, bbr.Min)
}
Esempio n. 7
0
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
}
Esempio n. 8
0
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)
}
Esempio n. 9
0
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
}
Esempio n. 10
0
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()
}
Esempio n. 11
0
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
}
Esempio n. 12
0
File: demo.go Progetto: gdey/tinygo
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.")
}
Esempio n. 13
0
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;
        }
    }
}
Esempio n. 14
0
func (cp *ControlPoint) Draw(dst draw.Image, clipr image.Rectangle) {
	r := clipr.Intersect(cp.Bbox())
	draw.Draw(dst, r, cp.col, image.ZP)
}
Esempio n. 15
0
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)
	}
}
Esempio n. 16
0
func randomizeWindow() {
	s := window.Screen()

	colorScaler := 0xFFFF / div / 2

	//Overlay
	totalSide := div * wholes
	st := 600 / totalSide
	boundary := st * div * wholes

	for i := range pic.Pix {
		var setting uint16
		x, y := i%picStride, i/picStride
		if x > boundary || y > boundary {
			pic.Pix[i].Y = 0
		} else {
			x, y = x/st, y/st
			if z := x * y % div; z == 0 {
				setting = 0xFFFF
			} else {
				if nonDivOff {
					setting = 0x0000
				} else {
					setting = uint16(z * colorScaler)
				}
			}
		}
		pic.Pix[i].Y = setting
		/*if x := ((i%pic.Stride * (i / pic.Stride)) % div); x == 0 {
			pic.Pix[i].Y = 0xFFFF
		} else {
			if nonDivOff {
				pic.Pix[i].Y = 0
			} else{
				pic.Pix[i].Y = uint16(x * colorScaler)
			}
		}*/
		//pic.Set(i % pic.Stride, i / pic.Stride, image.Gray16Color{0xFFFF})
	}
	draw.Draw(s, s.Bounds(), pic, image.ZP)

	/*	for i := 0; i < bounds.Dy(); i++ {
				for j := 0; j < bounds.Dx(); j++ {
					var c image.Gray16Color
					if x:= (j * i)%div; x == 0 {
						c = image.Gray16Color{0xFFFF}
					} else {
						if nonDivOff {
							c = image.Gray16Color{0}
						} else {
							c = image.Gray16Color{uint16(x*(0xFFFF/div))}
						}
					}
		//image.GrayColor{uint8(rnd.Intn(256))}
					s.Set(bounds.Min.X + j,
						bounds.Min.Y + i,
						c)
				}
			} */
	window.FlushImage()
}
Esempio n. 17
0
func (inpMazeCell *SMazeCell) draw(inContext draw.Context, inSquareSize int)
{
    vl_screen := inContext.Screen();

    upXLeft, upYLeft := 100, 100;
    squareSize := inSquareSize;

    fullCell := draw.Rect(upXLeft, upYLeft, squareSize + upXLeft, squareSize + upYLeft);
    draw.Draw(vl_screen, fullCell, draw.Black, nil, draw.ZP);

    // inset set the color of the inside
    draw.Draw(vl_screen, fullCell.Inset(1), draw.White, nil, draw.ZP);

    //hide a wall with a rectangle... POOR SOLUTION !!
    if inpMazeCell.northOpen
    {
        // up wall
        hiderup := draw.Rect(upXLeft, upYLeft,
                             upXLeft + squareSize, upYLeft + 1);
        draw.Draw(vl_screen, hiderup, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }

    if inpMazeCell.westOpen
    {
        // right wall
        hiderright := draw.Rect(upXLeft + squareSize - 1, upYLeft,
                                upXLeft + squareSize, upYLeft + squareSize);
        draw.Draw(vl_screen, hiderright, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }

    if inpMazeCell.southOpen
    {
        // down wall
        hiderdown := draw.Rect(upXLeft, upYLeft + squareSize - 1,
                              upXLeft + squareSize, upYLeft + squareSize);
        draw.Draw(vl_screen, hiderdown, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }

    if inpMazeCell.eastOpen
    {
        // left wall
        hiderleft := draw.Rect(upXLeft, upYLeft,
                               upXLeft + 1, upYLeft + squareSize);
        draw.Draw(vl_screen, hiderleft, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }
}