Add gradient below SKShapeNode

I am working on such a schedule in watchKit.

enter image description here

I successfully draw a line graph as shown above according to user data, but I cannot draw a gradient below the line graph as shown above.

here is what i did:

 var points = [CGPoint(x: 0, y: 20),
                      CGPoint(x: 10, y: 10),
                      CGPoint(x: 25, y: 25),
                      CGPoint(x: 45, y: 5),
                      CGPoint(x: 60, y: 10),
                      CGPoint(x: 75, y: 0),
                      CGPoint(x: 90, y: 25),
                      CGPoint(x: 110, y: 0),
                      CGPoint(x: 125, y: 25)]
        let shape = SKShapeNode(splinePoints: &points,
                                          count: points.count)
        shape.strokeColor = UIColor.white
        shape.lineWidth = 2

        let gradientShader = SKShader(source: "void main() {" +
            "float normalisedPosition = v_path_distance / u_path_length;" +
            "gl_FragColor = vec4(normalisedPosition, normalisedPosition, 0.0, 1.0);" +
            "}")
       // shape.strokeShader = gradientShader

        addChild(shape)

This code will draw such a graph. (for example, the graph is perfect, but I tried the gradient problem as well SKShader).

enter image description here

+4
source share

Source: https://habr.com/ru/post/1693255/


All Articles