Code Monkey home page Code Monkey logo

Comments (4)

rylnd avatar rylnd commented on June 9, 2024 1

@BaileyMillerSSI you are correct that if the hashing function changes the outcomes will change.

I encourage you to look at the SlotMachine class and its tests, but in essence our hashing works like this: given a collection of outcomes (e.g. avatar images) and a hashing function that returns an integer (e.g. "sum all the character codes in the string"), we get an instance that will return one of the outcomes when passed a string.

I hope that sets you on the right path. If so, please do close this issue.

The code is all right here, so I will again encourage you to browse the codebase if you have more questions. Thanks for your interest!

from avatars-api-middleware.

BaileyMillerSSI avatar BaileyMillerSSI commented on June 9, 2024

My friend is looking to do something similar for a school project so I am trying to help with the code. Your @slots variable is an array of images, or in the test case file1, file2, file3, file4, file5. Then you call the pull method with your input string, in the case of the demo website this can the username, or anything really.
Pull returns a variable out of the @slots array of images, in the test case again file1, file2, file3, file4, file5, and what you do is you go var eyes= SlotMachine.pull('inputString'); var nose = SlotMachine.pull('inputString'); where SlotMachine will be a different machine for each category, eyes, face, etc. Then at the end you have some code that creates an image by combining all these variables.

@rylnd Aside from the literal hashing function and the image creation code, did I get that correct?

from avatars-api-middleware.

rylnd avatar rylnd commented on June 9, 2024

@BaileyMillerSSI yes, I think you've got it.

The eyes/nose stuff is for the more complicated v2 endpoint with several slotMachine instances for each part of the image, and would be closer to

var eyes = (new SlotMachine(eyesCollection)).pull('inputString');
var nose = (new SlotMachine(noseCollection)).pull('inputString');

The v1 endpoint is the simpler one that I'd suggest you start with; it does the "hash the string and pick an image file" logic, as opposed to building up the image programmatically. The general concept is the same in both cases, though.

Also, @itsthatguy just rewrote the code for es6, so I would suggest looking at the develop branch as opposed to master.

from avatars-api-middleware.

rylnd avatar rylnd commented on June 9, 2024

Closing this due to inactivity.

from avatars-api-middleware.

Related Issues (20)

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.