WeixiangYan/CodeTransOcean huggingface dataset:
Task: Munching squares

C: #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

void hue_to_rgb(double hue, double sat, unsigned char *p)
{
	double x;
	int c = 255 * sat;
	hue /= 60;
	x = (1 - fabs(fmod(hue, 2) - 1)) * 255;

	switch((int)hue) {
	case 0:	p[0] = c; p[1] = x; p[2] = 0; return;
	case 1:	p[0] = x; p[1] = c; p[2] = 0; return;
	case 2:	p[0] = 0; p[1] = c; p[2] = x; return;
	case 3:	p[0] = 0; p[1] = x; p[2] = c; return;
	case 4:	p[0] = x; p[1] = 0; p[2] = c; return;
	case 5:	p[0] = c; p[1] = 0; p[2] = x; return;
	}
}

int main(void)
{
	const int size = 512;
	int i, j;
	unsigned char *colors = malloc(size * 3);
	unsigned char *pix = malloc(size * size * 3), *p;
	FILE *fp;

	for (i = 0; i < size; i++)
		hue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i);

	for (i = 0, p = pix; i < size; i++)
		for (j = 0; j < size; j++, p += 3)
			memcpy(p, colors + (i ^ j) * 3, 3);

	fp = fopen("xor.ppm", "wb");
	fprintf(fp, "P6\n%d %d\n255\n", size, size);
	fwrite(pix, size * size * 3, 1, fp);
	fclose(fp);

	return 0;
}





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class XorPattern extends JFrame{
    private JPanel xorPanel;

    public XorPattern(){
        xorPanel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                for(int y = 0; y < getHeight();y++){
                    for(int x = 0; x < getWidth();x++){
                        g.setColor(new Color(0, (x ^ y) % 256, 0));
                        g.drawLine(x, y, x, y);
                    }
                }
            }
        };
        add(xorPanel);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args){
        new XorPattern();
    }
}
Task: Munching squares



C#: using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;

class XORPattern
{
    static void Main()
    {
        var size = 0x100;
        var black = Color.Black.ToArgb();
        var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
        using (var image = new Bitmap(size, size))
        {
            for (var x = 0; x < size; x++)
            {
                for (var y = 0; y < size; y++)
                {
                    image.SetPixel(x, y, palette[x ^ y]);
                }
            }
            image.Save("XORPatternCSharp.png", ImageFormat.Png);
        }
    }
}



Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class XorPattern extends JFrame{
    private JPanel xorPanel;

    public XorPattern(){
        xorPanel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                for(int y = 0; y < getHeight();y++){
                    for(int x = 0; x < getWidth();x++){
                        g.setColor(new Color(0, (x ^ y) % 256, 0));
                        g.drawLine(x, y, x, y);
                    }
                }
            }
        };
        add(xorPanel);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args){
        new XorPattern();
    }
}
Task: Munching squares



C#: using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;

class XORPattern
{
    static void Main()
    {
        var size = 0x100;
        var black = Color.Black.ToArgb();
        var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
        using (var image = new Bitmap(size, size))
        {
            for (var x = 0; x < size; x++)
            {
                for (var y = 0; y < size; y++)
                {
                    image.SetPixel(x, y, palette[x ^ y]);
                }
            }
            image.Save("XORPatternCSharp.png", ImageFormat.Png);
        }
    }
}





Python: import Image, ImageDraw

image = Image.new("RGB", (256, 256))
drawingTool = ImageDraw.Draw(image)

for x in range(256):
    for y in range(256):
        drawingTool.point((x, y), (0, x^y, 0))

del drawingTool
image.save("xorpic.png", "PNG")
Task: Munching squares





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class XorPattern extends JFrame{
    private JPanel xorPanel;

    public XorPattern(){
        xorPanel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                for(int y = 0; y < getHeight();y++){
                    for(int x = 0; x < getWidth();x++){
                        g.setColor(new Color(0, (x ^ y) % 256, 0));
                        g.drawLine(x, y, x, y);
                    }
                }
            }
        };
        add(xorPanel);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args){
        new XorPattern();
    }
}




VB: 
Public Class MunchingSquares
    Const xsize = 256
    Dim BMP As New Drawing.Bitmap(xsize, xsize)
    Dim GFX As Graphics = Graphics.FromImage(BMP)

    Private Sub MunchingSquares_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        
        Dim MyGraph As Graphics = Me.CreateGraphics
        Dim nColor As Color
        Dim i, j, cp As Integer
        xPictureBox.Image = BMP
        For i = 0 To xsize - 1
            For j = 0 To xsize - 1
                cp = i Xor j
                nColor = Color.FromArgb(cp, 0, cp)
                BMP.SetPixel(i, j, nColor)
            Next j
        Next i
    End Sub 

End Class
Task: Munching squares




Go: package main

import (
    "image"
    "image/png"
    "os"
)

func main() {
    g := image.NewGray(image.Rect(0, 0, 256, 256))
    for i := range g.Pix {
        g.Pix[i] = uint8(i>>8 ^ i)
    }
    f, _ := os.Create("xor.png")
    png.Encode(f, g)
    f.Close()
}




Python: import Image, ImageDraw

image = Image.new("RGB", (256, 256))
drawingTool = ImageDraw.Draw(image)

for x in range(256):
    for y in range(256):
        drawingTool.point((x, y), (0, x^y, 0))

del drawingTool
image.save("xorpic.png", "PNG")
Task: Munching squares




Go: package main

import (
    "image"
    "image/png"
    "os"
)

func main() {
    g := image.NewGray(image.Rect(0, 0, 256, 256))
    for i := range g.Pix {
        g.Pix[i] = uint8(i>>8 ^ i)
    }
    f, _ := os.Create("xor.png")
    png.Encode(f, g)
    f.Close()
}





VB: 
Public Class MunchingSquares
    Const xsize = 256
    Dim BMP As New Drawing.Bitmap(xsize, xsize)
    Dim GFX As Graphics = Graphics.FromImage(BMP)

    Private Sub MunchingSquares_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        
        Dim MyGraph As Graphics = Me.CreateGraphics
        Dim nColor As Color
        Dim i, j, cp As Integer
        xPictureBox.Image = BMP
        For i = 0 To xsize - 1
            For j = 0 To xsize - 1
                cp = i Xor j
                nColor = Color.FromArgb(cp, 0, cp)
                BMP.SetPixel(i, j, nColor)
            Next j
        Next i
    End Sub 

End Class
Task: Munching squares







Python: import Image, ImageDraw

image = Image.new("RGB", (256, 256))
drawingTool = ImageDraw.Draw(image)

for x in range(256):
    for y in range(256):
        drawingTool.point((x, y), (0, x^y, 0))

del drawingTool
image.save("xorpic.png", "PNG")


VB: 
Public Class MunchingSquares
    Const xsize = 256
    Dim BMP As New Drawing.Bitmap(xsize, xsize)
    Dim GFX As Graphics = Graphics.FromImage(BMP)

    Private Sub MunchingSquares_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        
        Dim MyGraph As Graphics = Me.CreateGraphics
        Dim nColor As Color
        Dim i, j, cp As Integer
        xPictureBox.Image = BMP
        For i = 0 To xsize - 1
            For j = 0 To xsize - 1
                cp = i Xor j
                nColor = Color.FromArgb(cp, 0, cp)
                BMP.SetPixel(i, j, nColor)
            Next j
        Next i
    End Sub 

End Class
Task: Munching squares

C: #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

void hue_to_rgb(double hue, double sat, unsigned char *p)
{
	double x;
	int c = 255 * sat;
	hue /= 60;
	x = (1 - fabs(fmod(hue, 2) - 1)) * 255;

	switch((int)hue) {
	case 0:	p[0] = c; p[1] = x; p[2] = 0; return;
	case 1:	p[0] = x; p[1] = c; p[2] = 0; return;
	case 2:	p[0] = 0; p[1] = c; p[2] = x; return;
	case 3:	p[0] = 0; p[1] = x; p[2] = c; return;
	case 4:	p[0] = x; p[1] = 0; p[2] = c; return;
	case 5:	p[0] = c; p[1] = 0; p[2] = x; return;
	}
}

int main(void)
{
	const int size = 512;
	int i, j;
	unsigned char *colors = malloc(size * 3);
	unsigned char *pix = malloc(size * size * 3), *p;
	FILE *fp;

	for (i = 0; i < size; i++)
		hue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i);

	for (i = 0, p = pix; i < size; i++)
		for (j = 0; j < size; j++, p += 3)
			memcpy(p, colors + (i ^ j) * 3, 3);

	fp = fopen("xor.ppm", "wb");
	fprintf(fp, "P6\n%d %d\n255\n", size, size);
	fwrite(pix, size * size * 3, 1, fp);
	fclose(fp);

	return 0;
}




Go: package main

import (
    "image"
    "image/png"
    "os"
)

func main() {
    g := image.NewGray(image.Rect(0, 0, 256, 256))
    for i := range g.Pix {
        g.Pix[i] = uint8(i>>8 ^ i)
    }
    f, _ := os.Create("xor.png")
    png.Encode(f, g)
    f.Close()
}
Task: Munching squares

C: #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

void hue_to_rgb(double hue, double sat, unsigned char *p)
{
	double x;
	int c = 255 * sat;
	hue /= 60;
	x = (1 - fabs(fmod(hue, 2) - 1)) * 255;

	switch((int)hue) {
	case 0:	p[0] = c; p[1] = x; p[2] = 0; return;
	case 1:	p[0] = x; p[1] = c; p[2] = 0; return;
	case 2:	p[0] = 0; p[1] = c; p[2] = x; return;
	case 3:	p[0] = 0; p[1] = x; p[2] = c; return;
	case 4:	p[0] = x; p[1] = 0; p[2] = c; return;
	case 5:	p[0] = c; p[1] = 0; p[2] = x; return;
	}
}

int main(void)
{
	const int size = 512;
	int i, j;
	unsigned char *colors = malloc(size * 3);
	unsigned char *pix = malloc(size * size * 3), *p;
	FILE *fp;

	for (i = 0; i < size; i++)
		hue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i);

	for (i = 0, p = pix; i < size; i++)
		for (j = 0; j < size; j++, p += 3)
			memcpy(p, colors + (i ^ j) * 3, 3);

	fp = fopen("xor.ppm", "wb");
	fprintf(fp, "P6\n%d %d\n255\n", size, size);
	fwrite(pix, size * size * 3, 1, fp);
	fclose(fp);

	return 0;
}







Python: import Image, ImageDraw

image = Image.new("RGB", (256, 256))
drawingTool = ImageDraw.Draw(image)

for x in range(256):
    for y in range(256):
        drawingTool.point((x, y), (0, x^y, 0))

del drawingTool
image.save("xorpic.png", "PNG")
Task: Munching squares

C: #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

void hue_to_rgb(double hue, double sat, unsigned char *p)
{
	double x;
	int c = 255 * sat;
	hue /= 60;
	x = (1 - fabs(fmod(hue, 2) - 1)) * 255;

	switch((int)hue) {
	case 0:	p[0] = c; p[1] = x; p[2] = 0; return;
	case 1:	p[0] = x; p[1] = c; p[2] = 0; return;
	case 2:	p[0] = 0; p[1] = c; p[2] = x; return;
	case 3:	p[0] = 0; p[1] = x; p[2] = c; return;
	case 4:	p[0] = x; p[1] = 0; p[2] = c; return;
	case 5:	p[0] = c; p[1] = 0; p[2] = x; return;
	}
}

int main(void)
{
	const int size = 512;
	int i, j;
	unsigned char *colors = malloc(size * 3);
	unsigned char *pix = malloc(size * size * 3), *p;
	FILE *fp;

	for (i = 0; i < size; i++)
		hue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i);

	for (i = 0, p = pix; i < size; i++)
		for (j = 0; j < size; j++, p += 3)
			memcpy(p, colors + (i ^ j) * 3, 3);

	fp = fopen("xor.ppm", "wb");
	fprintf(fp, "P6\n%d %d\n255\n", size, size);
	fwrite(pix, size * size * 3, 1, fp);
	fclose(fp);

	return 0;
}








VB: 
Public Class MunchingSquares
    Const xsize = 256
    Dim BMP As New Drawing.Bitmap(xsize, xsize)
    Dim GFX As Graphics = Graphics.FromImage(BMP)

    Private Sub MunchingSquares_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        
        Dim MyGraph As Graphics = Me.CreateGraphics
        Dim nColor As Color
        Dim i, j, cp As Integer
        xPictureBox.Image = BMP
        For i = 0 To xsize - 1
            For j = 0 To xsize - 1
                cp = i Xor j
                nColor = Color.FromArgb(cp, 0, cp)
                BMP.SetPixel(i, j, nColor)
            Next j
        Next i
    End Sub 

End Class
Task: Munching squares



C#: using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;

class XORPattern
{
    static void Main()
    {
        var size = 0x100;
        var black = Color.Black.ToArgb();
        var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
        using (var image = new Bitmap(size, size))
        {
            for (var x = 0; x < size; x++)
            {
                for (var y = 0; y < size; y++)
                {
                    image.SetPixel(x, y, palette[x ^ y]);
                }
            }
            image.Save("XORPatternCSharp.png", ImageFormat.Png);
        }
    }
}


Go: package main

import (
    "image"
    "image/png"
    "os"
)

func main() {
    g := image.NewGray(image.Rect(0, 0, 256, 256))
    for i := range g.Pix {
        g.Pix[i] = uint8(i>>8 ^ i)
    }
    f, _ := os.Create("xor.png")
    png.Encode(f, g)
    f.Close()
}
Task: Munching squares




Go: package main

import (
    "image"
    "image/png"
    "os"
)

func main() {
    g := image.NewGray(image.Rect(0, 0, 256, 256))
    for i := range g.Pix {
        g.Pix[i] = uint8(i>>8 ^ i)
    }
    f, _ := os.Create("xor.png")
    png.Encode(f, g)
    f.Close()
}


Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class XorPattern extends JFrame{
    private JPanel xorPanel;

    public XorPattern(){
        xorPanel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                for(int y = 0; y < getHeight();y++){
                    for(int x = 0; x < getWidth();x++){
                        g.setColor(new Color(0, (x ^ y) % 256, 0));
                        g.drawLine(x, y, x, y);
                    }
                }
            }
        };
        add(xorPanel);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args){
        new XorPattern();
    }
}
Task: Munching squares





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class XorPattern extends JFrame{
    private JPanel xorPanel;

    public XorPattern(){
        xorPanel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                for(int y = 0; y < getHeight();y++){
                    for(int x = 0; x < getWidth();x++){
                        g.setColor(new Color(0, (x ^ y) % 256, 0));
                        g.drawLine(x, y, x, y);
                    }
                }
            }
        };
        add(xorPanel);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args){
        new XorPattern();
    }
}



Python: import Image, ImageDraw

image = Image.new("RGB", (256, 256))
drawingTool = ImageDraw.Draw(image)

for x in range(256):
    for y in range(256):
        drawingTool.point((x, y), (0, x^y, 0))

del drawingTool
image.save("xorpic.png", "PNG")
Task: Munching squares



C#: using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;

class XORPattern
{
    static void Main()
    {
        var size = 0x100;
        var black = Color.Black.ToArgb();
        var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
        using (var image = new Bitmap(size, size))
        {
            for (var x = 0; x < size; x++)
            {
                for (var y = 0; y < size; y++)
                {
                    image.SetPixel(x, y, palette[x ^ y]);
                }
            }
            image.Save("XORPatternCSharp.png", ImageFormat.Png);
        }
    }
}






VB: 
Public Class MunchingSquares
    Const xsize = 256
    Dim BMP As New Drawing.Bitmap(xsize, xsize)
    Dim GFX As Graphics = Graphics.FromImage(BMP)

    Private Sub MunchingSquares_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        
        Dim MyGraph As Graphics = Me.CreateGraphics
        Dim nColor As Color
        Dim i, j, cp As Integer
        xPictureBox.Image = BMP
        For i = 0 To xsize - 1
            For j = 0 To xsize - 1
                cp = i Xor j
                nColor = Color.FromArgb(cp, 0, cp)
                BMP.SetPixel(i, j, nColor)
            Next j
        Next i
    End Sub 

End Class
Task: Munching squares

C: #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

void hue_to_rgb(double hue, double sat, unsigned char *p)
{
	double x;
	int c = 255 * sat;
	hue /= 60;
	x = (1 - fabs(fmod(hue, 2) - 1)) * 255;

	switch((int)hue) {
	case 0:	p[0] = c; p[1] = x; p[2] = 0; return;
	case 1:	p[0] = x; p[1] = c; p[2] = 0; return;
	case 2:	p[0] = 0; p[1] = c; p[2] = x; return;
	case 3:	p[0] = 0; p[1] = x; p[2] = c; return;
	case 4:	p[0] = x; p[1] = 0; p[2] = c; return;
	case 5:	p[0] = c; p[1] = 0; p[2] = x; return;
	}
}

int main(void)
{
	const int size = 512;
	int i, j;
	unsigned char *colors = malloc(size * 3);
	unsigned char *pix = malloc(size * size * 3), *p;
	FILE *fp;

	for (i = 0; i < size; i++)
		hue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i);

	for (i = 0, p = pix; i < size; i++)
		for (j = 0; j < size; j++, p += 3)
			memcpy(p, colors + (i ^ j) * 3, 3);

	fp = fopen("xor.ppm", "wb");
	fprintf(fp, "P6\n%d %d\n255\n", size, size);
	fwrite(pix, size * size * 3, 1, fp);
	fclose(fp);

	return 0;
}






PHP: header("Content-Type: image/png");

$w = 256;
$h = 256;

$im = imagecreate($w, $h)
    or die("Cannot Initialize new GD image stream");

$color = array();
for($i=0;$i<256;$i++)
{
        array_push($color,imagecolorallocate($im,sin(($i)*(2*3.14/256))*128+128,$i/2,$i));
}

for($i=0;$i<$w;$i++)
{
        for($j=0;$j<$h;$j++)
        {
                imagesetpixel($im,$i,$j,$color[$i^$j]);
        }
}

imagepng($im);
imagedestroy($im);
Task: Munching squares



C#: using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;

class XORPattern
{
    static void Main()
    {
        var size = 0x100;
        var black = Color.Black.ToArgb();
        var palette = Enumerable.Range(black, size).Select(Color.FromArgb).ToArray();
        using (var image = new Bitmap(size, size))
        {
            for (var x = 0; x < size; x++)
            {
                for (var y = 0; y < size; y++)
                {
                    image.SetPixel(x, y, palette[x ^ y]);
                }
            }
            image.Save("XORPatternCSharp.png", ImageFormat.Png);
        }
    }
}




PHP: header("Content-Type: image/png");

$w = 256;
$h = 256;

$im = imagecreate($w, $h)
    or die("Cannot Initialize new GD image stream");

$color = array();
for($i=0;$i<256;$i++)
{
        array_push($color,imagecolorallocate($im,sin(($i)*(2*3.14/256))*128+128,$i/2,$i));
}

for($i=0;$i<$w;$i++)
{
        for($j=0;$j<$h;$j++)
        {
                imagesetpixel($im,$i,$j,$color[$i^$j]);
        }
}

imagepng($im);
imagedestroy($im);
Task: Munching squares




Go: package main

import (
    "image"
    "image/png"
    "os"
)

func main() {
    g := image.NewGray(image.Rect(0, 0, 256, 256))
    for i := range g.Pix {
        g.Pix[i] = uint8(i>>8 ^ i)
    }
    f, _ := os.Create("xor.png")
    png.Encode(f, g)
    f.Close()
}



PHP: header("Content-Type: image/png");

$w = 256;
$h = 256;

$im = imagecreate($w, $h)
    or die("Cannot Initialize new GD image stream");

$color = array();
for($i=0;$i<256;$i++)
{
        array_push($color,imagecolorallocate($im,sin(($i)*(2*3.14/256))*128+128,$i/2,$i));
}

for($i=0;$i<$w;$i++)
{
        for($j=0;$j<$h;$j++)
        {
                imagesetpixel($im,$i,$j,$color[$i^$j]);
        }
}

imagepng($im);
imagedestroy($im);
Task: Munching squares





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class XorPattern extends JFrame{
    private JPanel xorPanel;

    public XorPattern(){
        xorPanel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                for(int y = 0; y < getHeight();y++){
                    for(int x = 0; x < getWidth();x++){
                        g.setColor(new Color(0, (x ^ y) % 256, 0));
                        g.drawLine(x, y, x, y);
                    }
                }
            }
        };
        add(xorPanel);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args){
        new XorPattern();
    }
}


PHP: header("Content-Type: image/png");

$w = 256;
$h = 256;

$im = imagecreate($w, $h)
    or die("Cannot Initialize new GD image stream");

$color = array();
for($i=0;$i<256;$i++)
{
        array_push($color,imagecolorallocate($im,sin(($i)*(2*3.14/256))*128+128,$i/2,$i));
}

for($i=0;$i<$w;$i++)
{
        for($j=0;$j<$h;$j++)
        {
                imagesetpixel($im,$i,$j,$color[$i^$j]);
        }
}

imagepng($im);
imagedestroy($im);
Task: Munching squares






PHP: header("Content-Type: image/png");

$w = 256;
$h = 256;

$im = imagecreate($w, $h)
    or die("Cannot Initialize new GD image stream");

$color = array();
for($i=0;$i<256;$i++)
{
        array_push($color,imagecolorallocate($im,sin(($i)*(2*3.14/256))*128+128,$i/2,$i));
}

for($i=0;$i<$w;$i++)
{
        for($j=0;$j<$h;$j++)
        {
                imagesetpixel($im,$i,$j,$color[$i^$j]);
        }
}

imagepng($im);
imagedestroy($im);


Python: import Image, ImageDraw

image = Image.new("RGB", (256, 256))
drawingTool = ImageDraw.Draw(image)

for x in range(256):
    for y in range(256):
        drawingTool.point((x, y), (0, x^y, 0))

del drawingTool
image.save("xorpic.png", "PNG")
Task: Munching squares






PHP: header("Content-Type: image/png");

$w = 256;
$h = 256;

$im = imagecreate($w, $h)
    or die("Cannot Initialize new GD image stream");

$color = array();
for($i=0;$i<256;$i++)
{
        array_push($color,imagecolorallocate($im,sin(($i)*(2*3.14/256))*128+128,$i/2,$i));
}

for($i=0;$i<$w;$i++)
{
        for($j=0;$j<$h;$j++)
        {
                imagesetpixel($im,$i,$j,$color[$i^$j]);
        }
}

imagepng($im);
imagedestroy($im);



VB: 
Public Class MunchingSquares
    Const xsize = 256
    Dim BMP As New Drawing.Bitmap(xsize, xsize)
    Dim GFX As Graphics = Graphics.FromImage(BMP)

    Private Sub MunchingSquares_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        
        Dim MyGraph As Graphics = Me.CreateGraphics
        Dim nColor As Color
        Dim i, j, cp As Integer
        xPictureBox.Image = BMP
        For i = 0 To xsize - 1
            For j = 0 To xsize - 1
                cp = i Xor j
                nColor = Color.FromArgb(cp, 0, cp)
                BMP.SetPixel(i, j, nColor)
            Next j
        Next i
    End Sub 

End Class