WeixiangYan/CodeTransOcean huggingface dataset:
Task: Split a character string based on change of character




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(scc(`gHHH5YY++
}

func scc(s string) string {
    if len(s) < 2 {
        return s
    }
    var b strings.Builder
    p := s[0]
    b.WriteByte(p)
    for _, c := range []byte(s[1:]) {
        if c != p {
            b.WriteString(", ")
        }
        b.WriteByte(c)
        p = c
    }
    return b.String()
}


Java: package org.rosettacode;

import java.util.ArrayList;
import java.util.List;



public class SplitStringByCharacterChange {
    
    public static void main(String... args){
        for (String string : args){
            
            List<String> resultStrings = splitStringByCharacter(string);
            String output = formatList(resultStrings);
            System.out.println(output);
        }
    }
    
    
    public static List<String> splitStringByCharacter(String string){
        
        List<String> resultStrings = new ArrayList<>();
        StringBuilder currentString = new StringBuilder();
        
        for (int pointer = 0; pointer < string.length(); pointer++){
            
            currentString.append(string.charAt(pointer));
            
            if (pointer == string.length() - 1 
                    || currentString.charAt(0) != string.charAt(pointer + 1)) {
                resultStrings.add(currentString.toString());
                currentString = new StringBuilder();
            }
        }
        
        return resultStrings;
    }
    
    
    public static String formatList(List<String> list){
        
        StringBuilder output = new StringBuilder();
        
        for (int pointer = 0; pointer < list.size(); pointer++){
            output.append(list.get(pointer));
            
            if (pointer != list.size() - 1){
                output.append(", ");
            }
        }
        
        return output.toString();
    }
}
Task: Split a character string based on change of character




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(scc(`gHHH5YY++
}

func scc(s string) string {
    if len(s) < 2 {
        return s
    }
    var b strings.Builder
    p := s[0]
    b.WriteByte(p)
    for _, c := range []byte(s[1:]) {
        if c != p {
            b.WriteString(", ")
        }
        b.WriteByte(c)
        p = c
    }
    return b.String()
}




Python: from itertools import groupby

def splitter(text):
    return ', '.join(''.join(group) for key, group in groupby(text))

if __name__ == '__main__':
    txt = 'gHHH5YY++///\\'      
    print(f'Input: {txt}\nSplit: {splitter(txt)}')
Task: Split a character string based on change of character


C++: 
#include<string>
#include<iostream>

auto split(const std::string& input, const std::string& delim){
	std::string res;
	for(auto ch : input){
		if(!res.empty() && ch != res.back())
			res += delim;
		res += ch;
	}
	return res;
}

int main(){
	std::cout << split("gHHH5  ))YY++,,,
}






Python: from itertools import groupby

def splitter(text):
    return ', '.join(''.join(group) for key, group in groupby(text))

if __name__ == '__main__':
    txt = 'gHHH5YY++///\\'      
    print(f'Input: {txt}\nSplit: {splitter(txt)}')
Task: Mandelbrot set

C:  
 #include <stdio.h>
 #include <math.h>
 int main()
 {
          
        int iX,iY;
        const int iXmax = 800; 
        const int iYmax = 800;
        
        double Cx,Cy;
        const double CxMin=-2.5;
        const double CxMax=1.5;
        const double CyMin=-2.0;
        const double CyMax=2.0;
        
        double PixelWidth=(CxMax-CxMin)/iXmax;
        double PixelHeight=(CyMax-CyMin)/iYmax;
        
        
        const int MaxColorComponentValue=255; 
        FILE * fp;
        char *filename="new1.ppm";
        char *comment="# ";
        static unsigned char color[3];
        
        double Zx, Zy;
        double Zx2, Zy2; 
        
        int Iteration;
        const int IterationMax=200;
        
        const double EscapeRadius=2;
        double ER2=EscapeRadius*EscapeRadius;
        
        fp= fopen(filename,"wb"); 
        
        fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
        
        for(iY=0;iY<iYmax;iY++)
        {
             Cy=CyMin + iY*PixelHeight;
             if (fabs(Cy)< PixelHeight/2) Cy=0.0; 
             for(iX=0;iX<iXmax;iX++)
             {         
                        Cx=CxMin + iX*PixelWidth;
                        
                        Zx=0.0;
                        Zy=0.0;
                        Zx2=Zx*Zx;
                        Zy2=Zy*Zy;
                        
                        for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++)
                        {
                            Zy=2*Zx*Zy + Cy;
                            Zx=Zx2-Zy2 +Cx;
                            Zx2=Zx*Zx;
                            Zy2=Zy*Zy;
                        };
                        
                        if (Iteration==IterationMax)
                        { 
                           color[0]=0;
                           color[1]=0;
                           color[2]=0;                           
                        }
                     else 
                        { 
                             color[0]=255; 
                             color[1]=255;   
                             color[2]=255;
                        };
                        
                        fwrite(color,1,3,fp);
                }
        }
        fclose(fp);
        return 0;
 }




Go: package main

import "fmt"
import "math/cmplx"

func mandelbrot(a complex128) (z complex128) {
    for i := 0; i < 50; i++ {
        z = z*z + a
    }
    return
}

func main() {
    for y := 1.0; y >= -1.0; y -= 0.05 {
        for x := -2.0; x <= 0.5; x += 0.0315 {
            if cmplx.Abs(mandelbrot(complex(x, y))) < 2 {
                fmt.Print("*")
            } else {
                fmt.Print(" ")
            }
        }
        fmt.Println("")
    }
}
Task: Mandelbrot set


C++: #include <cstdlib>
#include <complex>


template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_first_dimension(ElementType (&a)[dim1][dim2])
{
  return dim1;
}

template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_second_dimension(ElementType (&a)[dim1][dim2])
{
  return dim2;
}


template<typename ColorType, typename ImageType>
 void draw_Mandelbrot(ImageType& image,                                   
                      ColorType set_color, ColorType non_set_color,       
                      double cxmin, double cxmax, double cymin, double cymax,
                      unsigned int max_iterations)                          
{
  std::size_t const ixsize = get_first_dimension(image);
  std::size_t const iysize = get_first_dimension(image);
  for (std::size_t ix = 0; ix < ixsize; ++ix)
    for (std::size_t iy = 0; iy < iysize; ++iy)
    {
      std::complex<double> c(cxmin + ix/(ixsize-1.0)*(cxmax-cxmin), cymin + iy/(iysize-1.0)*(cymax-cymin));
      std::complex<double> z = 0;
      unsigned int iterations;

      for (iterations = 0; iterations < max_iterations && std::abs(z) < 2.0; ++iterations) 
        z = z*z + c;

      image[ix][iy] = (iterations == max_iterations) ? set_color : non_set_color;

    }
}



Go: package main

import "fmt"
import "math/cmplx"

func mandelbrot(a complex128) (z complex128) {
    for i := 0; i < 50; i++ {
        z = z*z + a
    }
    return
}

func main() {
    for y := 1.0; y >= -1.0; y -= 0.05 {
        for x := -2.0; x <= 0.5; x += 0.0315 {
            if cmplx.Abs(mandelbrot(complex(x, y))) < 2 {
                fmt.Print("*")
            } else {
                fmt.Print(" ")
            }
        }
        fmt.Println("")
    }
}
Task: Mandelbrot set


C++: #include <cstdlib>
#include <complex>


template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_first_dimension(ElementType (&a)[dim1][dim2])
{
  return dim1;
}

template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_second_dimension(ElementType (&a)[dim1][dim2])
{
  return dim2;
}


template<typename ColorType, typename ImageType>
 void draw_Mandelbrot(ImageType& image,                                   
                      ColorType set_color, ColorType non_set_color,       
                      double cxmin, double cxmax, double cymin, double cymax,
                      unsigned int max_iterations)                          
{
  std::size_t const ixsize = get_first_dimension(image);
  std::size_t const iysize = get_first_dimension(image);
  for (std::size_t ix = 0; ix < ixsize; ++ix)
    for (std::size_t iy = 0; iy < iysize; ++iy)
    {
      std::complex<double> c(cxmin + ix/(ixsize-1.0)*(cxmax-cxmin), cymin + iy/(iysize-1.0)*(cymax-cymin));
      std::complex<double> z = 0;
      unsigned int iterations;

      for (iterations = 0; iterations < max_iterations && std::abs(z) < 2.0; ++iterations) 
        z = z*z + c;

      image[ix][iy] = (iterations == max_iterations) ? set_color : non_set_color;

    }
}




Java: import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

public class Mandelbrot extends JFrame {

    private final int MAX_ITER = 570;
    private final double ZOOM = 150;
    private BufferedImage I;
    private double zx, zy, cX, cY, tmp;

    public Mandelbrot() {
        super("Mandelbrot Set");
        setBounds(100, 100, 800, 600);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        I = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
        for (int y = 0; y < getHeight(); y++) {
            for (int x = 0; x < getWidth(); x++) {
                zx = zy = 0;
                cX = (x - 400) / ZOOM;
                cY = (y - 300) / ZOOM;
                int iter = MAX_ITER;
                while (zx * zx + zy * zy < 4 && iter > 0) {
                    tmp = zx * zx - zy * zy + cX;
                    zy = 2.0 * zx * zy + cY;
                    zx = tmp;
                    iter--;
                }
                I.setRGB(x, y, iter | (iter << 8));
            }
        }
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(I, 0, 0, this);
    }

    public static void main(String[] args) {
        new Mandelbrot().setVisible(true);
    }
}
Task: Mandelbrot set


C++: #include <cstdlib>
#include <complex>


template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_first_dimension(ElementType (&a)[dim1][dim2])
{
  return dim1;
}

template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_second_dimension(ElementType (&a)[dim1][dim2])
{
  return dim2;
}


template<typename ColorType, typename ImageType>
 void draw_Mandelbrot(ImageType& image,                                   
                      ColorType set_color, ColorType non_set_color,       
                      double cxmin, double cxmax, double cymin, double cymax,
                      unsigned int max_iterations)                          
{
  std::size_t const ixsize = get_first_dimension(image);
  std::size_t const iysize = get_first_dimension(image);
  for (std::size_t ix = 0; ix < ixsize; ++ix)
    for (std::size_t iy = 0; iy < iysize; ++iy)
    {
      std::complex<double> c(cxmin + ix/(ixsize-1.0)*(cxmax-cxmin), cymin + iy/(iysize-1.0)*(cymax-cymin));
      std::complex<double> z = 0;
      unsigned int iterations;

      for (iterations = 0; iterations < max_iterations && std::abs(z) < 2.0; ++iterations) 
        z = z*z + c;

      image[ix][iy] = (iterations == max_iterations) ? set_color : non_set_color;

    }
}






Python: i = di = dj = 0
fn1, fn2, fn3 = random(20), random(20), random(20)
f = 10
    
def setup():
    global zmx1, zmx2, zmy1, zmy2
    size(500, 500)
    zmx1 = int(width / 4)
    zmx2 = 2
    zmy1 = int(height / 4)
    zmy2 = 2


def draw():
    global i

    if i <= width:
        i += 1
    x = float(i + di) / zmx1 - zmx2
    for j in range(height + 1):
        y = zmy2 - float(j + dj) / zmy1
        zr = zi = zr2 = zi2 = 0
        cr, ci = x, y
        n = 1
        while n < 200 and (zr2 + zi2) < 4:
            zi2 = zi * zi
            zr2 = zr * zr
            zi = 2 * zi * zr + ci
            zr = zr2 - zi2 + cr
            n += 1

        re = (n * fn1) % 255
        gr = (n * fn2) % 255
        bl = (n * fn3) % 255
        stroke(re, gr, bl)
        point(i, j)


def mousePressed():
    global zmx1, zmx2, zmy1, zmy2, di, dj
    global i, j
    background(200)
    xt, yt = mouseX, mouseY
    di = di + xt - width / 2.
    dj = dj + yt - height / 2.
    zmx1 = zmx1 * f
    zmx2 = zmx2 * (1. / f)
    zmy1 = zmy1 * f
    zmy2 = zmy2 * (1. / f)
    di, dj = di * f, dj * f
    i = j = 0
Task: Mandelbrot set




Go: package main

import "fmt"
import "math/cmplx"

func mandelbrot(a complex128) (z complex128) {
    for i := 0; i < 50; i++ {
        z = z*z + a
    }
    return
}

func main() {
    for y := 1.0; y >= -1.0; y -= 0.05 {
        for x := -2.0; x <= 0.5; x += 0.0315 {
            if cmplx.Abs(mandelbrot(complex(x, y))) < 2 {
                fmt.Print("*")
            } else {
                fmt.Print(" ")
            }
        }
        fmt.Println("")
    }
}


Java: import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

public class Mandelbrot extends JFrame {

    private final int MAX_ITER = 570;
    private final double ZOOM = 150;
    private BufferedImage I;
    private double zx, zy, cX, cY, tmp;

    public Mandelbrot() {
        super("Mandelbrot Set");
        setBounds(100, 100, 800, 600);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        I = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
        for (int y = 0; y < getHeight(); y++) {
            for (int x = 0; x < getWidth(); x++) {
                zx = zy = 0;
                cX = (x - 400) / ZOOM;
                cY = (y - 300) / ZOOM;
                int iter = MAX_ITER;
                while (zx * zx + zy * zy < 4 && iter > 0) {
                    tmp = zx * zx - zy * zy + cX;
                    zy = 2.0 * zx * zy + cY;
                    zx = tmp;
                    iter--;
                }
                I.setRGB(x, y, iter | (iter << 8));
            }
        }
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(I, 0, 0, this);
    }

    public static void main(String[] args) {
        new Mandelbrot().setVisible(true);
    }
}
Task: Mandelbrot set





Java: import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

public class Mandelbrot extends JFrame {

    private final int MAX_ITER = 570;
    private final double ZOOM = 150;
    private BufferedImage I;
    private double zx, zy, cX, cY, tmp;

    public Mandelbrot() {
        super("Mandelbrot Set");
        setBounds(100, 100, 800, 600);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        I = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
        for (int y = 0; y < getHeight(); y++) {
            for (int x = 0; x < getWidth(); x++) {
                zx = zy = 0;
                cX = (x - 400) / ZOOM;
                cY = (y - 300) / ZOOM;
                int iter = MAX_ITER;
                while (zx * zx + zy * zy < 4 && iter > 0) {
                    tmp = zx * zx - zy * zy + cX;
                    zy = 2.0 * zx * zy + cY;
                    zx = tmp;
                    iter--;
                }
                I.setRGB(x, y, iter | (iter << 8));
            }
        }
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(I, 0, 0, this);
    }

    public static void main(String[] args) {
        new Mandelbrot().setVisible(true);
    }
}



Python: i = di = dj = 0
fn1, fn2, fn3 = random(20), random(20), random(20)
f = 10
    
def setup():
    global zmx1, zmx2, zmy1, zmy2
    size(500, 500)
    zmx1 = int(width / 4)
    zmx2 = 2
    zmy1 = int(height / 4)
    zmy2 = 2


def draw():
    global i

    if i <= width:
        i += 1
    x = float(i + di) / zmx1 - zmx2
    for j in range(height + 1):
        y = zmy2 - float(j + dj) / zmy1
        zr = zi = zr2 = zi2 = 0
        cr, ci = x, y
        n = 1
        while n < 200 and (zr2 + zi2) < 4:
            zi2 = zi * zi
            zr2 = zr * zr
            zi = 2 * zi * zr + ci
            zr = zr2 - zi2 + cr
            n += 1

        re = (n * fn1) % 255
        gr = (n * fn2) % 255
        bl = (n * fn3) % 255
        stroke(re, gr, bl)
        point(i, j)


def mousePressed():
    global zmx1, zmx2, zmy1, zmy2, di, dj
    global i, j
    background(200)
    xt, yt = mouseX, mouseY
    di = di + xt - width / 2.
    dj = dj + yt - height / 2.
    zmx1 = zmx1 * f
    zmx2 = zmx2 * (1. / f)
    zmy1 = zmy1 * f
    zmy2 = zmy2 * (1. / f)
    di, dj = di * f, dj * f
    i = j = 0
Task: Mandelbrot set




Go: package main

import "fmt"
import "math/cmplx"

func mandelbrot(a complex128) (z complex128) {
    for i := 0; i < 50; i++ {
        z = z*z + a
    }
    return
}

func main() {
    for y := 1.0; y >= -1.0; y -= 0.05 {
        for x := -2.0; x <= 0.5; x += 0.0315 {
            if cmplx.Abs(mandelbrot(complex(x, y))) < 2 {
                fmt.Print("*")
            } else {
                fmt.Print(" ")
            }
        }
        fmt.Println("")
    }
}




Python: i = di = dj = 0
fn1, fn2, fn3 = random(20), random(20), random(20)
f = 10
    
def setup():
    global zmx1, zmx2, zmy1, zmy2
    size(500, 500)
    zmx1 = int(width / 4)
    zmx2 = 2
    zmy1 = int(height / 4)
    zmy2 = 2


def draw():
    global i

    if i <= width:
        i += 1
    x = float(i + di) / zmx1 - zmx2
    for j in range(height + 1):
        y = zmy2 - float(j + dj) / zmy1
        zr = zi = zr2 = zi2 = 0
        cr, ci = x, y
        n = 1
        while n < 200 and (zr2 + zi2) < 4:
            zi2 = zi * zi
            zr2 = zr * zr
            zi = 2 * zi * zr + ci
            zr = zr2 - zi2 + cr
            n += 1

        re = (n * fn1) % 255
        gr = (n * fn2) % 255
        bl = (n * fn3) % 255
        stroke(re, gr, bl)
        point(i, j)


def mousePressed():
    global zmx1, zmx2, zmy1, zmy2, di, dj
    global i, j
    background(200)
    xt, yt = mouseX, mouseY
    di = di + xt - width / 2.
    dj = dj + yt - height / 2.
    zmx1 = zmx1 * f
    zmx2 = zmx2 * (1. / f)
    zmy1 = zmy1 * f
    zmy2 = zmy2 * (1. / f)
    di, dj = di * f, dj * f
    i = j = 0
Task: Mandelbrot set

C:  
 #include <stdio.h>
 #include <math.h>
 int main()
 {
          
        int iX,iY;
        const int iXmax = 800; 
        const int iYmax = 800;
        
        double Cx,Cy;
        const double CxMin=-2.5;
        const double CxMax=1.5;
        const double CyMin=-2.0;
        const double CyMax=2.0;
        
        double PixelWidth=(CxMax-CxMin)/iXmax;
        double PixelHeight=(CyMax-CyMin)/iYmax;
        
        
        const int MaxColorComponentValue=255; 
        FILE * fp;
        char *filename="new1.ppm";
        char *comment="# ";
        static unsigned char color[3];
        
        double Zx, Zy;
        double Zx2, Zy2; 
        
        int Iteration;
        const int IterationMax=200;
        
        const double EscapeRadius=2;
        double ER2=EscapeRadius*EscapeRadius;
        
        fp= fopen(filename,"wb"); 
        
        fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
        
        for(iY=0;iY<iYmax;iY++)
        {
             Cy=CyMin + iY*PixelHeight;
             if (fabs(Cy)< PixelHeight/2) Cy=0.0; 
             for(iX=0;iX<iXmax;iX++)
             {         
                        Cx=CxMin + iX*PixelWidth;
                        
                        Zx=0.0;
                        Zy=0.0;
                        Zx2=Zx*Zx;
                        Zy2=Zy*Zy;
                        
                        for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++)
                        {
                            Zy=2*Zx*Zy + Cy;
                            Zx=Zx2-Zy2 +Cx;
                            Zx2=Zx*Zx;
                            Zy2=Zy*Zy;
                        };
                        
                        if (Iteration==IterationMax)
                        { 
                           color[0]=0;
                           color[1]=0;
                           color[2]=0;                           
                        }
                     else 
                        { 
                             color[0]=255; 
                             color[1]=255;   
                             color[2]=255;
                        };
                        
                        fwrite(color,1,3,fp);
                }
        }
        fclose(fp);
        return 0;
 }






PHP: $min_x=-2;
$max_x=1;
$min_y=-1;
$max_y=1;

$dim_x=400;
$dim_y=300;

$im = @imagecreate($dim_x, $dim_y)
  or die("Cannot Initialize new GD image stream");
header("Content-Type: image/png");
$black_color = imagecolorallocate($im, 0, 0, 0);
$white_color = imagecolorallocate($im, 255, 255, 255);

for($y=0;$y<=$dim_y;$y++) {
  for($x=0;$x<=$dim_x;$x++) {
    $c1=$min_x+($max_x-$min_x)/$dim_x*$x;
    $c2=$min_y+($max_y-$min_y)/$dim_y*$y;

    $z1=0;
    $z2=0;

    for($i=0;$i<100;$i++) {
      $new1=$z1*$z1-$z2*$z2+$c1;
      $new2=2*$z1*$z2+$c2;
      $z1=$new1;
      $z2=$new2;
      if($z1*$z1+$z2*$z2>=4) {
        break;
      }
    }
    if($i<100) {
      imagesetpixel ($im, $x, $y, $white_color);
    }
  }
}

imagepng($im);
imagedestroy($im);
Task: Mandelbrot set


C++: #include <cstdlib>
#include <complex>


template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_first_dimension(ElementType (&a)[dim1][dim2])
{
  return dim1;
}

template<typename ElementType, std::size_t dim1, std::size_t dim2>
 std::size_t get_second_dimension(ElementType (&a)[dim1][dim2])
{
  return dim2;
}


template<typename ColorType, typename ImageType>
 void draw_Mandelbrot(ImageType& image,                                   
                      ColorType set_color, ColorType non_set_color,       
                      double cxmin, double cxmax, double cymin, double cymax,
                      unsigned int max_iterations)                          
{
  std::size_t const ixsize = get_first_dimension(image);
  std::size_t const iysize = get_first_dimension(image);
  for (std::size_t ix = 0; ix < ixsize; ++ix)
    for (std::size_t iy = 0; iy < iysize; ++iy)
    {
      std::complex<double> c(cxmin + ix/(ixsize-1.0)*(cxmax-cxmin), cymin + iy/(iysize-1.0)*(cymax-cymin));
      std::complex<double> z = 0;
      unsigned int iterations;

      for (iterations = 0; iterations < max_iterations && std::abs(z) < 2.0; ++iterations) 
        z = z*z + c;

      image[ix][iy] = (iterations == max_iterations) ? set_color : non_set_color;

    }
}





PHP: $min_x=-2;
$max_x=1;
$min_y=-1;
$max_y=1;

$dim_x=400;
$dim_y=300;

$im = @imagecreate($dim_x, $dim_y)
  or die("Cannot Initialize new GD image stream");
header("Content-Type: image/png");
$black_color = imagecolorallocate($im, 0, 0, 0);
$white_color = imagecolorallocate($im, 255, 255, 255);

for($y=0;$y<=$dim_y;$y++) {
  for($x=0;$x<=$dim_x;$x++) {
    $c1=$min_x+($max_x-$min_x)/$dim_x*$x;
    $c2=$min_y+($max_y-$min_y)/$dim_y*$y;

    $z1=0;
    $z2=0;

    for($i=0;$i<100;$i++) {
      $new1=$z1*$z1-$z2*$z2+$c1;
      $new2=2*$z1*$z2+$c2;
      $z1=$new1;
      $z2=$new2;
      if($z1*$z1+$z2*$z2>=4) {
        break;
      }
    }
    if($i<100) {
      imagesetpixel ($im, $x, $y, $white_color);
    }
  }
}

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