func drawGraph(ctx *nanovgo.Context, x, y, w, h, t float32) { var sx, sy [6]float32 dx := w / 5.0 samples := []float32{ (1 + sinF(t*1.2345+cosF(t*0.33457)*0.44)) * 0.5, (1 + sinF(t*0.68363+cosF(t*1.3)*1.55)) * 0.5, (1 + sinF(t*1.1642+cosF(t*0.33457)*1.24)) * 0.5, (1 + sinF(t*0.56345+cosF(t*1.63)*0.14)) * 0.5, (1 + sinF(t*1.6245+cosF(t*0.254)*0.3)) * 0.5, (1 + sinF(t*0.345+cosF(t*0.03)*0.6)) * 0.5, } for i := 0; i < 6; i++ { sx[i] = x + float32(i)*dx sy[i] = y + h*samples[i]*0.8 } // Graph background bg := nanovgo.LinearGradient(x, y, x, y+h, nanovgo.RGBA(0, 160, 192, 0), nanovgo.RGBA(0, 160, 192, 64)) ctx.BeginPath() ctx.MoveTo(sx[0], sy[0]) for i := 1; i < 6; i++ { ctx.BezierTo(sx[i-1]+dx*0.5, sy[i-1], sx[i]-dx*0.5, sy[i], sx[i], sy[i]) } ctx.LineTo(x+w, y+h) ctx.LineTo(x, y+h) ctx.SetFillPaint(bg) ctx.Fill() // Graph line ctx.BeginPath() ctx.MoveTo(sx[0], sy[0]+2) for i := 1; i < 6; i++ { ctx.BezierTo(sx[i-1]+dx*0.5, sy[i-1]+2, sx[i]-dx*0.5, sy[i]+2, sx[i], sy[i]+2) } ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 32)) ctx.SetStrokeWidth(3.0) ctx.Stroke() ctx.BeginPath() ctx.MoveTo(sx[0], sy[0]) for i := 1; i < 6; i++ { ctx.BezierTo(sx[i-1]+dx*0.5, sy[i-1], sx[i]-dx*0.5, sy[i], sx[i], sy[i]) } ctx.SetStrokeColor(nanovgo.RGBA(0, 160, 192, 255)) ctx.SetStrokeWidth(3.0) ctx.Stroke() // Graph sample pos for i := 0; i < 6; i++ { bg = nanovgo.RadialGradient(sx[i], sy[i]+2, 3.0, 8.0, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 0)) ctx.BeginPath() ctx.Rect(sx[i]-10, sy[i]-10+2, 20, 20) ctx.SetFillPaint(bg) ctx.Fill() } ctx.BeginPath() for i := 0; i < 6; i++ { ctx.Circle(sx[i], sy[i], 4.0) } ctx.SetFillColor(nanovgo.RGBA(0, 160, 192, 255)) ctx.Fill() ctx.BeginPath() for i := 0; i < 6; i++ { ctx.Circle(sx[i], sy[i], 2.0) } ctx.SetFillColor(nanovgo.RGBA(220, 220, 220, 255)) ctx.Fill() ctx.SetStrokeWidth(1.0) }