1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::prelude::*;
use crate::{scalar, ISize, Shader};
use skia_bindings as sb;
use skia_bindings::SkShader;

impl RCHandle<SkShader> {
    pub fn fractal_perlin_noise(
        base_frequency: (scalar, scalar),
        num_octaves: usize,
        seed: scalar,
        tile_size: impl Into<Option<ISize>>,
    ) -> Option<Self> {
        fractal_noise(base_frequency, num_octaves, seed, tile_size)
    }

    pub fn turbulence_perlin_noise(
        base_frequency: (scalar, scalar),
        num_octaves: usize,
        seed: scalar,
        tile_size: impl Into<Option<ISize>>,
    ) -> Option<Self> {
        turbulence(base_frequency, num_octaves, seed, tile_size)
    }

    pub fn improved_perlin_noise(
        base_frequency: (scalar, scalar),
        num_octaves: usize,
        z: scalar,
    ) -> Option<Self> {
        improved_noise(base_frequency, num_octaves, z)
    }
}

pub fn fractal_noise(
    base_frequency: (scalar, scalar),
    num_octaves: usize,
    seed: scalar,
    tile_size: impl Into<Option<ISize>>,
) -> Option<Shader> {
    Shader::from_ptr(unsafe {
        sb::C_SkPerlinNoiseShader_MakeFractalNoise(
            base_frequency.0,
            base_frequency.1,
            num_octaves.try_into().unwrap(),
            seed,
            tile_size.into().native().as_ptr_or_null(),
        )
    })
}

pub fn turbulence(
    base_frequency: (scalar, scalar),
    num_octaves: usize,
    seed: scalar,
    tile_size: impl Into<Option<ISize>>,
) -> Option<Shader> {
    Shader::from_ptr(unsafe {
        sb::C_SkPerlinNoiseShader_MakeTurbulence(
            base_frequency.0,
            base_frequency.1,
            num_octaves.try_into().unwrap(),
            seed,
            tile_size.into().native().as_ptr_or_null(),
        )
    })
}

pub fn improved_noise(
    base_frequency: (scalar, scalar),
    num_octaves: usize,
    z: scalar,
) -> Option<Shader> {
    Shader::from_ptr(unsafe {
        sb::C_SkPerlinNoiseShader_MakeImprovedNoise(
            base_frequency.0,
            base_frequency.1,
            num_octaves.try_into().unwrap(),
            z,
        )
    })
}