Nov
12
2014
12
2014
Draw Munching Squares
An article by mgear
No Comments
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; } }
Tags: munching squares, script
Related Posts
Leave a comment
Recent posts
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
- UnityHub: Add support for custom project title (instead of folder name) or use ProductName
Recent Comments
@unitycoder_com
My TweetsSubscribe to Blog via Email
Tag Cloud
2d
3D
AI
algorithm
android
asset
build
color
custom
demo
editor
effect
error
fake
free
game
generator
greasemonkey
indie
javascript
light
line
ludumdare
mesh
paint
particles
physics
plugin
proto
prototype
script
sea
shader
shadow
sprite
terrain
texture
tutorial
ui
unity
vertex
visibility
water
waves
webgl