Contents

lightTunnel()

Distorts an image by generating a light tunnel.

Declaration

class func lightTunnel() -> any CIFilter & CILightTunnel

Return Value

The distorted image.

Discussion

This method applies the light tunnel filter to an image. This effect distorts the input image by warping the image to cylinder shape.

The light tunnel filter uses the following properties:

inputImage

An image with the type CIImage.

center

A set of coordinates marking the center of the light tunnel as a CGPoint.

radius

A float representing the amount of pixels the filter uses to create the light tunnel as an NSNumber.

rotation

A float representing the rotation angle of the light tunnel as an NSNumber.

The following code creates a filter that generates a swirling pattern from the input image:

func lightTunnel(inputImage: CIImage) -> CIImage {
    let filter = CIFilter.lightTunnel()
    filter.inputImage = inputImage
    filter.radius = 100
    filter.rotation = .pi
    filter.center = CGPoint(
        x: inputImage.extent.width / 2,
        y: inputImage.extent.size.height / 2
    )
    return filter.outputImage!.cropped(to: inputImage.extent)
}

[Image]

See Also

Filters