From b325f796c0c691986620f58e7d8104bc16f79d9e Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 10 Oct 2021 20:01:00 +0530 Subject: Implement Bresenham's Algorithm --- src/algorithms/line-drawing/Bresenham.svelte | 172 ++++++++++++++++++++++++++- src/algorithms/line-drawing/DDA.svelte | 1 - 2 files changed, 171 insertions(+), 2 deletions(-) (limited to 'src/algorithms') diff --git a/src/algorithms/line-drawing/Bresenham.svelte b/src/algorithms/line-drawing/Bresenham.svelte index d2f81af..e3eaff1 100644 --- a/src/algorithms/line-drawing/Bresenham.svelte +++ b/src/algorithms/line-drawing/Bresenham.svelte @@ -1 +1,171 @@ -

Bresenham

+ + + + + +

Bresenham

+
+ {#if invalidInput === true} +

+ Slope must be between 0 to 1. +

+ {/if} + +   + + +
+ +   + + +
+ +
+ +{#if solved === true} +
+

Solution

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Value
dx = |x1 - x0|{dx}
dy = |y1 - y0|{dy}
step = |2 * (dy - dx)|{step}
2 * dy{2 * dy}
p0{p_vals[0]}
+ +
+ + Table + + + + + + + + + + + + + {#each x_axis as _, i} + + + + + + + {/each} + +
Iteration (k)Pkxk + 1yk + 1
{i}{p_vals[i]}{x_axis[i]}{y_axis[i]}
+
+ +

Graph

+ {#if plotlyReady === false} +

+ Cannot plot graph: Plotly is not ready. +

+ {/if} +{/if} +
+ + diff --git a/src/algorithms/line-drawing/DDA.svelte b/src/algorithms/line-drawing/DDA.svelte index b759cdc..c9f62a0 100644 --- a/src/algorithms/line-drawing/DDA.svelte +++ b/src/algorithms/line-drawing/DDA.svelte @@ -124,7 +124,6 @@

Graph

{#if plotlyReady === false} -

Cannot plot graph: Plotly is not ready.

-- cgit 1.4.1-2-gfad0