func (c *chip8) drawGraphics() { gl.MatrixMode(gl.POLYGON) for y := 0; y < 32; y++ { for x := 0; x < 64; x++ { if c.gfx[(y * 64) + x] == 1 { gl.Color3f(1,1,1) } else { gl.Color3f(0,0,0) } gl.Rectf(float32(x), float32(y), float32(x+1), float32(y+1)) } } c.drawFlag = false }
// drawSignal writes the input wave form(s) out to screen. func (s *Screen) drawSignal() { s.eventBuffer.Each(func(index int, value interface{}) { if value != nil { e := value.(Event) gl.Color3f(e.R, e.G, e.B) x := float64(index) * s.pixelsPerSample gl.Begin(gl.LINE_STRIP) gl.Vertex2d(x, -1.0) gl.Vertex2d(x, 1.0) gl.End() } }) for _, l := range s.lines { gl.Color3f(l.R, l.G, l.B) gl.Begin(gl.LINE_STRIP) l.valueBuffer.Each(func(index int, value float64) { gl.Vertex2d(float64(index)*s.pixelsPerSample, value) }) gl.End() } }
// drawSignal writes the input wave form(s) out to screen. func (s *SpectrogramScreen) drawSignal() { s.eventBuffer.Each(func(index int, value interface{}) { if value != nil { e := value.(Event) gl.Color3f(e.R, e.G, e.B) x := float64(index) * s.pixelsPerSample gl.Begin(gl.LINE_STRIP) gl.Vertex2d(x, -1.0) gl.Vertex2d(x, 1.0) gl.End() } }) spacing := 1 gl.PointSize(1.0) gl.Begin(gl.POINTS) s.line.valueBuffer.Each(func(index int, value interface{}) { col := value.([]complex128) for i, v := range col { // p = log(|v|) = [-20, 5], so map to [0, 1] // p := math.Log(cmplx.Abs(v) + 1.e-8) // grey := (p + 20.0) / 25.0 p := cmplx.Abs(v) grey := p / 15.0 if grey > 1.0 { grey = 1.0 } else if grey < 0.0 { grey = 0.0 } // HACK: Stretch to make the darks darker and the whites whiter. // grey = grey * grey * grey * grey // more space at the top, [0, 1] // grey = 2.0 * grey - 1.0 // [-1, 1] // grey = math.Tanh(2.0 * grey) // streched, still [-1, 1] // grey = (grey + 1.0) / 2.0 gl.Color3d(grey, grey, grey) // gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(s.height - 1 - (3 * i + 0))) gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(s.height-1-(spacing*i))) // gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(s.height - 1 - (3 * i + 2))) } gl.Color3ub(255, 0, 0) for i := 1; i < 7; i++ { gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(i*spacing*s.bpo)) } }) gl.End() }