
Experimental results obtained in 1879 when conducting electricity through rarefied gases in a vacuum tube and modulated by a magnetic field. From left to right, the tube is filled with nitrogen, oxygen, carbon dioxide and tin(IV) chloride. The positive electrode is on top. The tube with nitrogen produced a spiral, the one with carbon dioxide a set of nine stacked toroids embracing a Y-shaped column. (c) John Rand Capron.



using System.Collections.Generic;
using UnityEngine;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class GradientMapper : MonoBehaviour
{
[Header("Gradient map parameters")]
public Vector2Int gradientMapDimensions = new Vector2Int(128, 32);
public Gradient gradient;
[Header("Enable testing")]
public bool testing = false;
private SpriteRenderer spriteRenderer;
private Material material;
[HideInInspector]
public Texture2D texture;
public static int totalMaps = 0;
[Range(2, 50)]
public int numKeys = 2;
[Range(-1f, 1f)]
public float posterize = 0;
[Range(0f, 0.999f)]
public float drift = 0;
public Color color_1;
public Color color_2;
private void OnEnable()
{
spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer == null)
{
Debug.LogWarning("No sprite renderer on this game object! Removing GradientMapper");
DestroyImmediate(this);
}
else
{
material = spriteRenderer.sharedMaterial;
}
}
void Update()
{
if (testing)
{
if (texture == null)
{
texture = new Texture2D(gradientMapDimensions.x, gradientMapDimensions.y);
}
texture.wrapMode = TextureWrapMode.Clamp;
Color col_1;
Color col_2;
float t = 0;
int pix_per_Key = gradientMapDimensions.x / (numKeys - 1);
int curr_key = -1;
int mod;
float dt = 1f / (float)pix_per_Key;
for (int x = 0; x < gradientMapDimensions.x; x++)
{
mod = x % pix_per_Key;
if (mod == (int)(pix_per_Key*drift))
{
curr_key++;
t = 0;
}
if (curr_key % 2 == 0)
{
col_1 = color_1;
col_2 = color_2;
}
else
{
col_1 = color_2;
col_2 = color_1;
}
Color color = Color.Lerp(col_1, col_2, t+posterize);
t += dt;
for (int y = 0; y < gradientMapDimensions.y; y++)
{
texture.SetPixel(x, y, color);
}
}
texture.Apply();
if (material.HasProperty("_GradientMap"))
{
material.SetTexture("_GradientMap", texture);
}
}
}
}









