Water flow from the bottom up using the iOS metal kit

I am creating an application in which water will flow from the bottom up. I made a lot of changes using the source from https://github.com/FlexMonkey/ParticleLab

Please find the video from the link below, it looks like Milk, but I'm trying to make it a real stream of water. http://expirebox.com/download/6e3c11ca4fb969df976b51628d1d9c89.html

enter image description here

func resetParticles(edgesOnly: Bool = false, distribution: Distribution = Distribution.Gaussian) { func rand() -> Float32 { return Float(drand48() * -20.005) } func rand2() -> Float32 { return Float(drand48() * 4) } let imageWidthDouble = Double(imageWidth/8) let imageHeightDouble = Double(Float(imageHeight)/1) let randomSource = GKRandomSource() let randomWidth: GKRandomDistribution let randomHeight: GKRandomDistribution switch distribution { case .Gaussian: randomWidth = GKGaussianDistribution(randomSource: randomSource, lowestValue: 0, highestValue: Int(imageWidthDouble)) randomHeight = GKGaussianDistribution(randomSource: randomSource, lowestValue: 0, highestValue: Int(imageHeightDouble)) case .Uniform: randomWidth = GKShuffledDistribution(randomSource: randomSource, lowestValue: 0, highestValue: Int(imageWidthDouble)) randomHeight = GKShuffledDistribution(randomSource: randomSource, lowestValue: 0, highestValue: Int(imageHeightDouble)) } for index in particlesParticleBufferPtr.startIndex ..< particlesParticleBufferPtr.endIndex { var positionAX = Float(randomWidth.nextInt()) var positionAY = Float(randomHeight.nextInt()) var positionBX = Float(randomWidth.nextInt()) var positionBY = Float(randomHeight.nextInt()) var positionCX = Float(randomWidth.nextInt()) var positionCY = Float(randomHeight.nextInt()) var positionDX = Float(randomWidth.nextInt()) var positionDY = Float(randomHeight.nextInt()) // print("\(positionAX) \(positionBX) \(positionCX) \(positionDX)") // print("\(positionAY) \(positionBY) \(positionCY) \(positionDX)") if edgesOnly { let positionRule = Int(arc4random() % 4) if positionRule == 0 { positionAX = 0 positionBX = 0 positionCX = 0 positionDX = 0 } else if positionRule == 1 { positionAX = Float(imageWidth) positionBX = Float(imageWidth) positionCX = Float(imageWidth) positionDX = Float(imageWidth) } else if positionRule == 2 { positionAY = 0 positionBY = 0 positionCY = 0 positionDY = 0 } else { positionAY = Float(imageHeight) positionBY = Float(imageHeight) positionCY = Float(imageHeight) positionDY = Float(imageHeight) } } let particle = Particle(A: Vector4(x: positionAX + 400 + rand(), y: positionAY, z: -rand2(), w: rand()), B: Vector4(x: positionBX + 400 + rand(), y: positionBY, z: rand2(), w: rand()), C: Vector4(x: positionCX + 400 + rand(), y: positionCY, z: -rand2(), w: rand()), D: Vector4(x: positionDX + 400 + rand(), y: positionDY, z: rand2(), w: rand())) particlesParticleBufferPtr[index] = particle } } 
+6
source share

All Articles