113 {
114
115
116
118
119
120
121 float xf = (float)width / (float)max_width;
122 uint8_t
x = (uint8_t)(xf * 255);
123
124
125 uint32_t cosx =
cos8(
x);
126 uint32_t sinx =
sin8(
x);
127
128
129
131 cosx *= trig_scale;
132 sinx *= trig_scale;
133
134
136
137
138 uint16_t
z = millis32 /
invSpeedZ.as<uint16_t>();
139
140
141
142
143 uint16_t noise16 =
inoise16(cosx << 8, sinx << 8,
y << 8, 0);
144
145
146 uint8_t noise_val = noise16 >> 8;
147
148
149
150
151 int8_t subtraction_factor =
abs8(height - (max_height - 1)) * 255 /
152 (max_height - 1);
153
154
155
156 return qsub8(noise_val, subtraction_factor);
157}
UISlider scaleXY("Scale", 8, 1, 100, 1)
UISlider invSpeedZ("Inverse SpeedZ", 20, 1, 100, 1)
UISlider scaleX("ScaleX",.3, 0.1, 3,.01)
LIB8STATIC_ALWAYS_INLINE int8_t abs8(int8_t i)
Take the absolute value of a signed 8-bit uint8_t.
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z, uint32_t t)
16-bit, fixed point implementation of Perlin's noise.
LIB8STATIC uint8_t cos8(uint8_t theta)
Fast 8-bit approximation of cos(x).
#define sin8
Platform-independent alias of the fast sin implementation.