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

Trapezoidal Waves

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 4

File: Untitled.png (6KB, 1001x343px) Image search: [Google]
Untitled.png
6KB, 1001x343px
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 (84KB, 575x675px) Image search: [Google]
U2eeo.jpg
84KB, 575x675px
>>
>>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 (438KB, 568x422px) Image search: [Google]
ZcBXMSb.webm
438KB, 568x422px
>>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 posts: 13
Thread images: 4


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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 content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.