Open source software for numerical computation

Skip to main content

Create your own Season's Greetings with Scilab

ScilabSeasonsGreeting.png

With this Scilab script, create your own Season's Greeting, to share it with your friends:

0001  function Star(B, b, n, name)

 0002      colour = modulo(name, 128);

 0003      for p = n:-1:1

 0004          for q = 1:min(p,2):2^(p-1)*b

 0005             Z = B*exp(%i*q*%pi/2^(p-2)/b);

 0006              xfpolys(real(Z), imag(Z), [colour colour+8]);

 0007          end

 0008      end

 0009  endfunction

 0010 

 0011  txt = ["First Name"; "Date of Birth"];

 0012  sig = x_mdialog("Enter your info", txt, ["John"; "2017"]);

 0013  if ~isempty(sig) then

 0014     

 0015      year = evstr(sig(2));

 0016      n = modulo(year,3)+3;

 0017      b = modulo(year,6)+5;

 0018      name = sum(ascii(sig(1)));

 0019     

 0020      R = 1;

 0021      r = R/(2*cos(%pi/b));

 0022      B = [0 0; R*%i r*exp(%i*(%pi/2 + %pi/b)); r*exp(%i*(%pi/2 - %pi/b)) R*%i];

 0023      

 0024      f = figure("visible","off", ..

 0025      "figure_name", "",..

 0026      "color_map", jetcolormap(128),..

 0027      "menubar_visible", "off",..

 0028      "toolbar_visible", "off",..

 0029      "infobar_visible", "off");

 0030      f.background = color("white");

 0031     

 0032      imageWidth = 138;

 0033      imageHeight = 69;

 0034     

 0035      try

 0036          // getURL requires an internet connection

 0037          URL = getURL("http://scilab.io/wp-content/uploads/2016/05/logo_scilab.png");

 0038          uicontrol("Parent", f, ..

 0039          "Style", "image", ..

 0040          "Position", [(f.axes_size(1)-imageWidth-20) imageHeight imageWidth imageHeight], ..

 0041          "Backgroundcolor",[1 1 1], ..

 0042          "String", URL);

 0043      catch

 0044      end

 0045     

 0046      f.visible = "on";

 0047      plot2d(%inf, %inf, frameflag = 3, rect = [-R,-R,R,R], axesflag = 0);

 0048      Star(B, b, n, name);

 0049      a = gca();

 0050      t = a.title;

 0051      t.font_size = 4;

 0052      t.font_style = 5;

 0053      t.text = sig(1)+"''s Season''s Greetings (proudly made with Scilab)";

 0054     

 0055      uicontrol("Parent", f, ..

 0056      "Style", "pushbutton", ..

 0057      "Position", [30 imageHeight 100 40], ..

 0058      "String", "Save to PNG",..

 0059      "Callback","savePNG()");

 0060     

 0061      function savePNG()

 0062          File = uiputfile("*.png");

 0063          if isempty(File) then

 0064              return;

 0065          end

 0066          xs2png(f, File+".png");

 0067      endfunction

 0068     

 0069  end