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
- 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)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
- Convert LAS/LAZ/PLY pointclouds to GLTF (GLB) Point Meshes (standalone converter)
- Detect SRP (URP or HDRP) with Assembly Definition Version Defines
- [LudumDare57] Theme: Depths
- MotionVector Effect: Object “disappears” when paused
Recent Comments
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
- on UI Scroll View automatic Content height
- on [Asset Store] Point Cloud Viewer & Tools
- on [Asset Store] Point Cloud Viewer & Tools
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by











