├── .gitignore ├── LICENSE.md ├── README.md ├── canvas.js ├── img ├── adder.png ├── adder_chain.png ├── adder_plus_plus.png ├── and.png ├── dirswitch.png ├── multiplexer.png ├── srnor.png └── srnor_small.png └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | /sublime-text -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Shreyas Raman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HexLogic 2 | ======== 3 | 4 | A clone of [LogicHex](https://mojang.com/notch/logichex/) by [Notch](https://mojang.com/notch/) (yes, the guy who made Minecraft) using Javascript canvas. Try it out: http://anubiann00b.github.io/HexLogic/ 5 | 6 | Here are some examples of what you can make: 7 | 8 | Switch direction: 9 | 10 | ![Switching direction](img/dirswitch.png) 11 | 12 | AND gate: 13 | 14 | ![AND gate](img/and.png) 15 | 16 | Multiplexer: 17 | 18 | ![Multiplexer](img/multiplexer.png) 19 | 20 | Adder: 21 | 22 | ![Example of an adder](img/adder.png) 23 | 24 | Adder that's more chainable: 25 | 26 | ![Chainable adder](img/adder_chain.png) 27 | 28 | SR-NOR latch: 29 | 30 | ![SR-NOR Latch](img/srnor.png) 31 | 32 | Better SR-NOR latch: 33 | 34 | ![Better SR-NOR latch](img/srnor_small.png) 35 | 36 | Much better Adder: 37 | 38 | ![Much better adder](img/adder_plus_plus.png) -------------------------------------------------------------------------------- /canvas.js: -------------------------------------------------------------------------------- 1 | 2 | var neighbors = [ 3 | [ [+1, +1], [+1, 0], [ 0, -1], 4 | [-1, 0], [-1, +1], [ 0, +1] ], 5 | [ [+1, 0], [+1, -1], [ 0, -1], 6 | [-1, -1], [-1, 0], [ 0, +1] ] 7 | ]; 8 | 9 | var size = 15; 10 | var map; 11 | 12 | var canvas = document.getElementById('canvas') 13 | 14 | var xs; 15 | var ys 16 | 17 | configureMap(); 18 | 19 | var xo = 0; 20 | var yo = 0; 21 | 22 | var xpo = size; 23 | var ypo = size; 24 | 25 | canvas.addEventListener('click', onClick, false); 26 | var g = canvas.getContext('2d'); 27 | drawAll(); 28 | 29 | window.setInterval(function() { 30 | for (var i=0; i=xs || ny<0 || ny>=ys) 127 | return { state:0, type:0, x:nx, y:ny}; 128 | 129 | var newHex = map[nx][ny]; 130 | 131 | return newHex; 132 | } 133 | 134 | function onClick(e) { 135 | var pp = getPosition(e.currentTarget); 136 | var xp = e.clientX - pp.x - xpo; 137 | var yp = e.clientY - pp.y - ypo; 138 | 139 | var hx = 2/3 * xp / size; 140 | var hy = Math.sqrt(3)/3 * yp / size + (Math.round(hx)%2)*Math.sqrt(3)/3; 141 | 142 | var h = map[Math.round(hx)][Math.floor(hy)]; 143 | h.type++; 144 | if (h.type>3) 145 | h.type=0; 146 | 147 | h.repaint = true; 148 | 149 | repaint(); 150 | } 151 | 152 | function drawHex(hex, xp, yp) { 153 | g.beginPath(); 154 | var i; 155 | for (i=0; i<=6; i++) { 156 | var angle = 2 * Math.PI / 6 * i; 157 | x = xp + size * Math.cos(angle); 158 | y = yp + size * Math.sin(angle); 159 | if (i === 0) 160 | g.moveTo(x,y); 161 | else 162 | g.lineTo(x,y); 163 | } 164 | g.stroke(); 165 | 166 | if (hex.type === 0) 167 | g.fillStyle='#AAAAAA'; 168 | else if (hex.state==0) 169 | g.fillStyle='#FFFFFF'; 170 | else 171 | g.fillStyle='#FFFF00'; 172 | g.fill(); 173 | 174 | g.beginPath(); 175 | switch(hex.type) { 176 | case 0: // Blank 177 | break; 178 | case 1: // XOR 179 | g.moveTo(xp - size/4, yp - size/4); 180 | g.lineTo(xp + size/4, yp + size/4); 181 | g.moveTo(xp - size/4, yp + size/4); 182 | g.lineTo(xp + size/4, yp - size/4); 183 | break; 184 | case 2: // OR 185 | g.arc(xp, yp, size/4, 0, 2*Math.PI); 186 | break; 187 | case 3: // Power 188 | g.moveTo(xp - size/4, yp); 189 | g.lineTo(xp + size/4, yp); 190 | g.moveTo(xp, yp + size/4); 191 | g.lineTo(xp, yp - size/4); 192 | break; 193 | } 194 | g.stroke(); 195 | } 196 | 197 | function getPosition(e) { 198 | var xp = 0; 199 | var yp = 0; 200 | 201 | while (e) { 202 | xp += (e.offsetLeft - e.scrollLeft + e.clientLeft); 203 | yp += (e.offsetTop - e.scrollTop + e.clientTop); 204 | e = e.offsetParent; 205 | } 206 | return { x: xp, y: yp }; 207 | } -------------------------------------------------------------------------------- /img/adder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/adder.png -------------------------------------------------------------------------------- /img/adder_chain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/adder_chain.png -------------------------------------------------------------------------------- /img/adder_plus_plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/adder_plus_plus.png -------------------------------------------------------------------------------- /img/and.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/and.png -------------------------------------------------------------------------------- /img/dirswitch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/dirswitch.png -------------------------------------------------------------------------------- /img/multiplexer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/multiplexer.png -------------------------------------------------------------------------------- /img/srnor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/srnor.png -------------------------------------------------------------------------------- /img/srnor_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sylvia43/HexLogic/7aa3ea98e21fae17213ae55af1159e4a652773c2/img/srnor_small.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | HexLogic 4 | 12 | 13 | 14 | Fork me on GitHub 15 |

HexLogic

16 | 17 | 18 | 19 |

Click to toggle cell types.

20 |

Cell types:

21 | 27 | 28 |

Cell inputs are straight down, and diagonally up right and left.

29 |

Cell outputs are straight up, and diagonally down right and left.

30 | 31 |

Web clone of LogicHex by Notch, who's also the creator of Minecraft.

32 | 33 | 34 | --------------------------------------------------------------------------------