{"id":23412653,"url":"https://github.com/joelumbley/draw-arc","last_synced_at":"2026-01-21T04:11:22.304Z","repository":{"id":268919725,"uuid":"905836755","full_name":"JoeLumbley/Draw-Arc","owner":"JoeLumbley","description":"This interactive application provides a visual demonstration of arcs drawn with various starting and sweep angles","archived":false,"fork":false,"pushed_at":"2024-12-22T16:33:26.000Z","size":121,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T04:11:12.646Z","etag":null,"topics":["arc","arcs","computer-graphics","draw","drawarc","drawing","gdi","gdi-plus","graphics","vb-net","visual-basic"],"latest_commit_sha":null,"homepage":"","language":"Visual Basic .NET","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JoeLumbley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-19T16:09:22.000Z","updated_at":"2024-12-22T16:33:29.000Z","dependencies_parsed_at":"2024-12-19T18:23:08.637Z","dependency_job_id":"939ffdd2-a537-44a9-8908-f3ce0107248a","html_url":"https://github.com/JoeLumbley/Draw-Arc","commit_stats":null,"previous_names":["joelumbley/draw-arc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JoeLumbley/Draw-Arc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FDraw-Arc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FDraw-Arc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FDraw-Arc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FDraw-Arc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoeLumbley","download_url":"https://codeload.github.com/JoeLumbley/Draw-Arc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FDraw-Arc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28625931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T02:47:06.670Z","status":"ssl_error","status_checked_at":"2026-01-21T02:45:44.886Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arc","arcs","computer-graphics","draw","drawarc","drawing","gdi","gdi-plus","graphics","vb-net","visual-basic"],"created_at":"2024-12-22T18:17:57.443Z","updated_at":"2026-01-21T04:11:22.289Z","avatar_url":"https://github.com/JoeLumbley.png","language":"Visual Basic .NET","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Draw Arc\n\nThis interactive application provides a visual demonstration of arcs drawn with various starting and sweep angles using GDI (Graphics Device Interface) graphics.\n\nIt aims to help users gain a deeper understanding of how angles affect the rendering of arcs in graphical applications.\n\n\n\n\n![003](https://github.com/user-attachments/assets/bde01867-02e5-4cb1-af6d-0ab1265832dd)\n\n\n\n\n\n\n\n## Features\n\n- **Interactive Visualization**: Adjust starting and sweep angles dynamically to see real-time changes in arc rendering.\n- **Intuitive Controls**: User-friendly interface for manipulating angles.\n- **Educational Tool**: Designed to help users grasp the concepts of angles in graphics programming.\n\n---\n\n## Code Walkthrough\n\n### **Imports**\n```vb\nImports System.Drawing.Drawing2D\n```\n-  This line imports the `System.Drawing.Drawing2D` namespace, which provides advanced 2D graphics functionality. It includes classes for drawing shapes, such as arcs and curves.\n\n### **Class Definition**\n```vb\nPublic Class Form1\n```\n-  This line defines a new class called `Form1`. A class is a blueprint for creating objects. Here, `Form1` is a form (window) in the application.\n\n### **Variable Declarations**\n```vb\nPrivate Context As BufferedGraphicsContext\nPrivate Buffer As BufferedGraphics\n```\n\n  - `Context`: This variable will hold the graphics context for buffered graphics, which helps in rendering graphics smoothly.\n  - `Buffer`: This variable is used to store the graphics buffer, which allows for double buffering to reduce flickering during drawing.\n\n### **Structure Definition**\n```vb\nPrivate Structure DisplayStructure\n    Public Location As Point\n    Public Text As String\n    Public Font As Font\nEnd Structure\n```\n\n  - This defines a structure called `DisplayStructure` that holds information about where to display text (`Location`), the text itself (`Text`), and the font used (`Font`).\n\n### **More Variable Declarations**\n```vb\nPrivate CodeDisplay As DisplayStructure\nPrivate CircleOfProgress As Rectangle\nPrivate CircleOfProgressPen As Pen\nPrivate CircleOfProgressBackgroundPen As Pen\n```\n\n  - `CodeDisplay`: An instance of `DisplayStructure` to display code-related information.\n  - `CircleOfProgress`: A rectangle that defines the area where the arc will be drawn.\n  - `CircleOfProgressPen` and `CircleOfProgressBackgroundPen`: Pens used to draw the arc and its background.\n\n```vb\nPrivate startAngle As Single = 0.0F\nPrivate sweepAngle As Single\n```\n\n  - `startAngle`: A variable representing the starting angle for the arc (0 degrees).\n  - `sweepAngle`: A variable that will hold the sweep angle, which determines how far the arc extends.\n\n### **String Format for Centering Text**\n```vb\nPrivate ReadOnly AlineCenterMiddle As New StringFormat With {\n    .Alignment = StringAlignment.Center,\n    .LineAlignment = StringAlignment.Center}\n```\n-  This creates a `StringFormat` object that centers text both horizontally and vertically.\n\n### **Form Load Event**\n```vb\nPrivate Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load\n    InitializeApp()\n    Debug.Print($\"Program running... {Now.ToShortTimeString}\")\nEnd Sub\n```\n  - This method is called when the form loads. It initializes the application by calling `InitializeApp()`.\n  - It also prints a message to the debug console indicating that the program is running, along with the current time.\n\n### **Form Resize Event**\n```vb\nPrivate Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize\n    If Not WindowState = FormWindowState.Minimized Then\n        ResizeCodeDisplay()\n        ResizeControls()\n        ResizeCircleOfProgress()\n        DisposeBuffer()\n    End If\nEnd Sub\n```\n\n  - This method handles the form's resize event. If the window is not minimized, it resizes various components of the form (like text display and controls) and disposes of the buffer to prepare for redrawing.\n\n### **Timer Tick Event**\n```vb\nPrivate Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick\n    If Not WindowState = FormWindowState.Minimized Then\n        UpdateCodeDisplay()\n        Invalidate() ' Calls OnPaint Sub\n    End If\nEnd Sub\n```\n\n  - This method is called every time the timer ticks (every 30 milliseconds, as set later). It updates the code display and triggers a repaint of the form.\n\n### **OnPaint Method**\n```vb\nProtected Overrides Sub OnPaint(ByVal e As PaintEventArgs)\n    AllocateBuffer(e)\n    DrawDisplays()\n    Buffer.Render(e.Graphics)\n    MyBase.OnPaint(e)\nEnd Sub\n```\n\n  - This method is overridden to perform custom painting. It allocates a graphics buffer, draws the displays, and then renders the buffer onto the form.\n\n### **TrackBar Scroll Events**\n```vb\nPrivate Sub StartAngleTrackBar_Scroll(sender As Object, e As EventArgs) Handles StartAngleTrackBar.Scroll\n    StartAngleLabel.Text = $\"Start Angle: {StartAngleTrackBar.Value}°\"\nEnd Sub\n\nPrivate Sub SweepAngleTrackBar_Scroll(sender As Object, e As EventArgs) Handles SweepAngleTrackBar.Scroll\n    SweepAngleLabel.Text = $\"Sweep Angle: {SweepAngleTrackBar.Value}°\"\nEnd Sub\n```\n\n  - These methods handle the scrolling of two trackbars (sliders) for adjusting the start angle and sweep angle. They update the corresponding labels to show the current angle values.\n\n### **Update Code Display Method**\n```vb\nPrivate Sub UpdateCodeDisplay()\n    CodeDisplay.Text = $\"Graphics.DrawArc(Pen, Rectangle, {StartAngleTrackBar.Value}, {SweepAngleTrackBar.Value})\"\nEnd Sub\n```\n\n  - This method updates the text displayed in the `CodeDisplay` structure to show the current code that would be used to draw the arc with the selected angles.\n\n### **OnPaintBackground Method**\n```vb\nProtected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)\n    'Intentionally left blank. Do not remove.\nEnd Sub\n```\n\n  - This method is overridden but intentionally left blank to prevent flickering during painting.\n\n### **Allocate Buffer Method**\n```vb\nPrivate Sub AllocateBuffer(e As PaintEventArgs)\n    If Buffer Is Nothing Then\n        Buffer = Context.Allocate(e.Graphics, ClientRectangle)\n        With Buffer.Graphics\n            .CompositingMode = Drawing2D.CompositingMode.SourceOver\n            .TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias\n            .SmoothingMode = Drawing2D.SmoothingMode.HighQuality\n            .PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality\n            .CompositingQuality = Drawing2D.CompositingQuality.HighQuality\n            .InterpolationMode = InterpolationMode.HighQualityBicubic\n            .TextContrast = SmoothingMode.HighQuality\n        End With\n    End If\nEnd Sub\n```\n\n  - This method checks if the buffer has been allocated. If not, it allocates a new buffer and sets various rendering properties to ensure high-quality graphics.\n\n### **Draw Displays Method**\n```vb\n    Private Sub DrawDisplays()\n\n        If Buffer IsNot Nothing Then\n\n            Try\n\n                With Buffer.Graphics\n\n                    .Clear(SystemColors.Control)\n\n                    .DrawEllipse(CircleOfProgressBackgroundPen,\n                                 CircleOfProgress)\n\n                    .DrawArc(CircleOfProgressPen,\n                             CircleOfProgress,\n                             StartAngleTrackBar.Value,\n                             SweepAngleTrackBar.Value)\n\n                    .DrawString(CodeDisplay.Text,\n                                CodeDisplay.Font,\n                                New SolidBrush(SystemColors.ControlText),\n                                CodeDisplay.Location,\n                                AlineCenterMiddle)\n\n                End With\n\n            Catch ex As Exception\n\n                Debug.Print(\"Draw error: \" \u0026 ex.Message)\n\n            End Try\n\n        Else\n\n            Debug.Print(\"Buffer is not initialized.\")\n\n        End If\n\n    End Sub\n\n```\n\n  - This method draws the background ellipse, the arc based on the current angles, and the code display text on the buffer. It also handles any potential drawing errors.\n\n### **Dispose Buffer Method**\n```vb\nPrivate Sub DisposeBuffer()\n    If Buffer IsNot Nothing Then\n        Buffer.Dispose()\n        Buffer = Nothing ' Set to Nothing to avoid using a disposed object\n    End If\nEnd Sub\n```\n\n  - This method disposes of the buffer if it exists and sets it to `Nothing` to avoid using a disposed object.\n\n### **Initialize App Method**\n```vb\nPrivate Sub InitializeApp()\n    InitializeForm()\n    InitializeBuffer()\n    InitializeLabels()\n    InitializeTimer()\nEnd Sub\n```\n\n  - This method initializes the application by calling several initialization methods for the form, buffer, labels, and timer.\n\n### **Initialize Form Method**\n```vb\nPrivate Sub InitializeForm()\n    CenterToScreen()\n    SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)\n    SetStyle(ControlStyles.UserPaint, True)\n    Text = \"Draw Arc - Code with Joe\"\n    Me.WindowState = FormWindowState.Maximized\nEnd Sub\n```\n\n  - This method centers the form on the screen, sets styles for double buffering (to reduce flickering), sets the window title, and maximizes the window.\n\n### **Initialize Buffer Method**\n```vb\nPrivate Sub InitializeBuffer()\n    Context = BufferedGraphicsManager.Current\n    Context.MaximumBuffer = Screen.PrimaryScreen.WorkingArea.Size\n    Buffer = Context.Allocate(CreateGraphics(), ClientRectangle)\n    With Buffer.Graphics\n        .CompositingMode = Drawing2D.CompositingMode.SourceOver\n        .TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias\n        .SmoothingMode = Drawing2D.SmoothingMode.HighQuality\n        .PixelOffsetMode = Drawing2D.PixelOffsetMode.None\n        .CompositingQuality = Drawing2D.CompositingQuality.HighQuality\n    End With\nEnd Sub\n```\n\n  - This method initializes the graphics buffer context, sets the maximum buffer size, and allocates the buffer with high-quality rendering settings.\n\n### **Initialize Timer Method**\n```vb\nPrivate Sub InitializeTimer()\n    Timer1.Interval = 30\n    Timer1.Enabled = True\nEnd Sub\n```\n\n  - This method sets the timer interval to 30 milliseconds and enables the timer, which will trigger periodic updates.\n\n### **Initialize Labels Method**\n```vb\nPrivate Sub InitializeLabels()\n    StartAngleLabel.Text = $\"Start Angle: {StartAngleTrackBar.Value}°\"\n    SweepAngleLabel.Text = $\"Sweep Angle: {SweepAngleTrackBar.Value}°\"\nEnd Sub\n```\n\n  - This method initializes the text for the angle labels based on the initial values of the trackbars.\n\n### **Resize Methods**\n- **ResizeCodeDisplay, ResizeControls, ResizeCircleOfProgress**\n```vb\n    Private Sub ResizeCodeDisplay()\n\n        Dim FontSize As Single\n\n        If ClientSize.Height / 25 \u003e 13 Then\n\n            FontSize = ClientSize.Height / 25\n\n        Else\n\n            FontSize = 13\n\n        End If\n\n        Dim YPosition As Integer\n\n        If ClientSize.Height / 2.5 \u003e 175 Then\n\n            YPosition = ClientSize.Height / 2.5\n\n        Else\n\n            YPosition = 175\n\n        End If\n\n        CodeDisplay.Font = New Font(\"Segoe UI\",\n                                    FontSize,\n                                    FontStyle.Regular)\n\n        CodeDisplay.Location.X = ClientSize.Width / 2\n\n        CodeDisplay.Location.Y = ClientSize.Height / 2 - YPosition\n\n    End Sub\n\n    Private Sub ResizeControls()\n\n        Dim TrackBarWidth As Integer\n\n        If ClientSize.Height / 2 \u003e 225 Then\n\n            TrackBarWidth = ClientSize.Height / 2\n\n        Else\n\n            TrackBarWidth = 225\n\n        End If\n\n        StartAngleTrackBar.Width = TrackBarWidth\n\n        StartAngleTrackBar.Left = ClientSize.Width / 2 - StartAngleTrackBar.Width / 2\n\n        StartAngleTrackBar.Top = ClientSize.Height / 2 - StartAngleTrackBar.Height\n\n        StartAngleLabel.Left = StartAngleTrackBar.Left + 8\n\n        StartAngleLabel.Top = StartAngleTrackBar.Top + 40\n\n        SweepAngleTrackBar.Width = TrackBarWidth\n\n        SweepAngleTrackBar.Left = ClientSize.Width / 2 - SweepAngleTrackBar.Width / 2\n\n        SweepAngleTrackBar.Top = ClientSize.Height / 2 + SweepAngleTrackBar.Height * 0.1\n\n        SweepAngleLabel.Left = SweepAngleTrackBar.Left + 8\n\n        SweepAngleLabel.Top = SweepAngleTrackBar.Top + 40\n\n    End Sub\n\n    Private Sub ResizeCircleOfProgress()\n\n        Dim PenSize As Single\n\n        If ClientSize.Height / 30 \u003e 15 Then\n\n            PenSize = ClientSize.Height / 30\n\n        Else\n\n            PenSize = 15\n\n        End If\n\n        CircleOfProgressBackgroundPen = New Pen(SystemColors.ControlLightLight,\n                                                PenSize)\n\n        If ClientSize.Height / 40 \u003e 10 Then\n\n            PenSize = ClientSize.Height / 40\n\n        Else\n\n            PenSize = 10\n\n        End If\n\n        CircleOfProgressPen = New Pen(SystemColors.MenuHighlight, PenSize) With {\n            .EndCap = LineCap.Round,\n            .StartCap = LineCap.Round\n        }\n\n        Dim CircleSize As Single\n\n        If ClientSize.Height / 1.5 \u003e 300 Then\n\n            CircleSize = ClientSize.Height / 1.5\n\n        Else\n\n            CircleSize = 300\n\n        End If\n\n        CircleOfProgress.Width = CircleSize\n        CircleOfProgress.Height = CircleSize\n\n        CircleOfProgress.X = ClientSize.Width / 2 - CircleOfProgress.Width / 2\n        CircleOfProgress.Y = ClientSize.Height / 2 - CircleOfProgress.Height / 2\n\n    End Sub\n\n```\n\n  - These methods adjust the size and position of the code display, controls (like trackbars), and the drawing area (circle) based on the current size of the form.\n\n\nThis code creates an interactive application that allows users to visualize how arcs are drawn based on different starting and sweep angles. It uses VB.NET's GDI+ for graphics rendering and provides a user-friendly interface for manipulating the angles. Each section of the code is designed to handle specific aspects of the application, from initialization to drawing and resizing components. \n\n\n\n![AnglesDiagram02](https://github.com/user-attachments/assets/f8ee119d-ecd8-42af-9cac-eccd4b12d9b0)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoelumbley%2Fdraw-arc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoelumbley%2Fdraw-arc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoelumbley%2Fdraw-arc/lists"}