// computeFrame computes next frame minimal changes and returns them.
computeFrame computes next frame minimal changes and returns them.
// computeFrame computes next frame minimal changes and returns them .
func (app *App) computeFrame(gd Grid, exposed bool) Frame {
	if gd.Ug == nil || gd.Rg.Empty() && !exposed {
		return Frame{}
	}
	if app.grid.Ug == nil {
		app.grid = NewGrid(gd.Ug.Width, gd.Ug.Height)
		app.frame.Width = gd.Ug.Width
		app.frame.Height = gd.Ug.Height
	} else if app.grid.Ug.Width != gd.Ug.Width || app.grid.Ug.Height != gd.Ug.Height {
		app.grid = app.grid.Resize(gd.Ug.Width, gd.Ug.Height)
		app.frame.Width = gd.Ug.Width
		app.frame.Height = gd.Ug.Height
	}
	app.frame.Time = time.Now()
	app.frame.Cells = app.frame.Cells[:0]
	if exposed {
		return app.refresh(gd)
	}
	w := gd.Ug.Width
	cells := gd.Ug.Cells
	pcells := app.grid.Ug.Cells 
	yimax := gd.Rg.Max.Y * w
	for y, yi := 0, gd.Rg.Min.Y*w; yi < yimax; y, yi = y+1, yi+w {
		ximax := yi + gd.Rg.Max.X
		for x, xi := 0, yi+gd.Rg.Min.X; xi < ximax; x, xi = x+1, xi+1 {
			c := cells[xi]
			if c == pcells[xi] {
				continue
			}
			pcells[xi] = c
			p := Point{X: x, Y: y}
			cdraw := FrameCell{Cell: c, P: p}
			app.frame.Cells = append(app.frame.Cells, cdraw)
		}
	}
	return app.frame
}
func ( app * App ) computeFrame ( gd Grid , exposed bool ) Frame { if gd . Ug == nil || gd . Rg . Empty ( ) && ! exposed { return Frame { } } if app . grid . Ug == nil { app . grid = NewGrid ( gd . Ug . Width , gd . Ug . Height ) app . frame . Width = gd . Ug . Width app . frame . Height = gd . Ug . Height } else if app . grid . Ug . Width != gd . Ug . Width || app . grid . Ug . Height != gd . Ug . Height { app . grid = app . grid . Resize ( gd . Ug . Width , gd . Ug . Height ) app . frame . Width = gd . Ug . Width app . frame . Height = gd . Ug . Height } app . frame . Time = time . Now ( ) app . frame . Cells = app . frame . Cells [ : 0 ] if exposed { return app . refresh ( gd ) } w := gd . Ug . Width cells := gd . Ug . Cells pcells := app . grid . Ug . Cells yimax := gd . Rg . Max . Y * w for y , yi := 0 , gd . Rg . Min . Y * w ; yi < yimax ; y , yi = y + 1 , yi + w { ximax := yi + gd . Rg . Max . X for x , xi := 0 , yi + gd . Rg . Min . X ; xi < ximax ; x , xi = x + 1 , xi + 1 { c := cells [ xi ] if c == pcells [ xi ] { continue } pcells [ xi ] = c p := Point { X : x , Y : y } cdraw := FrameCell { Cell : c , P : p } app . frame . Cells = append ( app . frame . Cells , cdraw ) } } return app . frame }
computeFrame computes next frame minimal changes and returns them.
computeFrame computes next frame minimal changes and returns them .
// previous cells