|
Post by xavier on Mar 15, 2019 14:27:29 GMT
Hello, I am at the end of «chapter 10, Patterns», trying to figure out an algorithm for a radial gradient pattern. But all what I tried fail… I will take any hint. Thank you
(very great and fun book, by the way)
|
|
|
Post by Jamis on Mar 15, 2019 14:40:14 GMT
Hello xavier ! For the radial gradient pattern, what you need to do is find the distance of the given point from the origin. Once you have that distance, the algorithm works very much like the linear gradient. In other words, with the linear gradient you used the x coordinate as the distance from the origin. For the radial gradient, you use the point's radial distance from the origin. Something like this, perhaps: m ← magnitude(point) fraction ← m - floor(m)
Does that help?
|
|
|
Post by xavier on Mar 15, 2019 15:26:34 GMT
Yes, it helps! Thank you. After a quick try I can generate this pattern
|
|
|
Post by baptiste on Nov 5, 2019 17:22:54 GMT
Hey,
Sorry for reviving this post, but I think this is the most appropriate place for my question.
Since our point has its w component == 1, shouldn't we set it to 0 before calculating the magnitude?
v ← point v.w = 0 m ← magnitude(v) fraction ← m - floor(m)
Cheers
|
|
|
Post by Jamis on Nov 8, 2019 4:24:01 GMT
baptiste -- yeah, you're right. Taking the magnitude of a point is kind of nonsensical, it really does need to be converted to a vector first (by setting w to 0), which is the vector from the origin the point.
|
|