Coder Social home page Coder Social logo

pizza-meow's Introduction

Pizza-Meow

Hello, hello! I'm not sure how you found your way to this part of the internet but welcome! This was my first stab at canvas based off a tutorial from the folks at codrops, referenced from one of the organizers of the Prototype, Process, & Play conference.

I had a lot of fun running through this exercise. This is definitely not how the end-product of the codrops tutorial looked like, I just wanted to get a feel for the fundamentals so I deviated from the path and decided to add in a few of my favorite things: pizza, cats, gradients and space. :D

I did notice an inconsistency in the source code that I grabbed from the site. The section where you grab the five closest surrounding points had the following:

for(var i = 0; i < points.length; i++) {
              var closest = [];
              var p1 = points[i];
              for(var j = 0; j < points.length; j++) {
                var p2 = points[j]
                if(!(p1 == p2)) {
                  var placed = false;
                  for(var k = 0; k < 5; k++) {
                    if(!placed) {
                      if(closest[k] == undefined) {
                        closest[k] = p2;
                        placed = true;
                      }
                    }
                  }
                  for(var k = 0; k < 5; k++) {
                    if(!placed) {
                      if(getDistance(p1, p2) < getDistance(p1, closest[k])) {
                        closest[k] = p2;
                        placed = true;
                      }
                    }
                  }
                }
              }
            }

This would work to get the five closest points if all the coordinates in the points array were in order. If the coordinates are unordered you run into the possibility of replacing the first surrounding point that may not be the farthest out of the recorded five. For example, if we were traversing through an array with the following coordinates:

[ {x:0,y:0}, {x:2,y:3}, {x:4,y:5}, {x:5,y:6}, {x:7,y:16}, {x:4,y:4}, {x:0,y:1} ]

comparing the surrounding points to the coordinate {x:5, y:5}, with the above code we would have filled closest with the first five points. Now when we are comparing the remaining points to see if they are closer we would actually bump out closest[0] when we should actually bump out closest[4]. One way to solve this would be to track the comparison, another would be to sort the points array before we do any comparisons for proximity.

pizza-meow's People

Contributors

sashak007 avatar

Watchers

James Cloos avatar  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.