Giter VIP home page Giter VIP logo

visualsort's Introduction

Sorting Visualised

Sorting algorithms visualised in form of a spiral, as well as basic sorting rectangle to fill the background. Uses promises to delay run time, so draw() can create animation that is humanly visable. Runs both 'draw()' and sorting algorithms asynchronously.

Website link - https://zollf.github.io/visualsort/

How the spiral works

Given an array of inputs arr[n], we will create a spiral using polar equations.

x = ricos(iθ) + c, y = risin(iθ) + c

r = arr[i]

θ = 2π/n

i = current index of the array

c = centered value for corresponding axis

'spiralVal' is randomised value that to get a random design for the spiral. The random value will influence the modulus and arguement of the equation

spiralVal = randomInt(3, 6) * Math.random() + 4;

Coded spiral equation given array of values

let dotsize = 8;
let fracCircle = (2 * pi)/MAX_VALUES;
for(let i = 0; i <= MAX_VALUES; i++){
    // Color of each dot, increasing in value
    fill(color(values[i]**2 /1000, 100, 100));

    let angle = fracCircle * i * spiralVal;
    let x = (CENTER_POINT_X)+                     (2*values[i]/spiralVal * Math.cos(angle));  
    let y = (CENTER_POINT_Y + dotsize/2 + 20) +   (2*values[i]/spiralVal * Math.sin(angle));

    circle(x, y, dotsize);
}

Sorting Algorithms

  • Bubble Sort
  • Insert Sort
  • Selection Sort
  • Merge Sort
  • Heap Sort
  • Quick Sort
  • Radix Sort
  • Count Sort

Uses p5.js library

(https://p5js.org/)

visualsort's People

Contributors

zollf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.