Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Better rainbow code #6

Open
inxomnyaa opened this issue Jan 22, 2021 · 1 comment
Open

Better rainbow code #6

inxomnyaa opened this issue Jan 22, 2021 · 1 comment

Comments

@inxomnyaa
Copy link

inxomnyaa commented Jan 22, 2021

Good morning my friend. I fiddled around a bit, and figured this code works better and is cleaner for rainbow color fading:

	private function updateColor(int $step): Color
	{
		$center = 128;
		$width = 127;
		$frequency = 100;//controls change speed
		$red = sin($frequency * $step + 2) * $width + $center;
		$green = sin($frequency * $step + 0) * $width + $center;
		$blue = sin($frequency * $step + 4) * $width + $center;
		return new Color($red, $green, $blue);
	}

$step can be the current tick. $frequency controls how fast/much the colors change

Original code and read-up can be found here: https://krazydad.com/tutorials/makecolors.php

@Enes5519
Copy link
Member

my friend, I'm away from this stuff, but thanks for your advice. I will approve if you send a pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants