Rainbow effect module

Rainbow Module

By LuaBearyGood


About

Rainbow module is the latest addition to my personal suite of modules ‘BearSuite’, It is designed to make it easy to give almost any visible instance a rainbow effect, which can be either the traditional colours of the spectrum, or perhaps something more unique

Want to know what it can do without reading an entire lengthy post? Look no further


Settings

One of my main focuses of this module was making it easily adaptable for as many use cases as possible, therefor it has several settings that can control how the module runs, The module settings can be configured in the setting module located inside of the main module. The settings available are:

  • FramesBeforeUpdate - How many times RunService.Heartbeat will be fired before the instances update to the next position (The rainbow effect is calculated in a way that increasing this variable will not slow down the rainbow effect.) If you want to run the rainbow effect as smoothly as possible set this to 0 or 1

  • DefaultColor - This is the color sequence that the instance will follow if it is not supplied when calling the RainbowModule:Add() function, This can either be a table of colours or a string referencing an existing sequence.

  • DefaultSpeed - This is the default speed if it is not supplied when calling RainbowModule:Add(). The lower the speed, the faster the effect goes, I would recommend not setting it to too extreme values. (stay between 0-20)

  • BaseTypesForInstances - This is a table showing the base properties the module will change if the Type argument is not supplied when calling the RainbowModule:Add() function, I would recommend leaving them as they are, however if you know what you are doing it is very simple to change.

  • PresetSequences - This is a table where you can store sequences you will use throughout your game, these sequences can then be called by giving a string instead of a table as the Color argument when calling RainbowModule:Add(). Here is an example of how to create sequences in the table (You can use Color3.FromRGB(), I just used Color3.new()):

PresetSequences = {
		['BlueToRed'] = {
			{KeyPoint = 0, Color = Color3.new(0.985916, 0, 0.145861)},
			{KeyPoint = 1, Color = Color3.new(0, 0, 0.998184)},
		},
		['Digital'] = {
			{KeyPoint = 0, Color = Color3.new(0.140154, 1, 0.0249485)},
			{KeyPoint = 1, Color = Color3.new(0, 0, 0)},
		},
		['Rainbow'] = {
			{KeyPoint = 0, Color = Color3.new(0.985916, 0, 0.145861)},
			{KeyPoint = 0.2, Color = Color3.new(0.990188, 0.488899, 0.154574)},
			{KeyPoint = 0.4, Color = Color3.new(0.16228, 1, 0.0721294)},
			{KeyPoint = 0.6, Color = Color3.new(0.040528, 0.0441444, 0.96965)},
			{KeyPoint = 0.8, Color = Color3.new(0.567102, 0, 0.96997)},
			{KeyPoint = 1, Color = Color3.new(0.956786, 0, 0.90898)},
		},
	}

Usage

The module is fairly straightforward and only contains 3 functions which are as follows:

  • Module:Add(Object, Color, Speed, Type) - Of all these four arguments, this function will work so long as a valid instance is supplied, and the other arguments will reset to the defaults defined in the settings module. For example you can just do:
    Module:Add(game.Workspace.Part)
    or
    Module:Add(Player.PlayerGui.ScreenGui.TextLabel, 'Rainbow')

  • Module:ClearAll() - This function will simply stop any rainbow parts from continuing to loop through their color cycle, it also deletes all records of them from the script.

  • Module:Remove(Object) - This function can be used to remove a single object from the rainbow loop, this will also delete all record of this object from the script.


Example of usage

While testing this module I decided to mess around with making my entire workspace rainbow using the following code:

If you are interesting in the result, click here

Code
local RainbowModule = require(game.ReplicatedStorage.BearSuite.Client.RainbowModule)
local Settings = require(game.ReplicatedStorage.BearSuite.Client.RainbowModule.Settings)

local List = {
	'Rainbow',
	'Digital',
	'BlueToRed'
}

for _, Frame in pairs(game.Workspace:GetDescendants()) do
	if Frame:IsA('BasePart') then
		RainbowModule:Add(Frame, List[math.random(1, #List)])
	end
end

The model

You can download a file of the module Here (2.6 KB)
Or get the model here


Credit

You do not have to credit me anywhere for using this module, but it means a lot to me if you do, also feel free to follow and tag me on twitter @LuaBearyGood, I would love to see what people do with it.

14 Likes

Looks amazing! I can definitely see many uses for this in some games, can’t wait to see what people make with this, haha. Thanks for sharing! :smiley: :+1:

3 Likes