Skip to content
Snippets Groups Projects
Select Git revision
  • a3ca14ffc10e78cd73e537f00167ae91a10eab02
  • main default protected
  • 1.3.0.1
  • 1.3.0.0
4 results

example.m

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    screenplot.go 1.78 KiB
    // For fun.. Plot to the screen
    
    package main
    
    import (
    	"fmt"
    	"image"
    	"image/color"
    	"image/draw"
    	ui "github.com/gizak/termui/v3"
    	"github.com/gizak/termui/v3/widgets"
    )
    
    func breaker(x interface{}) {}
    func scrnPlt(pi, stdErr []float32) error {
    	nrmlStyle := ui.NewStyle (ui.ColorBlack, ui.ColorClear)
    //	invisStyle := ui.NewStyle (ui.ColorClear, ui.ColorClear)
    	thm := ui.Theme
    	thm.Block.Title = nrmlStyle
    	thm.Plot.Axes = ui.ColorBlack
    
    	thm.Default = ui.NewStyle(ui.ColorBlack, ui.ColorClear)
    	thm.Block.Border = nrmlStyle
    
    	ui.Theme = thm
    
    	ptxt := widgets.NewParagraph()
    
    	for i := 0; i < 24; i++ {
    		for j := 0; j < 800; j++ { 
    			ptxt.Text += "."
    		}
    		ptxt.Text += " \n"
    	}
    	
    	ptxt.SetRect(0, 0, 80, 24)
    	ptxt.TextStyle = ui.NewStyle(ui.ColorWhite, ui.ColorWhite)
    	p1 := widgets.NewPlot()
    
    	p1.Title = "π"
    	{
    		data := make([][]float64, 2)
    		data[0] = make([]float64, len(pi))
    		data[1] = make([]float64, len(pi))
    		for i := range pi {
    			data[0][i] = float64(i + 1)
    			data[1][i] = float64(pi[i])
    		}
    		p1.Data = data
    	}
    
    	p1.SetRect(2, 2, 80, 24)
    	p1.Block.TitleStyle = nrmlStyle
    	p1.AxesColor = ui.ColorBlack
    //	p1.LineColors = []ui.Color{ui.ColorBlack, ui.ColorBlack}
    	p1.SetRect (0, 0, 80, 24)
    	p1.Marker = widgets.MarkerBraille
    	p1.PlotType = widgets.ScatterPlot
    	p1.Border = false
    	
    	breaker(thm)
    	
    	m := image.NewRGBA(image.Rect(0, 0, 80, 24))
    
    	//	draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
    	draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
    	img := widgets.NewImage(m)
    	img.SetRect(0, 0, 100, 50)
    
    	defer  fmt.Println ("m bounds", m.Bounds())
    
    	if err := ui.Init(); err != nil {
    		return err
    	}
    
    
    	defer ui.Close()
    
    	ui.Render(img, ptxt, p1)
    	for e := range ui.PollEvents() {
    		if e.Type == ui.KeyboardEvent {
    			break
    		}
    	}
    	return nil
    }