Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp1
  9. {
  10. public static class postscriptAssembler
  11. {
  12. public static List<string> defSquares(this List<string> program, int x, int y)
  13. {
  14. program.Add("/whiteSqure{" + $"{x} 0 rlineto 0 {y} rlineto {-x} 0 rlineto closepath 0.9 setgray fill" +"} def");
  15. program.Add("/blackSquare{" + $"{x} 0 rlineto 0 {y} rlineto {-x} 0 rlineto closepath 0 setgray fill" + "} def");
  16. return program;
  17. }
  18.  
  19. public static List<string> addHeader(this List<string> program)
  20. {
  21. program.Add("%! Adobe – PS");
  22. return program;
  23. }
  24.  
  25. public static List<string> addFooter(this List<string> program)
  26. {
  27. program.Add("showpage");
  28. return program;
  29. }
  30.  
  31. public static List<string> translate(this List<string> program, int x, int y)
  32. {
  33. program.Add($"{x} {y} translate");
  34. return program;
  35. }
  36. public static List<string> moveto(this List<string> program, int x, int y)
  37. {
  38. program.Add($"{x} {y} moveto");
  39. return program;
  40. }
  41. }
  42. class Program
  43. {
  44. private static void saveProgramToFile(List<string> program, string filename)
  45. {
  46. File.Delete($"E:\\{filename}.ps");
  47. File.AppendAllLines($"E:\\{filename}.ps", program);
  48. }
  49.  
  50. static void Main(string[] args)
  51. {
  52. List<string> program = new List<string>();
  53. int x = 16,
  54. y = 16;
  55.  
  56. int xLength = 400 / x;
  57. int yLength = 400 / y;
  58. int curposx = 0;
  59. int curposy = 0;
  60.  
  61. program = program
  62. .addHeader()
  63. .defSquares(xLength, yLength)
  64. .translate(50, 350);
  65.  
  66. for(int i = 0; i < x; i++)
  67. {
  68. curposy = 0;
  69. curposx += xLength;
  70. for (int j = 0; j < y; j++)
  71. {
  72. curposy += yLength;
  73. program = program.moveto(curposx, curposy);
  74. if (j%2==0)
  75. program[program.Count -1] += " blackSquare";
  76. else
  77. program[program.Count - 1] += " whiteSqure";
  78.  
  79. }
  80. }
  81.  
  82. program.addFooter();
  83.  
  84. saveProgramToFile(program, "zad5");
  85.  
  86. Console.Write(program);
  87. foreach (var line in program)
  88. Console.Write(line);
  89.  
  90. //Console.ReadLine();
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement