[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
Trapezoidal Waves
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /sci/ - Science & Math

Thread replies: 13
Thread images: 4
File: Untitled.png (6 KB, 1001x343) Image search: [iqdb] [SauceNao] [Google]
Untitled.png
6 KB, 1001x343
Hey /sci/,
I'm trying to program a function that simply takes an integer, but cycles through all non-grey RGB values (i.e. one value is 255, one value is 0, one changes). My current method requires a lot of if-statements, so I was wondering if there was a mathematical approach I could take. The value of each color's brightness has a trapezoidal waveform, and so far I have this function (couldn't get latex to work for some reason so bare with me):
(255/pi) * [ sin^-1( sin( pi/2 * x ) ) + cos^-1( cos( pi/2*x ) ) ]

However I want to "stretch" just the horizontal parts so they last for a longer interval (picture is a visual explanation), so that the values read as follows:
x=0, y=0
1 <= x <= 3. y=255
4 <= x <= 6, y=0

Any ideas how to achieve this mathematically, without resorting to piece-wise?
>>
>>7754984
Op here
To clarify, I want to preserve the characteristic that the wave goes from 0 to 255 in an interval of 1, or [x,x+1], so normal sinusoidal stretching won't suffice.
>>
>>
File: U2eeo.jpg (84 KB, 575x675) Image search: [iqdb] [SauceNao] [Google]
U2eeo.jpg
84 KB, 575x675
>>
>>7754984
Pre-generate a lookup table
>>
>>7754984
Let R3 represent an RGB space.
Imagine an object flying around in an orbit.
The position of that object marks your RGB value.
>>
Why not something like

min( 255, K - L * | 255 * (x-offset) | )

where you adjust the offset, K and L to your liking? Deep down, using min and abs is obviously the same as nested if-statements, but that'd still yield a simple formula.
>>
>>7756650
yes, here is an extended version
https://www.desmos.com/calculator/cndmbbi3qa
(One uses mod and the other arcsin(sin(x)), I dont know which one is more efficient)
>>
>>7757949
>>7756396
I would run through the equation once to generate the lookup table, so you dont have to calculate arcsin(sin(x)) or MOD each time
>>
>>7754984
Just use the HSV color space and convert back to RGB.
>>
File: ZcBXMSb.webm (438 KB, 568x422) Image search: [iqdb] [SauceNao] [Google]
ZcBXMSb.webm
438 KB, 568x422
>>7754984
Matlab can realise yo dreams homie!!
>>
What's the point of using asin(sin(x)), asin is just inverse of sin, so wouldn't it just return it's argument?
>>
>>7759666
Depends on which interval you work. asin always returns values between -pi/2 and pi/2 and pi/2*x obviously doesn't. In the interval -1 to 1, it's the same. But outside that, pi/2*x is a straight line and asin(sin(pi/2*x)) is a triangle.
Thread replies: 13
Thread images: 4
Thread DB ID: 377580



[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.