Exemplo n.º 1
0
Arquivo: a.go Projeto: karlek/vanilj
// render renders the background and foreground images onto the window.
func render() (err error) {
	// Draw the entire background image onto the screen starting at the top left
	// point (0, 0).
	dp := image.ZP
	err = win.Draw(dp, fractalImg)
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 2
0
func update(buf audio.PCM32Samples, dec audio.Decoder) error {
	n, err := dec.Read(buf)
	if err != nil {
		return err
	}
	fmt.Println(len(buf), n)
	if n == 0 {
		return errutil.NewNoPos("EOF")
	}

	// The x scale is relative to the number of frames.
	xscale := len(buf) / width

	// The y scale is relative to the range of values from the frames.
	yscale := Range(buf) / height

	i := image.NewRGBA(image.Rect(0, 0, width, height))
	draw.Draw(i, i.Bounds(), &image.Uniform{black}, image.ZP, draw.Src)

	oldx, oldy := 0, height/2
	for x := 0; x < width; x += 2 {
		// loudness from the frame scaled down to the image.
		loudness := int(buf[x*xscale]) / (yscale + 1)

		// To center the oscilloscope on the y axis we add height/2.
		y := loudness + height/2

		// draw a line between (x, y) and (oldx, oldy)
		line(i, x, y, oldx, oldy)

		// Update old x/y.
		oldx, oldy = x, y
	}

	// Change image.Image type to win.Image.
	img, err := win.ReadImage(i)
	if err != nil {
		return errutil.Err(err)
	}
	// Draw image to window.
	err = win.Draw(image.ZP, img)
	if err != nil {
		return errutil.Err(err)
	}

	// Display window updates on screen.
	return win.Update()
}