Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public static class postscriptAssembler
- {
- public static List<string> defSquares(this List<string> program, int x, int y)
- {
- program.Add("/whiteSqure{" + $"{x} 0 rlineto 0 {y} rlineto {-x} 0 rlineto closepath 0.9 setgray fill" +"} def");
- program.Add("/blackSquare{" + $"{x} 0 rlineto 0 {y} rlineto {-x} 0 rlineto closepath 0 setgray fill" + "} def");
- return program;
- }
- public static List<string> addHeader(this List<string> program)
- {
- program.Add("%! Adobe – PS");
- return program;
- }
- public static List<string> addFooter(this List<string> program)
- {
- program.Add("showpage");
- return program;
- }
- public static List<string> translate(this List<string> program, int x, int y)
- {
- program.Add($"{x} {y} translate");
- return program;
- }
- public static List<string> moveto(this List<string> program, int x, int y)
- {
- program.Add($"{x} {y} moveto");
- return program;
- }
- }
- class Program
- {
- private static void saveProgramToFile(List<string> program, string filename)
- {
- File.Delete($"E:\\{filename}.ps");
- File.AppendAllLines($"E:\\{filename}.ps", program);
- }
- static void Main(string[] args)
- {
- List<string> program = new List<string>();
- int x = 16,
- y = 16;
- int xLength = 400 / x;
- int yLength = 400 / y;
- int curposx = 0;
- int curposy = 0;
- program = program
- .addHeader()
- .defSquares(xLength, yLength)
- .translate(50, 350);
- for(int i = 0; i < x; i++)
- {
- curposy = 0;
- curposx += xLength;
- for (int j = 0; j < y; j++)
- {
- curposy += yLength;
- program = program.moveto(curposx, curposy);
- if (j%2==0)
- program[program.Count -1] += " blackSquare";
- else
- program[program.Count - 1] += " whiteSqure";
- }
- }
- program.addFooter();
- saveProgramToFile(program, "zad5");
- Console.Write(program);
- foreach (var line in program)
- Console.Write(line);
- //Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement