# Animated Color Procedural Texture

(→JavaScript - AnimatedTextureUV.js) |
(→JavaScript - AnimatedTextureUV.js) |
||

Line 25: | Line 25: | ||

var width = 128; | var width = 128; | ||

var height = 128; | var height = 128; | ||

− | |||

− | |||

private var texture : Texture2D; | private var texture : Texture2D; |

## Revision as of 14:02, 3 July 2011

Author: Antony Stewart

## Description

This is a simple mod of the procedural perlin noise demo script, to generate textures with mixes of RGB by blending 3 independant RGB x,y, graphs.

## Usage

Attach this script to the object that you wish to give a special effects color. Write maths functions for the red, blue, green variables that compute between 0 and 1, based on x,y, graphs. pastel colors are closer to .7 and bright colors closer to 1. for example if you want a psycadelically angry robot, make a black and red dot graph and make move in Time.time*50, i.e. warping very fast. You need to know abit about 2D graphs, straight =sin(x*10) vertical =sin(y*10) oblique = sin(x+y) or (x-y) wiggle = sin(x*10+sin(y*5)*3) complex wiggles = add multiple wiggles together.

## JavaScript - AnimatedTextureUV.js

<javascript>

var gray = true;
var width = 128;
var height = 128;

private var texture : Texture2D;

function Start () { texture = new Texture2D(width, height, TextureFormat.RGB24, false); renderer.material.mainTexture = texture; }

function Update() { Calculate(); }

function Calculate() {

for (var y = 0;y<height;y++)
{
for (var x = 0;x<width;x++)
{
if (gray)
{
var red = 0;
var green = Mathf.Sin(x*50+Time.time+Mathf.Sin(y*30)*4)/5+.5;
var blue = Mathf.Sin(x*50+Time.time+Mathf.Sin(x*30)*4)/5+.5;

texture.SetPixel(x, y, Color (red,green, blue, 1)); } else {

texture.SetPixel(x, y, Color (1, 0, 0, 1));
}
}
}

texture.Apply(); } </javascript>