In a hex grid you’ll need three colors to color each hex so that it doesn’t have the same color as a neighbor:
You were on the right track with your solution. Instead of adding x+y
you’ll want to subtract x-y
. The other change is that &3
is for bit manipulation; you’ll want %3
instead. However, in some languages, including Javascript, %3
can return a negative number, so you’ll need to use ((___%3)+3)%3
to make it positive.
The color/sprite id you want is ((x-y)%3 + 3) % 3
. I made an interactive demo to test this.
Related Posts:
- addEventListener vs onclick
- How do you check that a number is NaN in JavaScript?
- JQuery – $ is not defined
- Client on Node.js: Uncaught ReferenceError: require is not defined
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- Error: Can’t set headers after they are sent to the client
- Express error – TypeError: Router.use() requires middleware function but got a Object
- How can I check for “undefined” in JavaScript? [duplicate]
- How can I reverse an array in JavaScript without using libraries?
- How to import jquery using ES6 syntax?
- How to filter an array/object by checking multiple values
- Does JavaScript pass by reference? [duplicate]
- How to resolve the C:\fakepath?
- React this.setState is not a function
- AngularJS- Login and Authentication in each route and controller
- Check if a variable is a string in JavaScript
- How to pass props to {this.props.children}
- Adding options to select with javascript
- MRAID file reference
- How to format numbers?
- Does parseDouble exist in JavaScript?
- What does !1 and !0 mean in Javascript?
- How to use php code in javascript
- RegExp in TypeScript
- How to use searchFile and searchFolder at the same time correctly? – App Script
- node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
- Delete first character of a string in Javascript
- How do I get the current time only in JavaScript
- Get the value of checked checkbox?
- Equivalent of jQuery .hide() to set visibility: hidden
- How can I get the last character in a string?
- Create table using Javascript
- Parse an HTML string with JS
- JS file gets a net::ERR_ABORTED 404 (Not Found)
- Shortest way to print current year in a website
- push object into array
- module.exports “Module is not defined”
- Why doesn’t JavaScript support multithreading?
- plain count up timer in javascript
- Uncaught TypeError: Cannot read property ‘name’ of undefined
- How to calculate date difference in JavaScript?
- React’s setState method with prevState argument
- Finding the average of an array using JS
- Is it possible to simulate key press events programmatically?
- Vue template or render function not defined yet I am using neither?
- Cannot read property ‘length’ of null (javascript)
- Caesar Cipher in Javascript
- Can’t perform a React state update on an unmounted component
- How to simulate a click with JavaScript?
- Return array from function
- Why define an anonymous function and pass it jQuery as the argument?
- Error parsing XHTML: The content of elements must consist of well-formed character data or markup
- How to scroll an HTML page to a given anchor
- Javascript call() & apply() vs bind()?
- “google is not defined” when using Google Maps V3 in Firefox remotely
- how to call a onclick function in tag?
- what is the best way to check variable type in javascript
- JavaScript Array Push key value
- stopPropagation vs. stopImmediatePropagation
- typescript – cloning object
- Ajax success function
- Register and enqueue conditional (browser-specific) javascript files?
- How to replace regular jquery calls with CDN calls from Google?
- Editing Source Code in WordPress
- How/Where is editor.min.js Added to the wp-admin Post Page?
- Why is this gutenberg custom format button only available from the toolbar as a dropdown?
- Close TinyMCE plugin window on click away
- VB.net and WordPress
- Gutenberg passing block attributes to component in ES6/ESNext
- Running JS after theme customizer finished initialization
- Script Localization doesn’t work
- How to conditionally show/hide controls & sections in WordPress customizer?
- Uncaught TypeError [closed]
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- How to get the title of the item that is clicked on
- Correct way to include extra styles & script files?
- How can I allow HTML in Gutenberg UI elements help text?
- How to move core js files into the footer
- UnitControl – Block has encountered an error
- Building a Featured Gallery component for Gutenberg
- Should I manually resolve WP Core File security issues or await a subsequent WP release?
- Retrieving data about comments and likes
- Linking wp_enqueue can’t find the javascript file (adds “?ver=x.x.x” to the src)
- My code will not execute in wordpress, even though I’ve been told the code is fine
- Is it possible to override only a part of another plugin’s / theme’s js (asset) file?
- Gutenberg – dynamically created element: how to set onChange?
- JSX SVG Icon with WordPress
- Javascript working on jsfiddle but not wordpress site?
- Drodown list return issue
- Can I just insert JavaScript by using ?
- Gutenberg Edit Block Inspector Controls and save
- JavaScript and Google PageSpeed + wp_enqueue_script
- Put dynamic Javascript in header after doing operations
- Adding javascript blocks to a single file and adding it to the header
- How to modify a class in load-scripts.js ?
- How to integrate a different (JavaScript) editor in WordPress?
- Add Javascript/Html into a WordPress
- Gutenberg core/file add style support in js/ json
- uploading image to wordpress site with javascript fetch function failed