Generate Thumbnail

Mazes in SkiaSharp

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Maze Algorithm 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 public class MazeAlgorithm { Random random = new Random(); public int[,] GenerateMaze(int rows, int cols) { int[,] maze = new int[rows, cols]; // Initialize maze with walls for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { maze[i, j] = 1; } } // Set starting point maze[1, 1] = 0; DFS(maze, 1, 1); return maze; } void DFS(int[,] maze, int row, int col) { int[] directions = { 1, 2, 3, 4 }; Shuffle(directions); foreach (int dir in directions) { int[] dRow = { 0, 0, 1, -1 }; int[] dCol = { 1, -1, 0, 0 }; int newRow = row + 2 * dRow[dir - 1]; int newCol = col + 2 * dCol[dir - 1]; if (newRow > 0 && newRow < maze.GetLength(0) - 1 && newCol > 0 && newCol < maze.GetLength(1) - 1 && maze[newRow, newCol] == 1) { maze[row + dRow[dir - 1], col + dCol[dir - 1]] = 0; maze[newRow, newCol] = 0; DFS(maze, newRow, newCol); } } } void Shuffle(int[] array) { int n = array.Length; for (int i = 0; i < n; i++) { int r = i + random.Next(n - i); int temp = array[r]; array[r] = array[i]; array[i] = temp; } } } Skia Sharp To Utilise maze Algorithm and Generate Maze Image 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Create an image and fill it blue int width = 1920; int height = 1080; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; int m= width/step, n=height/step; var ls = (new MazeAlgorithm()).GenerateMaze(m,n); ls[0,1]=0; for(var i=0; i<m;i++) { for(var j=0; j<n;j++) { paint.ColorF=(ls[i,j]==0)?SKColor.Parse("#ffffff"):SKColor.Parse("#000000"); canvas.DrawRect(i*step,j*step,step,step,paint); } } SKFileWStream fs = new("maze.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 19, 2024 · 2 min · 412 words · PrashantUnity
Generate Thumbnail

Mandelbrot in SkiaSharp

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Mandelbrot 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 // Create an image and fill it blue int width = 1920; int height = 1080; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; double zoom = 1; double moveX = -0.5; double moveY = 0; int maxIterations = 50; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double zx = 1.5 * (x - width / 2) / (0.5 * zoom * width) + moveX; double zy = (y - height / 2) / (0.5 * zoom * height) + moveY; double cx = zx; double cy = zy; int iteration = 0; double tmp; while ((zx * zx + zy * zy < 4) && (iteration < maxIterations)) { tmp = zx * zx - zy * zy + cx; zy = 2.0 * zx * zy + cy; zx = tmp; iteration++; } if (iteration == maxIterations) { canvas.DrawPoint(x, y, SKColors.Black); } else { // Colorize based on the number of iterations var color = SKColor.FromHsv(iteration % 256, 255, 255); canvas.DrawPoint(x, y, color); } } } SKFileWStream fs = new("mandelbrot.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 18, 2024 · 2 min · 284 words · PrashantUnity
Generate Thumbnail

CFD logo in SkiaSharp

Creating Logos with SkiaSharp LOGO on this website is generated using SkiaSharp Only Requirements Visual Studio Code (VS Code) Polyglot Notebook Extension A little bit of experience in C# For Basic/Installation please visit Basic Setup Code Install SkiaSharp 1 #r "nuget:SkiaSharp" Import SkiaSharp Library 1 using SkiaSharp; Code To Generate Logo Logo Dimention and Stuff 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 int width=700; int height=700; int step = 30; float textSize =128f; string fontFamilyName = "Arial"; string LogoText ="<CFD/>"; float shiftX=150; float dividerX=2.0f; float shiftY=38; float dividerY=3.0f; var left=width/dividerX -shiftX; var top=height/dividerY -shiftY; var right= textSize*3.95f; var bottom=textSize*4f; float targetWidth = 800; // desired width float targetHeight = 800; // desired height float offsetX = 800; // horizontal offset float offsetY = 800; Vapor Structure Path ...

June 17, 2024 · 3 min · 490 words · PrashantUnity
Download Logo

First app in VS (Ch. 2)

Create Your First C# Console Application in Visual Studio Follow these steps to create and run a simple C# console application in Visual Studio. Step 1: Create a New Project Open Visual Studio and click on Create a New Project. Step 2: Choose the Console App Template In the search bar, type Console. Select Console App (C#) from the results. Click Next at the bottom right of the window. ...

June 17, 2024 · 2 min · 248 words · PrashantUnity
Download Logo

First app with CLI (Ch. 2)

Create a C# Console Application Using the CLI Follow these steps to create and run a simple C# console application using the command line. Step 1: Open Terminal and Create a New Project Open your terminal and type the following command to create a new console application project named “HelloWorld”: 1 dotnet new console -o HelloWorld Step 2: Confirm Project Creation After pressing Enter, the command will generate a new project. You should see a confirmation message similar to the image below. ...

June 17, 2024 · 2 min · 256 words · PrashantUnity
Download Logo

First notebook app (Ch. 2)

Using Polyglot Notebook in VS Code Step-by-Step Guide 1. Install Polyglot Notebook Open VS Code. Press Control + Shift + X to open the Extensions view. Search for “Polyglot Notebook” or directly open the URL Polyglot Notebook Extension. Look for the extension logo as shown below and install it. 2. Create a New File Create a new file named HelloWorld.ipynb as shown in the image below. Double-click to open the file. ...

June 17, 2024 · 1 min · 150 words · PrashantUnity
Google Drive Logo

GitHub Actions data jobs

Create a New Console Project I am going to create a dotnet project to demonstrate this, but it is applicable for all other programming languages as well Open any folder, then open Terminal In Terminal, create a new dotnet console project using the below command 1 2 3 4 5 6 7 8 dotnet new console -n GitCiCd cd .\GitCiCd\ code . mkdir .github cd .\.github\ mkdir workflows cd .\workflows\ echo "" > "dotnet.yaml" In dotnet.yaml file Paste Below Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 name: workflows on: push: branches: [ "master" ] jobs: scrape_videos: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up .NET uses: actions/setup-dotnet@v2 with: dotnet-version: '8.0.x' # Use the latest .NET version - name: Restore dependencies run: dotnet restore - name: Build the project run: dotnet build --configuration Release - name: Run the scraping script run: dotnet run --project GetYoutubeVideo.csproj - name: Commit and Push Changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add Text.txt git commit -m "Update Text.txt list" git push Inside Program.cs file paste below code for. 1 2 3 4 5 6 7 8 9 10 11 var ls = Enumerable.Range(1,8).Select(i => i.ToString() + DateTime.Now).ToList(); SaveToFile(ls, "Text.txt"); static void SaveToFile(List<string> videos, string filePath) { using StreamWriter file = new(filePath); foreach (var video in videos) { file.WriteLine(video); } } The code Responsible for operation is below code 1 2 3 4 5 6 7 - name: Commit and Push Changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add Text.txt git commit -m "Update Text.txt list" git push Push to github Now Go to Repository Setting Tab ...

July 28, 2024 · 2 min · 356 words · PrashantUnity
Download Logo

C# basics (Ch. 3)

Comments in C# Comments are essential for making your code understandable. They can explain what your code does, which is helpful for anyone reading it (including yourself). Inline Comments: Use // for single-line comments. 1 // This is an inline comment. Multi-line Comments: Use /* */ for comments that span multiple lines. 1 2 3 4 /* This is a multi-line comment. It spans multiple lines. */ Semicolons In C#, every statement ends with a semicolon (;). This tells the compiler where a statement ends. ...

June 16, 2024 · 3 min · 461 words · PrashantUnity
Download Logo

Math in C# (Ch. 4)

C# Basic Operations and Type Conversions Basic Operations In C#, you can perform various arithmetic operations using standard operators. Here are some examples: 1 2 3 4 5 6 int additionResult = 10 + 5; // result will be 15 int subtractionResult = 20 - 8; // result will be 12 int multiplicationResult = 7 * 4; // result will be 28 int divisionResult = 15 / 3; // result will be 5 int remainder = 17 % 5; // remainder will be 2 float floatDivisionResult = 15f / 4f; // result will be 3.75 Understanding Assignment in Programming In general mathematics, equality signifies that the expression on the left side of the = is equivalent to the expression on the right side: ...

June 18, 2024 · 2 min · 417 words · PrashantUnity
Download Logo

CFD loading SVG

Loading Animation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg width="300" height="300" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"> <text x="1" y="29" font-size="7" fill="white" font-family="Ubuntu">CFD AI</text> <style> .spinner { animation: move 2.4s linear infinite; } .delay1 { animation-delay: -2.4s; fill: #9BFAFF; } .delay2 { animation-delay: -1.6s; fill: #FFBD4D; } .delay3 { animation-delay: -0.8s; fill: #FFF8B3; } @keyframes move { 0%, 8.33% { x: 2px; y: 2px; } 25% { x: 13px; y: 2px; } 33.3%, 50% { x: 13px; y: 13px; } 58.33%, 75% { x: 2px; y: 13px; } 83.33%, 100% { x: 2px; y: 2px; } } </style> <rect class="spinner delay1" x="2" y="2" rx="2" width="10" height="10"/> <rect class="spinner delay2" x="2" y="2" rx="2" width="10" height="10"/> <rect class="spinner delay3" x="2" y="2" rx="2" width="10" height="10"/> </svg>

July 24, 2024 · 1 min · 171 words · PrashantUnity