コード例 #1
0
ファイル: libra.go プロジェクト: karlek/libra
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()
}
コード例 #2
0
ファイル: a.go プロジェクト: karlek/vanilj
// loadResources loads the background and foreground images.
func loadResources() (err error) {
	c := canvas.NewCanvas(width, height)
	for x := 0; x < c.Bounds().Size().X; x++ {
		for y := 0; y < c.Bounds().Size().Y; y++ {
			c.Set(x, y, color.RGBA{0, 0, 0, 255})
		}
	}

	f := fractal.Fractal{
		Src:    c.RGBA,
		Iter:   iterations,
		Center: complex(centerReal, centerImag),
		Zoom:   zoom,
	}
	mandel.Smooth(&f)

	// Load background image.
	fractalImg, err = win.ReadImage(f.Src)
	if err != nil {
		return err
	}
	return nil
}