12
2014
Draw Munching Squares

Converted this php script into unity, while trying to keep it similar to original code..
again some difference in the output but close enough..
http://rosettacode.org/wiki/Munching_squares#PHP
Source c# (MunchingSquares.cs)
// Original source: http://rosettacode.org/wiki/Munching_squares#PHP
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MunchingSquares : MonoBehaviour
{
void Start ()
{
MakeMunch();
}
void MakeMunch()
{
int w = 256;
int h = 256;
Texture2D im = new Texture2D(w, h);
if (im==null) Debug.LogError("Cannot Initialize new texture");
List<Color> color = new List<Color>();
for(int i=0;i<256;i++)
{
color.Add(new Color( (Mathf.Sin((i)*(2*3.14f/256))*128+128)/255 , (i/2)/255 , i/255 , 1));
}
for(int i=0;i<w;i++)
{
for(int j=0;j<h;j++)
{
im.SetPixel(i,j,color[i^j]);
}
}
im.Apply(false);
renderer.material.mainTexture = im;
}
}
Related Posts
Leave a comment
Recent posts
- Editor Tool: Property Watcher
- .unityignore : Hide files from Project window
- PostBuild Script to Create Single exe Standalone File
- Game Loop Designer
- Favorites in PackageManager
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
Recent Comments
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by











