Guest User

Untitled

a guest
Jan 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. documentclass[standalone]
  2. usepackage{tikz}
  3. begin{document}
  4. begin{tikzpicture}[scale=0.2]
  5. coordinate (O) at (0,0);
  6. fill[red!70] (O) circle (20);
  7. fill[white] (O) circle (19);
  8. fill[yellow!70] (O) circle (18);
  9. fill[white] (O) circle (17);
  10. fill[red!70] (O) circle (16);
  11. fill[white] (O) circle (15);
  12. fill[yellow!70] (O) circle (14);
  13. fill[white] (O) circle (13);
  14. fill[red!70] (O) circle (12);
  15. fill[white] (O) circle (11);
  16. fill[yellow!70] (O) circle (10);
  17. fill[white] (O) circle (9);
  18. fill[red!70] (O) circle (8);
  19. fill[white] (O) circle (7);
  20. fill[yellow!70] (O) circle (6);
  21. fill[white] (O) circle (5);
  22. fill[red!70] (O) circle (4);
  23. fill[white] (O) circle (3);
  24. fill[yellow!70] (O) circle (2);
  25. fill[white] (O) circle (1);
  26. end{tikzpicture}
  27. end{document}
  28.  
  29. documentclass{standalone}
  30. usepackage{tikz}
  31.  
  32. begin{document}
  33. begin{tikzpicture}[mystyle/.style={circle,draw,fill=none,minimum size=20, line width = 8pt}]
  34. foreach x in {1,3,5,7,9,11,13,15,17,19}
  35. node [mystyle, minimum size = x cm, color =red!70] (2) at (0, 0) {};
  36. foreach x in {2,4,6,8,10,12,14,16,18, 20}
  37. node [mystyle, minimum size = x cm, color =yellow!50] (2) at (0, 0) {};
  38. end{tikzpicture}
  39. end{document}
  40.  
  41. using SkiaSharp; // needs skiasharp nuget
  42. using System.Diagnostics;
  43.  
  44.  
  45. class ConcentricCircle
  46. {
  47. static readonly SKPaint yellowStroke = new SKPaint
  48. {
  49. Style = SKPaintStyle.Stroke,
  50. Color = SKColors.Yellow,
  51. IsAntialias = true
  52. };
  53.  
  54.  
  55. static readonly SKPaint redStroke = new SKPaint
  56. {
  57. Style = SKPaintStyle.Stroke,
  58. Color = SKColors.Red,
  59. IsAntialias = true
  60. };
  61.  
  62. static readonly float scale = SKDocument.DefaultRasterDpi / 2.54f; // dots per cm
  63. static readonly float width = 6 * scale; // 6 cm
  64. static readonly float height = 6 * scale; // 6 cm
  65.  
  66. static float PtToCm(float pt) => pt / scale;
  67.  
  68.  
  69.  
  70. public static void Generate(string filename)
  71. {
  72. yellowStroke.StrokeWidth = PtToCm(4); // 4pt
  73. redStroke.StrokeWidth = PtToCm(4); // 4pt
  74.  
  75. using (var stream = new SKFileWStream($"{filename}.pdf"))
  76. using (var document = SKDocument.CreatePdf(stream))
  77. using (var canvas = document.BeginPage(width, height))
  78. {
  79.  
  80. // translate first and then scale, don't reverse!
  81. canvas.Translate(width / 2, height / 2);
  82. canvas.Scale(scale);
  83.  
  84. // draw a red circle
  85. for (int i = 0; i < 5; i++)
  86. {
  87. canvas.DrawCircle(0, 0, PtToCm(8) * (2 * i + 1), yellowStroke);
  88. canvas.DrawCircle(0, 0, PtToCm(8) * (2 * i + 2), redStroke);
  89. }
  90.  
  91. document.EndPage();
  92. }
  93. }
  94.  
  95. private static void Main()
  96. {
  97. string filename = nameof(ConcentricCircle);
  98. Generate(filename);
  99.  
  100. // convert to PNG with ImageMagick
  101. using (Process p = new Process())
  102. {
  103. p.StartInfo.FileName = "magick";
  104. p.StartInfo.Arguments = $"convert -compose copy -bordercolor red -border 2x2 -density 200 -alpha remove {filename}.pdf {filename}.png";
  105. p.Start();
  106. }
  107. }
  108. }
  109.  
  110. documentclass{standalone}
  111. usepackage{tikz}
  112.  
  113. begin{document}
  114. begin{tikzpicture}[mystyle/.style={circle,draw,fill=none,minimum size=20, line width = 8pt}]
  115. foreach x in {1,...,20}{
  116. pgfmathparse{isodd(x)}ifnumpgfmathresult=1defcurrcol{red!70}elsedefcurrcol{yellow!50}fi
  117. draw[line width=8pt,currcol] (0,0) circle (x cm);}
  118. end{tikzpicture}
  119. end{document}
Add Comment
Please, Sign In to add comment