~whereswaldon/chipalee

6b3e445a0a98b7ff43eaab525f9000b49ef8f253 — Chris Waldon 1 year, 9 months ago d2ed91b
main: make pipes different heights

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 14 insertions(+), 3 deletions(-)

M main.go
M main.go => main.go +14 -3
@@ 272,6 272,7 @@ type Pipe struct {
	player  oto.Player
	playing bool
	since   time.Time
	freq    float64
}

func (p *Pipe) Play(now time.Time) {


@@ 363,11 364,18 @@ func run(w *app.Window) error {
							X: int(width),
							Y: gtx.Constraints.Max.Y,
						},
					}.Op()
					}
					lowestFreq := freqs[0]
					for i, pipe := range players {
						if pipe.playing {
							offset := op.Offset(f32.Point{X: width * float32(i)}).Push(gtx.Ops)
							paint.FillShape(gtx.Ops, color.NRGBA{R: 200, A: 100}, rect)
							rect := rect
							proportion := 1 / (pipe.freq / lowestFreq)
							height := int(math.Round(float64(gtx.Constraints.Max.Y) * proportion))
							gap := gtx.Constraints.Max.Y - height
							rect.Min.Y += gap

							paint.FillShape(gtx.Ops, color.NRGBA{R: 200, A: 100}, rect.Op())
							offset.Pop()
						}
					}


@@ 384,7 392,10 @@ func run(w *app.Window) error {
			ready = nil
			audioInit = true
			for idx, f := range freqs {
				players[idx] = Pipe{player: c.NewPlayer(NewSineWave(f))}
				players[idx] = Pipe{
					player: c.NewPlayer(NewSineWave(f)),
					freq:   f,
				}
			}
			log.Println("organ initialized")