+ Reply to Thread
Results 1 to 5 of 5

Thread: Flag of East Turkestan (MATLAB/Octave code)

  1. #1
    Unregistered Guest

    Default Flag of East Turkestan (MATLAB/Octave code)

    function flag_of_east_turkistan(varargin)
    % FLAG_OF_TURKY A function of create the image of turkish flag.

    % G is width of the flag. (The unit is pixel.)

    % Example:
    % flag_of_east_turkistan
    %
    % G=4000;
    % flag_of_east_turkistan(G);

    % Developed by an uyghur, February 18, 2018
    % https://en.wikipedia.org/wiki/Flag_of_East_Turkestan

    nVarargs = length(varargin);
    if nVarargs==0
    G=7600;
    elseif nVarargs==1
    G=varargin{1};
    else
    return
    end


    A=G/2;
    B=G/2;
    C=G/16;
    D=G*(2/5);
    E=G/3;
    F=G/4;
    L=round(G*1.5);
    M=round(G/30);

    % background and foreground color
    color_of_background=[85;151;226];
    foreground=[255 255 255];


    % Create moon
    Binary_I_moon=moon(A,B,C,D,G,L);

    % Create star
    numberOfPoints = 5;
    rotationAngle = pi;
    xCenter = A+C-D/2+E+F/2;
    yCenter = G/2;
    % Define distance from the arm tip to the center of star.
    amplitude = F/2;
    Binary_I_star=star(xCenter,yCenter,numberOfPoints, rotationAngle,amplitude,G,L);

    % Create background image
    I1=ones(G,L,1)*color_of_background(1);
    I2=ones(G,L,1)*color_of_background(2);
    I3=ones(G,L,1)*color_of_background(3);

    % plot moon
    I1(Binary_I_moon==1)=foreground(1);
    I2(Binary_I_moon==1)=foreground(2);
    I3(Binary_I_moon==1)=foreground(3);

    % plot star
    I1(Binary_I_star==1)=foreground(1);
    I2(Binary_I_star==1)=foreground(2);
    I3(Binary_I_star==1)=foreground(3);

    % Create RGB image
    I=zeros(G,L,3);
    I(:,:,1)=I1;
    I(:,:,2)=I2;
    I(:,:,3)=I3;
    I=uint8(I);

    % show and write the image
    figure
    imshow(I)
    imwrite(I, 'flag_of_east_turkistan.png');
    end



    function Binary_I_moon=moon(A,B,C,D,G,L)
    Binary_I_moon=zeros(G,L,1);
    x=round(A);
    y=round(G/2);
    r=round(B/2);
    for xx=(x-r)x+r)
    for yy=(y-r)y+r)
    if (xx-x)^2+(yy-y)^2<r^2
    Binary_I_moon(yy,xx)=1;
    end

    end
    end

    x=round(A+C);
    y=round(G/2);
    r=round(D/2);

    for xx=(x-r)x+r)
    for yy=(y-r)y+r)
    if (xx-x)^2+(yy-y)^2<r^2
    Binary_I_moon(yy,xx)=0;
    end
    end
    end
    end


    function [xp,yp]=circle(x,y,r)
    %x and y are the coordinates of the center of the circle
    %r is the radius of the circle
    %0.01 is the angle step, bigger values will draw the circle faster but
    %you might notice imperfections (not very smooth)
    ang=0:0.001:2*pi;
    xp=r*cos(ang);
    yp=r*sin(ang);
    %plot(x+xp,y+yp);
    end

    function Binary_I=star(xCenter,yCenter,numberOfPoints,rotat ionAngle,amplitude,G,L)

    % Determine the angles that the arm tips are at
    theta = (0 : (numberOfPoints-1)/numberOfPoints*pi : (numberOfPoints-1)*pi) + rotationAngle ;

    % Get x and y coordinates of the arm tips.
    xp = amplitude .* cos(theta) + xCenter;
    yp = amplitude .* sin(theta) + yCenter;

    Binary_I_temp=zeros(G,L,1);
    Binary_I=zeros(G,L,1);
    area_x=floor(xCenter-amplitude)-1:ceil(xCenter+amplitude)+1;
    area_y=floor(yCenter-amplitude)-1:ceil(yCenter+amplitude)+1;
    Binary_I(area_y,area_x)=1;

    [x,y]=line_two_points(xp([1 2]),yp([1 2]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [x,y]=line_two_points(xp([2 3]),yp([2 3]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [x,y]=line_two_points(xp([3 4]),yp([3 4]));
    if ~isnan(y)
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    end
    [x,y]=line_two_points(xp([4 5]),yp([4 5]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [x,y]=line_two_points(xp([5 6]),yp([5 6]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end

    [y,x]=line_two_points(yp([1 2]),xp([1 2]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([2 3]),xp([2 3]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([3 4]),xp([3 4]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([4 5]),xp([4 5]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([5 6]),xp([5 6]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    for k=area_y
    for kk=area_x
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end
    for k=area_y
    for kk=area_x(end:-1:1)
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end

    for kk=area_x
    for k=area_y
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end
    for kk=area_x
    for k=area_y(end:-1:1)
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end
    end

    function [x,y]=line_two_points(p1,p2)
    [temp,min_id]=min(p1);
    if min_id==2
    p1=[p1(2) p1(1)];
    p2=[p2(2) p2(1)];
    end
    x=p1(1)1(2);
    y=p2(1)+(p2(2)-p2(1))*(x-p1(1))/(p1(2)-p1(1));
    x=round(x);
    y=round(y);
    end

  2. #2
    Unregistered Guest

    Default Flag of Turkey (MATLAB/Octave code)

    function flag_of_east_turkistan(varargin)
    % FLAG_OF_TURKY A function of create the image of turkish flag.

    % G is width of the flag. (The unit is pixel.)

    % Example:
    % flag_of_east_turkistan
    %
    % G=4000;
    % flag_of_east_turkistan(G);

    % Developed by an uyghur, February 18, 2018
    % https://en.wikipedia.org/wiki/Flag_of_East_Turkestan

    nVarargs = length(varargin);
    if nVarargs==0
    G=7600;
    elseif nVarargs==1
    G=varargin{1};
    else
    return
    end


    A=G/2;
    B=G/2;
    C=G/16;
    D=G*(2/5);
    E=G/3;
    F=G/4;
    L=round(G*1.5);
    M=round(G/30);

    % background and foreground color
    color_of_background=[85;151;226];
    foreground=[255 255 255];


    % Create moon
    Binary_I_moon=moon(A,B,C,D,G,L);

    % Create star
    numberOfPoints = 5;
    rotationAngle = pi;
    xCenter = A+C-D/2+E+F/2;
    yCenter = G/2;
    % Define distance from the arm tip to the center of star.
    amplitude = F/2;
    Binary_I_star=star(xCenter,yCenter,numberOfPoints, rotationAngle,amplitude,G,L);

    % Create background image
    I1=ones(G,L,1)*color_of_background(1);
    I2=ones(G,L,1)*color_of_background(2);
    I3=ones(G,L,1)*color_of_background(3);

    % plot moon
    I1(Binary_I_moon==1)=foreground(1);
    I2(Binary_I_moon==1)=foreground(2);
    I3(Binary_I_moon==1)=foreground(3);

    % plot star
    I1(Binary_I_star==1)=foreground(1);
    I2(Binary_I_star==1)=foreground(2);
    I3(Binary_I_star==1)=foreground(3);

    % Create RGB image
    I=zeros(G,L,3);
    I(:,:,1)=I1;
    I(:,:,2)=I2;
    I(:,:,3)=I3;
    I=uint8(I);

    % show and write the image
    figure
    imshow(I)
    imwrite(I, 'flag_of_east_turkistan.png');
    end



    function Binary_I_moon=moon(A,B,C,D,G,L)
    Binary_I_moon=zeros(G,L,1);
    x=round(A);
    y=round(G/2);
    r=round(B/2);
    for xx=(x-r)x+r)
    for yy=(y-r)y+r)
    if (xx-x)^2+(yy-y)^2<r^2
    Binary_I_moon(yy,xx)=1;
    end

    end
    end

    x=round(A+C);
    y=round(G/2);
    r=round(D/2);

    for xx=(x-r)x+r)
    for yy=(y-r)y+r)
    if (xx-x)^2+(yy-y)^2<r^2
    Binary_I_moon(yy,xx)=0;
    end
    end
    end
    end


    function [xp,yp]=circle(x,y,r)
    %x and y are the coordinates of the center of the circle
    %r is the radius of the circle
    %0.01 is the angle step, bigger values will draw the circle faster but
    %you might notice imperfections (not very smooth)
    ang=0:0.001:2*pi;
    xp=r*cos(ang);
    yp=r*sin(ang);
    %plot(x+xp,y+yp);
    end

    function Binary_I=star(xCenter,yCenter,numberOfPoints,rotat ionAngle,amplitude,G,L)

    % Determine the angles that the arm tips are at
    theta = (0 : (numberOfPoints-1)/numberOfPoints*pi : (numberOfPoints-1)*pi) + rotationAngle ;

    % Get x and y coordinates of the arm tips.
    xp = amplitude .* cos(theta) + xCenter;
    yp = amplitude .* sin(theta) + yCenter;

    Binary_I_temp=zeros(G,L,1);
    Binary_I=zeros(G,L,1);
    area_x=floor(xCenter-amplitude)-1:ceil(xCenter+amplitude)+1;
    area_y=floor(yCenter-amplitude)-1:ceil(yCenter+amplitude)+1;
    Binary_I(area_y,area_x)=1;

    [x,y]=line_two_points(xp([1 2]),yp([1 2]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [x,y]=line_two_points(xp([2 3]),yp([2 3]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [x,y]=line_two_points(xp([3 4]),yp([3 4]));
    if ~isnan(y)
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    end
    [x,y]=line_two_points(xp([4 5]),yp([4 5]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [x,y]=line_two_points(xp([5 6]),yp([5 6]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end

    [y,x]=line_two_points(yp([1 2]),xp([1 2]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([2 3]),xp([2 3]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([3 4]),xp([3 4]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([4 5]),xp([4 5]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    [y,x]=line_two_points(yp([5 6]),xp([5 6]));
    for k=1:length(x)
    Binary_I_temp(y(k),x(k))=1;
    end
    for k=area_y
    for kk=area_x
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end
    for k=area_y
    for kk=area_x(end:-1:1)
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end

    for kk=area_x
    for k=area_y
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end
    for kk=area_x
    for k=area_y(end:-1:1)
    if Binary_I_temp(k,kk)==1
    break
    else
    Binary_I(k,kk)=0;
    end
    end
    end
    end

    function [x,y]=line_two_points(p1,p2)
    [temp,min_id]=min(p1);
    if min_id==2
    p1=[p1(2) p1(1)];
    p2=[p2(2) p2(1)];
    end
    x=p1(1)1(2);
    y=p2(1)+(p2(2)-p2(1))*(x-p1(1))/(p1(2)-p1(1));
    x=round(x);
    y=round(y);
    end

  3. #3
    Unregistered Guest

    Default

    % the background color of Turkish flag is
    color_of_background=[227;10;23];


    % https://en.wikipedia.org/wiki/Flag_of_Turkey

  4. #4
    Unregistered Guest

    Default The SVG code of Flag of East Turkestan

    The SVG code of Flag of East Turkestan

    <svg
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns="http://www.w3.org/2000/svg"
    width="1500"
    height="1000"
    viewBox="0 0 1500 1000"
    id="East_Turkestan_Flag">
    <rect x="0" y="0" width="1500" height="1000" fill="#559ee2" stroke="none" />
    <circle cx="500" cy="500" r="250" fill="#ffffff" stroke="none" />
    <circle cx="562.5" cy="500" r="200" fill="#559ee2" stroke="none" />
    <polygon points="695.833333333333,500 921.960457630202,426.526843463441 782.206209036465,618.882064536894 782.206209036465,381.117935463106 921.960457630202,573.473156536559"
    style="fill:#ffffff;stroke:none;" />
    </svg>

  5. #5
    sarang Guest

    Default

    Great, nice job.

+ Reply to Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •