No video

Coding Challenge #89: Langton's Ant

  Рет қаралды 155,902

The Coding Train

The Coding Train

Күн бұрын

Пікірлер: 185
@msclrhd
@msclrhd 6 жыл бұрын
If you have two ants, they create interesting patterns depending on their positions. As well as the hive (blob) - highway (diagonal line) pattern, they can run a create/destroy loop on a partial hive, or they can start chasing each other in an expanding-collapsing diamond pattern. It is worth creating an Ant class to support that. You can then extend that to encode the turn behaviour (left, right, no change, 180deg) and/or what colour to change to. These create some interesting behaviours -- I've had some ant variants build a "super highway" of a certain colour in a straight line, then zoom along it (using the "no change" turn rule). Combining ants with different rules is also interesting (but they need to support the same number of colours, otherwise they will stop if they get to an unsupported colour). You could also extend this to support Turmites (en.wikipedia.org/wiki/Turmite), who's behaviour depends on their state as well as the cell colour.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
This is such good info thank you! I should definitely do a follow-up!
@kamoroso94
@kamoroso94 6 жыл бұрын
I'd love to see a Langton's Ant Part 2! After I saw the video about it on Numberphile, I made it on my graphing calculator lol.
@vlahovivan
@vlahovivan 5 жыл бұрын
I made a video of Langton's ants "fighting", it's on my channel if anyone's interested :)
@gameglitcher
@gameglitcher 4 жыл бұрын
if an ant enters an ant tile add another ant!
@kevnar
@kevnar 6 жыл бұрын
Langton's Car. Set all pixels positions on screen to a random value of either 0,1,2, or 3. Set a particle "car" in the middle with an arbitrary velocity vector. On each frame, the car will move to a new position. if the pixel is 0, increase speed slightly, but never more than maxSpeed. If the pixel is 1, angle slightly to the right. If the pixel is 2, decrease speed slightly, but never less than 1. If the pixel is 3, angle slightly to the left. Reset the pixel it's on to a new random value so no infinite loops occur, and then update position. For bonus points, set up a "garage" somewhere (3 sides of a rectangle), and see if the car can drive into it. If you increase the increment of the angle to 90 degrees left or right, the car will drift sideways for a few frames before correcting. Add tire squealing sound effects as needed.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Cool suggestion!
@charbelsarkis3567
@charbelsarkis3567 6 жыл бұрын
This is a very elaborate comment. Can you do it and just show us the result
@paulkerrigan9857
@paulkerrigan9857 6 жыл бұрын
I like the beard, man! Your videos are always welcome!
@MarkJay
@MarkJay 6 жыл бұрын
I'm a simple man, I see new coding train video, I like.
@Bunny99s
@Bunny99s 4 жыл бұрын
Instead of that single direction variable (and the 4 constants and that huge movement function) when just using a vector (dirX, dirY) everything becomes much simpler. Rotating is just swapping dirX and dirY and inverting one of them. Which you invert defines the direction you're rotating. The movement is just adding dirX to x and dirY to y. Of course we still need the screen edge wrapping. Something like this: void Turn(boolean turnRight) { int tmp = dirX; if (turnRight) { dirX = -dirY; dirY = tmp; } else { dirX = dirY; dirY = -tmp; } } void moveForward() { x = (x + dirX + width) % width; y = (y + dirY + height) % height; }
@KitsumiTheFox
@KitsumiTheFox 6 жыл бұрын
My favorite way to set variables from a 1 or 0 value like this is doing (in this case) int color = grid[x][y]*255 Since if its 0, it'll be 0 and if its 1, it'll be 255
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Nice improvement!
@Nurutomo
@Nurutomo 4 жыл бұрын
Normalize a value
@Brahvim
@Brahvim 3 жыл бұрын
:0 I never though you could do that ..thanks for the trick!
@nahueljo
@nahueljo 6 жыл бұрын
Alright! This challenge was my suggestion! Thanks Daniel
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yay!
@AnirudhGiri
@AnirudhGiri 6 жыл бұрын
Finally! Processing is back,boys! :D :D
@chrishawker9463
@chrishawker9463 6 жыл бұрын
I discovered Processing at the same time I heard Support for Java is ending...
@aarond4577
@aarond4577 6 жыл бұрын
Chris Hawker lol
@mikal_1
@mikal_1 6 жыл бұрын
I don't even do that much coding, but this is so much fun and so very useful!
@alairock
@alairock 6 жыл бұрын
One way I implemented turning was with an array in js: direction = [0, -1, 0, 1] Then using some array management: direction.unshift(direction.pop()) // turns one way if (isWhite(img, loc.x + 1, loc.y + 1)) { direction.push(direction.shift()) // if white, turn right (undoes the first turn that always happens) direction.push(direction.shift()) // then turns again, effectively turning the way we wanted for this situation Then if you play with the direction variable values you can come up with some really neat patterns some are just loosely similar to Langton's ant, and others are bizarre recursive/fractal patterns. Loved this video. Fun inspiration, and had fun writing it for myself in p5!
@corruptconverter2616
@corruptconverter2616 2 жыл бұрын
When I made it, I did the same, but I used a 4 number array representing the amount to change the ant's index (As I had it represented by a position in a 1d array of the grid), and had a variable that would range from 0 to 3 representing the direction. When the ant would move, it would use the direction as an index for the aforementioned array, and that would be the amount it changes it's position by. For turning, I had an array of +1 and -1 representing right and left respectively, and using the value of the cell the ant moves into (post-step) as an index for this array, I would change the direction variable. So it would either increase by 1, or decrease by 1. Before assigning it, I would perform a bitwise AND operation on it with 0b11 (3) so that if it became -1, it would change to 3. My goal was to write it in JS while optimizing the absolute hell out of it, to the best of my ability, so that it would run as fast as possible in a webpage. With just JS, I got it to 80 million steps/second (Capped by Chrome), and with WebAssembly, I got it to 200 million/second. With WebAssembly: www.jdoodle.com/h/1Yw With pure JS: www.jdoodle.com/h/1ZM I had to reconstruct the pure JS version from a slightly older one because I didn't save the version that I made just before shifting to WASM. I'm pretty sure that I had it at just about 60 million/second, but it's running closer to 50 million/second. Maybe I missed something small, idk. (Note: The arrays are saved as Int32Array as a performance optimization) Test settings (10 million/frame): Rules: L Delay: 0 Steps: 10000000 Width: 2 Height: 2
@FriedNoodlee
@FriedNoodlee 3 жыл бұрын
I did this myself, and I thought I should see if you made a video on it! You actually did! I totally could've used this when making Langton's Ant haha.
@FriedNoodlee
@FriedNoodlee 3 жыл бұрын
I made it check the pixel's color, and then put a little rectangle to replace the color that the ant was just on.
@mickyr171
@mickyr171 2 жыл бұрын
same, my code is PVector pos, move; int spacing = 25; color white = color(255); color black = color(0); void setup(){ size(1000,1000, P2D); rectMode(CENTER); background(255); noStroke(); pos = new PVector(width/2,height/2); move = new PVector(0, -spacing); } void draw(){ color c = get(floor(pos.x), floor(pos.y)); if (c == white){ move.rotate(-HALF_PI); fill(black); rect(pos.x,pos.y,spacing, spacing); pos.add(move); } if (c == black){ move.rotate(HALF_PI); fill(white); rect(pos.x,pos.y,spacing,spacing); pos.add(move); } }
@Bunny99s
@Bunny99s 5 жыл бұрын
I think more interesting would be to encode the two states (0, 1) as (negative, positive). That way to flip the state you literally just have to flip the sign. Further more we could encode how often we visit the same pixel by incrementing (/ decrementing) the pixel value. Now you can use a color code to draw the pixels. I guess we should still draw the "background" either black or white and the "foreground" with our color based on the cells value. state = grid[x][y]; // flipping state = -state; // increment only when positive if (state >= 0) state++; grid[x][y] = state; The "(state >= 0)" condition also takes care of the initial "0" in the array. So " 0" is considered black (foreground)
@Dark_Warrior
@Dark_Warrior 2 жыл бұрын
I've been going through the entire Internet looking for this, I build this in minecraft but couldn't remember what it was called
@justgame5508
@justgame5508 6 жыл бұрын
Great video as always, speaking of "ants" could you do a video on an ant colony optimisation algorithm to follow up on your genetic algorithm and machine learning series.
@MatthewHolevinski
@MatthewHolevinski 6 жыл бұрын
These are my favorite kinds of Coding Train videos!
@corruptconverter2616
@corruptconverter2616 2 жыл бұрын
In JavaScript, I got it to run at 80 million steps/second, and including WebAssembly, I got it to 200 million/second.
@kenhaley4
@kenhaley4 6 жыл бұрын
Cool video, Dan. But one of the really amazing and fun things about Langton's Ant is what happens when there are two or more ants running around and interacting. Also, how to accept user input to set the initial position and direction of the ants. Maybe a followup video?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yes, I had meant to mention this is an exercise for the user to try but somehow forgot. Thanks for the comment I'm going to pin it! (And yes, I should follow up on this too.)
@gw_mc4521
@gw_mc4521 5 жыл бұрын
The reason why the image is rotated is because of the initial direction of the ant, if the ant dir is set to 0(up), then the first move will set the dir to 1(right) which makes the image rotated -90 degrees, so the initial dir should be 3(left) so that the first move will be upwards but not to the right.
@TylerDunphy
@TylerDunphy 6 жыл бұрын
I played a pixel game and the ants made the same patterns, never knew it was this!
@Alessandro-nq3tm
@Alessandro-nq3tm 6 жыл бұрын
12:32 That "YEA" was amazing :D :d
@fox9000000
@fox9000000 6 жыл бұрын
Awesome videos man! Keep it up!
@avi062
@avi062 6 жыл бұрын
nicely done. Really very intuitive way to learn all these. Thanks and keep up the good work.
@pumpkingamedev1042
@pumpkingamedev1042 6 жыл бұрын
Whatever you do, don't implement Langton's uncle
@seancpp
@seancpp 5 жыл бұрын
Why use anything provided to you by the programming language when you can just hack away at the keyboard until the spaghetti ends up producing a result!
@KnakuanaRka
@KnakuanaRka 5 жыл бұрын
Sean Franklin Admittedly, this is intended more to get people interested in coding and show them how it works then to be highly professional; accessibility is high priority here. Just look at the number of comments on pretty much any of his videos saying that so-and-so doesn’t know programming but enjoys watching him anyways, or that somebody became interested in programming because of him; that aspect of reaching out to laymen would be gone. I’ll admit he is pretty all over the place in this one, but I can forgive him for that.
@aholicrealm2850
@aholicrealm2850 6 жыл бұрын
That's so cool!
@clbgrmn
@clbgrmn 6 жыл бұрын
Love the videos! You should consider using an enumeration for the direction and/or the state of each cell. You could have up,down,left,right for directions and on,off,ant for cell state.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yes, a good point, thanks for the tip!
@mrjskrueger
@mrjskrueger 6 жыл бұрын
Thank you for sharing this educational videos with us! I wish I had you as my professor at university
@techgamer1333
@techgamer1333 6 жыл бұрын
Keep up the good work man
@esquach
@esquach 6 жыл бұрын
omg 19:20 made me really happy ahahahaha
@o5-1-formerlycalvinlucien60
@o5-1-formerlycalvinlucien60 Жыл бұрын
You should code something to generate a few layers of the Hilbert Curve.
@windigo000
@windigo000 5 жыл бұрын
RIP garbage collector xD 🎵 we will refactor this later🎵
@BrentAureliCodes
@BrentAureliCodes 6 жыл бұрын
Love this Atamata!
@JovenAlbarida
@JovenAlbarida 6 жыл бұрын
I love the p5.js series also :)
@MyRx777z
@MyRx777z 5 жыл бұрын
Even though this is old video but came here from one of the Dust video. This is really interesting! Why is it always making a highway after the 11000 steps? Any reason or hypothesis? 🤔
@ABaumstumpf
@ABaumstumpf 6 жыл бұрын
Just tried it my self - 106 Lines, the area wrap around, '+' and '-' to change the speed, 'Space' to let it run as fast as it can, and highlighting of the ant. it can do roughly 25 million iterations a second. was kinda fun using processing again for such a silly thing.
@lucase6077
@lucase6077 6 жыл бұрын
That was quite awesome
@arunks237
@arunks237 5 жыл бұрын
My first coding challenge. *Ant colony particle swarm optimization* 1. All ants should search food randomly from their nest. 2. Each ant should create trail of pheromone after finding food from food source to nest 2. The Pheromone should evaporating after some seconds 3. As the concentration of pheromone or trail from ants nest to food source increases all ants should follow this trail of concentrated pheromones. 4. This trail of concentrated pheromone must shortest path from nest to food source. *I am saying about mimic real ants. I believes it will be a great challenge for you. Sorry for my bad English.*
@TheCodingTrain
@TheCodingTrain 5 жыл бұрын
Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@arunks237
@arunks237 5 жыл бұрын
@@TheCodingTrain Hey... Hey I made an issue on GitHub after commenting here... Waiting...
@microdrone
@microdrone 6 жыл бұрын
Daniel is an awesome creative and ( perhaps too ) energetic person ( ok I'm kidding ). Superb dancer, but most importantly a good teacher and very inspiring. Oh yeah, a good writer/author, if you haven't already if you are a sincere fledgling Processing enthusiast you should check out his writings/ books etc.
@atrumluminarium
@atrumluminarium 6 жыл бұрын
Will you ever do a video on geometric flows like curve-shortening, mean-curvature, or Ricci flow?
@LeighzerCuber
@LeighzerCuber 6 жыл бұрын
I made this a long time ago and forgot to post it! I made a processing sketch that takes langton's ant, and uses it as a paintbrush with ever slightly shifting colors that create some neat looking images! I did it in a short amount of time so please forgive the sloppy code. Here is the link to my github repository: github.com/Leighzer/Langtons_Paint_Brush
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Nice work! You can submit a link to the coding train website if you like! github.com/CodingTrain/website/wiki/Community-Contributions-Guide
@mikee.
@mikee. 6 жыл бұрын
Cool! Seems a little complicated though :D
@reicafuli5760
@reicafuli5760 6 жыл бұрын
whatt dou?? this is magic man... i can't even seem to realize what he's doing.
@ideallyyours
@ideallyyours 6 жыл бұрын
Couldn't left and right turn be done using one variable for direction? like int AntDir = 0 //or 1,2,3 depending on clockwise direction then using increment/decrement and modulo to cycle through them? would've been easier and clearer imo.
@donoteatmikezila
@donoteatmikezila 6 жыл бұрын
Part of the video is giving the viewer the opportunity to learn how to do things better.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yes, a great improvement!
@tristanbellingham6759
@tristanbellingham6759 6 жыл бұрын
Unfortunately Java implements modulo funnily, if you take the modulo of a negative number it returns the same number. For example: -5%10 = -5 Whereas in other languages it would be 5. js also does it in the funny way too.
@rrxqz
@rrxqz 6 жыл бұрын
you could just take the absolute of the mod then
@samcomer7448
@samcomer7448 6 жыл бұрын
Thanatos 12321 Or not use 0,1,2,3. Have the directions start at anything above 0 modulo (weird Java modulo) should work then, right?
5 жыл бұрын
Ahh, these diagonal lines.. I'd change it to bounce off the wall, so it changes direction more often.
@Junior.Nascimento
@Junior.Nascimento 5 жыл бұрын
in line 82, u just can set the color inside the if statments, so u dont need to chek grid[x][y] twice, u already chek in the state == 0;
@ParkerDD
@ParkerDD 6 жыл бұрын
For wrapping around the Grid, should it not have been if x >= width? I noticed you accounted for the other case of setting x = width-1, but technically the other way the ant would go one pixel off screen no? (Apologies if you say this in the next few mins of video lol)
@ParkerDD
@ParkerDD 6 жыл бұрын
Yep, you did find it later on. Good job man! These challenges are super cool to watch!
@kdmq
@kdmq 5 жыл бұрын
I would have named constants ANTNORTH ANTEAST, etc. to avoid confusion with left and right.
@nikosplugachev6610
@nikosplugachev6610 6 жыл бұрын
what a smart ant...
@kphong73
@kphong73 6 жыл бұрын
Processing is back!!
@gudenau
@gudenau 6 жыл бұрын
Why use modulus when a logical and would work? It's only using the bottom two bits of the direction. If it uses the third it's in an overflow/underflow condition and using a logical and should always create the correct value in less cycles.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Thanks for this suggestion!
@i.c.weiner556
@i.c.weiner556 6 жыл бұрын
I really enjoyed watch you code but you mention a lot how you could do things better, I'd love to see those methods too.
@OrangeC7
@OrangeC7 5 жыл бұрын
_Emboldened words are edits_ I just made a version of this in the *online* p5 editor! I added some features like presets, multiple ants, and a generation counter. ( editor.p5js.org/OrangeC7/sketches/Sy0wACPiQ ) (I got the multiple ant idea with objects idea from this guy: kzfaq.info/get/bejne/fZd1ms2YstWYaIk.html&lc=UgyUDCU5lxCHRM8aib14AaABAg ) The program prints the starting positions of the ants (for when it's randomized) so they can be recorded for later and used as a preset (the code explains how to do that) Thanks for reading this and checking it out! :D P.S.: I was going to add a feature where the black pixels would instead be coloured based on the ant that last placed it, but it would require me to basically rewrite how the grid functions which would be hard to do since pretty much everything else is based on the grid. (._.*)
@JakeFace0
@JakeFace0 6 жыл бұрын
In python you could have just used a dict of all the points where the grid is 1. Way less processing power and storage required.
@pixelgamezz7172
@pixelgamezz7172 6 жыл бұрын
Hi daniel, do u have any good tips on how to become better with js ive just begon with it and the books said that ive must practice al lot i want to do that but i dont know where i sould start.
@finnheinemann3682
@finnheinemann3682 6 жыл бұрын
Thats what i asked for thanks
@marcasrealaccount
@marcasrealaccount 6 жыл бұрын
I tried to make it do as many updates as possible, and it was able to do more than 40 000 000 updates a second about 60 000 updates a frame :D ma computa is fast
@tarn4t1on79
@tarn4t1on79 4 жыл бұрын
I implemented colors by adding another layer of depth to the grid array, so that it's [y][x][filled?, color in hex] (x and y switched in case I want to rotate the array, don't have a use for it yet), with the colors being stored in a separate array. When the ant moves on a tile, the tile's color gets increased by one, up to the length of the color array, after which it's maxed out at colorArray.length - 1. imgur.com/03xSczh @ 11k cycles imgur.com/UYLpny4 @ 1M cycles Also, distribution graph of colors over cycles (not counting empty tiles) @ 1M cycles imgur.com/Kn27MjY btw, love your videos.
@yungnut4247
@yungnut4247 6 жыл бұрын
Why make the grid ints when only storing a 1 or 0, why not Boolean??
@mattschoolfield8932
@mattschoolfield8932 3 жыл бұрын
Use dx and dy for changing direction
@ableite
@ableite 6 жыл бұрын
at 7:00, I have a question about which would be the difference between using ifs and switch... wouldnt the result be the same? Also, just before he was talking about using modulus instead of the ifs also... whats the point of that? wouldnt the result be the same? I sometimes do some silly programs for microcontrollers and always had these doubts... Another one is: is there a problem updating a variable (to a same value) for each computer cycle? because, of course, we can add an if statement to jump it. But is there a pratical difference about these 2 situations?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yes, a switch statement is just concise syntax for a certain kind of if statement, but the result is exactly the same!
@corruptconverter2616
@corruptconverter2616 2 жыл бұрын
​@@TheCodingTrain Actually, it is not. Logically, it may seem the same, but there is a difference between if/else and switch-case. The instruction for performing a conditional jump takes 2 machine cycles if the condition is not met, and 3 if it is met. An if-else statement will jump to the end of each body if the condition is not met, while a switch-case will jump to a body if the condition is met. For example, let's say it were the 4th condition that was met (I will exclude the comparison, and only count the conditional jump instruction's time) if-else: 3 3 3 2 switch-case: 2 2 2 3 And when a switch-case doesn't test each condition, it uses an array of addresses for each condition, and jumps to one of these by index. This is especially efficient if the switch-case uses consecutive conditions, for example, [0, 1, 2, 3, 4, 5, 6...], but make no mistake, a switch-case and if-else are NOT the same. Switch-case is just slightly faster.
@LegatoTube
@LegatoTube 6 жыл бұрын
Need help, in this code, when x becomes larger than 255, why is the fill color still white? int x; void setup() { size(200, 200); surface.setResizable(true); smooth(); frameRate(60); x = 0; } void draw() { rectMode(CENTER); stroke(255, 0, 0); strokeWeight(5); fill(x); rect(width/2, height/2, 100, 100); x++; if(x > 255){ rect(100,100,20,20); } }
@AlejoEremita
@AlejoEremita 6 жыл бұрын
Because you have a fill(255) so every rect is going to be white. If you want to fill black put a fill(0) inside the if (x>255)
@LegatoTube
@LegatoTube 6 жыл бұрын
oh mistyped, imagine if x were in the place of that 255
@Minako-u2o
@Minako-u2o 6 жыл бұрын
Hey! Quick question, would Sublime Text or Atom work with this code or should I just use processing?
@alairock
@alairock 6 жыл бұрын
I used Atom, using the p5/javascript version of processing.
@ExclusiveSigma
@ExclusiveSigma 6 жыл бұрын
Are you writing in Java w/ processing library included? Or Javascript with p5?
@lemmesmash1618
@lemmesmash1618 5 жыл бұрын
yes yes i know this comment is a yer old but i dont care hes coding in java not js
@TorSkywalker
@TorSkywalker 6 жыл бұрын
Thanks so much for doing these videos, Dan! I didn't know about Langton's Ant before and I love that you present some of these "well known" concepts in your Coding Challenges! I have a few suggestions regarding the optimization of the code though - I felt like you were kinda all over the place in this coding challenge. :'D (no offense) You don't actually need to create a PImage, because you can just use the pixels array of the program itself. Also we only need to do background(255) once in the setup() instead of every frame because we don't want to redraw everything every time. When you were talking about optimization, the first thing that came to my mind was just changing the colorMode to (RGB, 1) so you don't need the grid array anymore! I quickly wrote my version of the same program, if anyone wants to take a look at it: pastebin.com/YWd1CdZX Btw maybe someone knows this: I also tried to just put noSmooth() in the setup() and then draw a point(x, y) with either stroke(0) or stroke(1) in the draw loop, but it didn't really work the same way and I couldn't figure out why it wouldn't do the exact same thing as setting the pixel manually. Any suggestions?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Thanks for these great suggestions!
@jonathanengwall2777
@jonathanengwall2777 6 жыл бұрын
I tried to use html canvas. I have seen various directions and wrap, just not at the same time. Why won't updates catch it in its state? Here is what I have if it will fit... // Not Quite Langton's Ant Coding Challenge ANTW=ANTH=4; ANTX=ANTY=200; v=5; DIR=[1,2,3,4,5]; window.onload=function() { c=document.getElementById('gc'); cc=c.getContext('2d'); setInterval(update,1000/100); ANTX=c.width/2; ANTY=c.height/2; } function update() { ANTX+=0; ANTY-=5; DIR=1; if (DIR === 1) { DIR+=1; ANTX+=0; ANTY+=5; turnRight(); } else if (DIR === 2) { DIR+=1; ANTX-=5; ANTY+=0; turnRight(); } else if (DIR === 3) { DIR+=1; ANTX+=0; ANTY-=5; turnRight(); } else if (DIR === 4) { DIR+=1; ANTX+=5; ANTY+=0; turnRight(); } if (ANTX > c.width-5) { ANTX=5; } else if (ANTX < 5) { ANTX=c.width-5; } else if (ANTY > c.height-5) { ANTY=5; } else if (ANTY < 5) { ANTY=c.height-5; } function turnRight() { if (DIR > 4) { DIR-=4; } return DIR; } cc.fillStyle='black'; cc.fillRect(0,0,c.width,c.height); cc.fillStyle='red'; cc.fillRect(ANTX-ANTW/2,ANTY-ANTH/2,ANTW,ANTH); } Presently, the red dot just sits there. That is what it was doing when I started several hours ago! If you would help that would be awesome.... And by the way, from the main image I though the ant would crawl diagonally over an image to turn it into a semi 3-D line drawing. Would that be awesome? Anyway, thanks for all these great videos!
@sabinamanafl8841
@sabinamanafl8841 6 жыл бұрын
thanks!
@pelegred6123
@pelegred6123 6 жыл бұрын
Dat Epic Beard Tho
@cristiancosneanu
@cristiancosneanu 5 жыл бұрын
Here is my version of Langton's ant in Processing... github.com/ccosnean/Langton_s_ant.git
@samdelong6708
@samdelong6708 6 жыл бұрын
How on earth do you find all these algorithms?
@user-fd6bd2hk1p
@user-fd6bd2hk1p 6 жыл бұрын
Sam DeLong Go Wikipedia, search for "AI", click around.
@HaydenMarsh15
@HaydenMarsh15 6 жыл бұрын
Couldn't you use an eNUM for the instead of the integers for the way that it's facing?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yes, a good point! I tend to be informal about these sorts of things and refactor later.
@RedEyedJedi
@RedEyedJedi 6 жыл бұрын
Did anybody else spot that Langton's ant was giving you the bird?
@raintzrandmaa9829
@raintzrandmaa9829 6 жыл бұрын
It will be cool when you will make some videos with pure Java, not Processing but like real Java.
@Victor_Marius
@Victor_Marius 6 жыл бұрын
What resolution do you have on your screen???
@tanqs789
@tanqs789 5 жыл бұрын
How to use modulus to account for the edges?
@garrethutchington1663
@garrethutchington1663 3 жыл бұрын
19:16 "and run it", screen goes black, ad break.
@no_name4796
@no_name4796 2 жыл бұрын
5:49 eww use some modulus operators (%) plz
@DamianReloaded
@DamianReloaded 6 жыл бұрын
I've ants in my room :(
@RossWasTaken
@RossWasTaken 6 жыл бұрын
:(
@pauhull
@pauhull 6 жыл бұрын
10:51 R.I.P. Bitrate
@lewisyuu
@lewisyuu 6 жыл бұрын
new sub!!!
@shervilgupta92
@shervilgupta92 5 жыл бұрын
i created it using js, framerate is too low. It's gonna take an eternity to get to the highway. :(
@kapilverma2668
@kapilverma2668 5 жыл бұрын
Coding challenge: Implement QLearning without using any ml libraries
@darthtorus9341
@darthtorus9341 6 жыл бұрын
TMW you coded Langton's ant before Dan did :O
@darthtorus9341
@darthtorus9341 6 жыл бұрын
Also TMW your code was more complicated than his
@KnakuanaRka
@KnakuanaRka 4 жыл бұрын
Who is Dan?
@darthtorus9341
@darthtorus9341 4 жыл бұрын
@@KnakuanaRka Dan is Dan Shiffman... the guy in the video
@bogdanpetrovic7070
@bogdanpetrovic7070 6 жыл бұрын
Can you do tic tac toe game in p5.js or something like that. Who agrees!
@CthulhusDream
@CthulhusDream 6 жыл бұрын
Kinda want to see what that looks like after you've let it run for a day or two.
@alairock
@alairock 6 жыл бұрын
I wrote this in p5 and after a while it will eventually just fill the screen (I just counted, and it took 3 million moves to fill the 400x400 screen) It only takes a minute and a half to do that, with output to screen every 10,000 moves.
@ritikkhatri
@ritikkhatri 6 жыл бұрын
19 th like.....keep up the good work, Dan, love yr videos,.////////
@zelrex4657
@zelrex4657 6 жыл бұрын
I'm made Langton's ant on scratch which is kid coding drag n drop bock code thing!
@zelrex4657
@zelrex4657 6 жыл бұрын
You hatred my thing cool
@gameglitcher
@gameglitcher 4 жыл бұрын
col = 255 * grid[x][y] :) Didn't see any comment like this lol
@sayanmondal4570
@sayanmondal4570 6 жыл бұрын
Processing :)
@thebailey__
@thebailey__ 6 жыл бұрын
His hair has a bit more floof than usual
@FallGuy1078
@FallGuy1078 6 жыл бұрын
dan you gotta shave my guy that beard is getting long *laughing while crying emoji*
@kaushalfeb
@kaushalfeb 6 жыл бұрын
How do you find these coding challenges?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
People suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@abhigyanrastogi1662
@abhigyanrastogi1662 6 жыл бұрын
wait a second, are you using java? if so, you didn't have a main class, how is that even working?
@GeckoLink
@GeckoLink 6 жыл бұрын
He's using Processing, which makes it really easy to make graphical applications by abstracting a lot of the boilerplate of java. Processing doesn't need a main method, it uses setup and draw methods instead
@abhigyanrastogi1662
@abhigyanrastogi1662 6 жыл бұрын
Thanks! I scratched my head around for a bit on that one.
@GeckoLink
@GeckoLink 6 жыл бұрын
No problem! I'd highly recommend checking out processing, it's super useful and really easy to use
@anteconfig5391
@anteconfig5391 6 жыл бұрын
idk why but for some reason I feel like I could turn this into a pseudorandom number generator.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
I love this idea!
@johncerpa3782
@johncerpa3782 6 жыл бұрын
how can you write those two functions (turnRight and turnLeft) in one line of code?
@danielgrunkin8705
@danielgrunkin8705 6 жыл бұрын
If you know which way to turn (-1 for left, +1 for right) you could do this: dir = (dir + turn) % 4;
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
I think you'd have to say: dir = (dir + 4 + turn) % 4; Otherwise it won't work with dir = 0 and turn = -1.
@danielgrunkin8705
@danielgrunkin8705 6 жыл бұрын
The Coding Train Thanks for pointing that out! You are right, forgot how modulus works in Java :)
@corruptconverter2616
@corruptconverter2616 2 жыл бұрын
@@danielgrunkin8705 Or, you can use "& 0b11" instead of % 4 to avoid that problem. Then you could ditch the + 4
@paraglide01
@paraglide01 6 жыл бұрын
Yeah, Processing. Do fullScreen() please.
@ceezgeez1793
@ceezgeez1793 5 жыл бұрын
JavaScript version?
@TheCodingTrain
@TheCodingTrain 4 жыл бұрын
You'll find it here! thecodingtrain.com/CodingChallenges/089-langtonsant.html
@grainfrizz
@grainfrizz 6 жыл бұрын
MODULUS! :p
@charbelsarkis3567
@charbelsarkis3567 6 жыл бұрын
Why is it mirrored
@msclrhd
@msclrhd 6 жыл бұрын
The direction the ant will move in diagonally depends on which direction it is facing initially (north, south, east, or west).
@mountolympus1098
@mountolympus1098 6 жыл бұрын
coding channel inspired me to jave my own channel my channel is basic version of javascript
@soumyamohapatra7621
@soumyamohapatra7621 6 жыл бұрын
I'll stick with p5
@julitoytqww2219
@julitoytqww2219 4 жыл бұрын
Hola
Coding Challenge #90: Floyd-Steinberg Dithering
28:51
The Coding Train
Рет қаралды 436 М.
Coding Challenge #86: Cube Wave by Bees and Bombs
30:09
The Coding Train
Рет қаралды 628 М.
Harley Quinn's desire to win!!!#Harley Quinn #joker
00:24
Harley Quinn with the Joker
Рет қаралды 16 МЛН
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 139 МЛН
Meet the one boy from the Ronaldo edit in India
00:30
Younes Zarou
Рет қаралды 16 МЛН
Coding Challenge 124: Flocking Simulation
42:27
The Coding Train
Рет қаралды 329 М.
Ant On A Rubber Rope Paradox
12:10
Vsauce2
Рет қаралды 7 МЛН
Coding Challenge #132: Fluid Simulation
54:31
The Coding Train
Рет қаралды 638 М.
Coding Challenge #113: 4D Hypercube (aka "Tesseract")
43:53
The Coding Train
Рет қаралды 251 М.
Langton's Ant
12:50
CyberHelix
Рет қаралды 34 М.
Coding the Hilbert Curve
28:08
The Coding Train
Рет қаралды 111 М.
Solid Programming - No Thanks
32:00
ThePrimeTime
Рет қаралды 282 М.
Harder Drive: Hard drives we didn't want or need
36:47
suckerpinch
Рет қаралды 1,6 МЛН
Coding Challenge 180: Falling Sand
23:00
The Coding Train
Рет қаралды 876 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,7 МЛН
Harley Quinn's desire to win!!!#Harley Quinn #joker
00:24
Harley Quinn with the Joker
Рет қаралды 16 МЛН