Coding Challenge

Sdílet
Vložit
  • čas přidán 5. 08. 2024
  • In this coding challenge, I implement a pixel-based “fire” algorithm using Processing (Java). Code: thecodingtrain.com/challenges...
    🕹️ p5.js Web Editor Sketch: editor.p5js.org/codingtrain/s...
    🎥 Previous video: • Coding Challenge 102: ...
    🎥 Next video: • Coding Challenge #104:...
    🎥 All videos: • Coding Challenges
    References:
    📓 Fire Simulation: web.archive.org/web/201604180...
    💾 Processing: processing.org
    Videos:
    🚂 What is Perlin Noise?: • 13: What is Perlin Noise?
    🔴 Livestream Archive: • Live Stream #136: More...
    Related Coding Challenges:
    🚂 #102 2D Water Ripple: • Coding Challenge 102: ...
    🚂 #132 Fluid Simulation: • Coding Challenge #132:...
    Timestamps:
    0:00 Introduction
    0:39 Fire algorithm
    1:11 Let's Code
    2:30 Add image buffers
    5:20 Implement smoothing algorithm
    11:58 Add cooling map
    15:57 Introduce Perlin noise field
    17:58 Add noise to the cooling map
    22:04 Scroll the cooling map
    24:32 Experiment with graphics objects
    26:18 Add mouseDragged
    27:52 Conclusion
    Editing by Mathieu Blanchette
    Animations by Jason Heglund
    Music from Epidemic Sound
    🚂 Website: thecodingtrain.com/
    👾 Share Your Creation! thecodingtrain.com/guides/pas...
    🚩 Suggest Topics: github.com/CodingTrain/Sugges...
    💡 GitHub: github.com/CodingTrain
    💬 Discord: / discord
    💖 Membership: czcams.com/users/thecodingtrainjoin
    🛒 Store: standard.tv/codingtrain
    🖋️ Twitter: / thecodingtrain
    📸 Instagram: / the.coding.train
    🎥 Coding Challenges: • Coding Challenges
    🎥 Intro to Programming: • Start learning here!
    🔗 p5.js: p5js.org
    🔗 p5.js Web Editor: editor.p5js.org/
    🔗 Processing: processing.org
    📄 Code of Conduct: github.com/CodingTrain/Code-o...
    This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
    #firesimulation #perlinnoise #processing #p5js

Komentáře • 152

  • @mebamme
    @mebamme Před 6 lety +105

    25:00
    Coding Challenge, A to Z,
    interviews and live streams,
    P5, Processing,
    front-end API
    Particles, Fireworks,
    10PRINT, Flappy Bird,
    Game of Life, Supershapes,
    approximating Pi
    GitHub, pull requests,
    Linting, unit tests,
    this.dot, MousePressed,
    random Perlin noise
    Unicorn, rainbow,
    neural network, Tensorflow,
    learning and intelligence,
    chatbots using voice
    Vectors, matrix math,
    A* finds the shortest path,
    Javascript, ES6,
    cutting for a bugfix
    Dan did start the fire
    He was always coding, had the pixels loading
    Dan did start the fire
    He did not invent it, but did implement it~

  • @rocketmagnet3844
    @rocketmagnet3844 Před 6 lety +103

    Hey, great to see that people are still enjoying articles from my web site, even though it's just in the archive. How did you even find it? Try adding the warp map for really cool looking fire. - Hugo Elias

    • @gamesvrtech6666
      @gamesvrtech6666 Před 6 lety +1

      Are you really Hugo Elias? Cool!!! I was looking for the code for the water ripples a few years ago already and found a lot of forum threads pointing to the website.
      Funny though coming to the same page again when searching for fire! :-)

    • @rocketmagnet3844
      @rocketmagnet3844 Před 6 lety +1

      Hi, yes. It's really me. :) Let me know if there's anything else you need, or any questions about the algorithms.

    • @rocketmagnet3844
      @rocketmagnet3844 Před 6 lety +4

      Someone at work was watching your videos, and heard you mention my name!

    • @gamesvrtech6666
      @gamesvrtech6666 Před 6 lety +2

      Fabulous!! Maybe you should get in touch with Dan, I assume he'll be very happy and curious to hear from you!
      As someone pointed out already I guess the whole idea of making this water ripple and/or fire effect dates back to the demo scene of the early 90s or even 80s...

    • @gabrieleiro4181
      @gabrieleiro4181 Před 5 lety +1

      man if you're really hugo i'd love to see you in the train. get in contact with dan, i'm sure he'll like this collab too. btw do you have a website/blog where you post more recent stuff?

  • @adamsero1249
    @adamsero1249 Před 6 lety +1

    I just wanted to say thank You for motivating me to start learning java through p5.js and Processing and overall for great attitude in all your videos! Now I can actually do some satisfying creations instead of some boring algorithms and being stuck in console like i do in school. Thanks Dan!

  • @dl0.0lb
    @dl0.0lb Před 2 lety

    Thanks for sharing - I first learned about this algorithm in the early 90's from a friend and implemented in QBasic and Freebasic back in the day. Was trying to remember it to play with making a Rust demo and came across this video. Good stuff!

  • @loicoberle6156
    @loicoberle6156 Před 6 lety +2

    Now you just need to make an earth effect and a wind effect and you will have the four elements!
    Also it was a while since we didn't hear about perlin noise from you ,i was beginning to worry !
    Love your work Dan !

  • @goodev
    @goodev Před 6 lety

    Always great to watch your videos!

  • @xxagnasiusxx8618
    @xxagnasiusxx8618 Před 6 lety +6

    OMG He did it^^ I didn't think you were going to edit this together :)
    (watched that whole stream live then^^)
    It was funny^^

  • @albertkovtoun662
    @albertkovtoun662 Před 6 lety +3

    Love this!

  • @marcusbluestone2822
    @marcusbluestone2822 Před 6 lety

    This is actually so cool! Thanks so much!

  • @rikilshah
    @rikilshah Před 5 lety

    Thanks for yet another awesome video!

  • @liquidexw
    @liquidexw Před 6 lety +10

    _// tip:_
    void settings() { _// use void settings() for variable sizes_
    size(yourWidth, yourHeight, FX2D); _// use the FX2D renderer for much better performance_
    }

  • @OrangeC7
    @OrangeC7 Před 6 lety +22

    Be kind to the elephants!

  • @kmjohnny
    @kmjohnny Před 6 lety

    I'll definitely will try to play with this around.

  • @marquetemarquete
    @marquetemarquete Před 6 lety +2

    You could try something simpler than noise: randomizing the generator rows at the bottom. Instead of filling them with white pixels, toss a coin (which might very well not be fair) to decide on white or black. I think it would be easiest with the code you had at roughly 14:10.
    Thank you for all the great videos!

  • @luismiguelgallegogomez8000

    Liked the new adjective, grayscaly! :)

  • @ShranjaniShukla
    @ShranjaniShukla Před 6 lety

    Hey dan! I am a great fan of yours. You are the one who took my cmd small coding to another level teaching me JAVA AND JAVASCRIPT and i would like to ask a favour...
    would you consider making a tutorial series with the p5 arduino library

  • @CYON4D
    @CYON4D Před rokem

    Awesome.

  • @clipsus_clips
    @clipsus_clips Před 6 lety

    yey! you finnaly covered fire. Thanks. you may only also want to color it :)

  • @CloudWalkBeta
    @CloudWalkBeta Před 6 lety +8

    This gives me an idea, ever try using perlin noise to try making a digital lava lamp? Iv been looking for a way to programme a believable lava lamp for awhile and this video might have given me the solutions iv been looking for.

    • @gamesvrtech6666
      @gamesvrtech6666 Před 6 lety +2

      Hey Beta, Dan's code from the "Metaballs" video looks a bit like a lava lamp, I had the same thought when I tried it out.

  • @lenardvandermaas6893
    @lenardvandermaas6893 Před 6 lety +2

    @thecodingtrain I challenge you to visualize a rope that hangs from 2 points with a specified length, using math (so not just showing an image from google :P) so basically: changing the catenary formula to depend on those 2 points and the length instead of the lowest point of the line and some other value that determines how quickly it 'opens up'.

  • @marcos772
    @marcos772 Před 4 lety

    This video is fire

  • @tommydrager5497
    @tommydrager5497 Před 3 lety

    "so much to 'starting with that code'" xD Every coding challenge I have to laugh out loud at least once xD.

  • @daniilparokonnyy7980
    @daniilparokonnyy7980 Před 6 lety +1

    Nice ending

  • @TheMyguitarisblue
    @TheMyguitarisblue Před 5 lety +1

    Drinking game: Shot every time Dan says that he should be more thoughtful about something

  • @KikoMovilla
    @KikoMovilla Před 3 lety

    u r awesome! 3 weeks ago I have no idea about javascript (just android and some html), today I downloaded processing and tried my mod version of this if u wanna watch. I'll leave code below. I cant believe how much I learn in ur videos. its most than a coding chanel, pure maths.

    • @KikoMovilla
      @KikoMovilla Před 3 lety

      PImage gr, cmp, sum;
      float start = 0.0, xo, yo, increase, noi, value;
      // this is the treshold for masking the flames
      float cap = 160;
      //this value should increased accord to lower resolution (size)
      float trh = 1.2;
      int w = 400;
      int h = 200;
      int ind, index;
      float r, a, c;
      color g, n;
      void setup() {
      size(400, 200);
      frameRate(30);
      gr = createImage(w, h, RGB); //done
      cmp = createImage(w, h, RGB);
      sum = createImage(w, h, ARGB);
      gradient();
      }
      void noiseMap(){
      //generate a noise map
      cmp.loadPixels();
      //x offset
      xo = 0.0;
      increase = 0.01;
      for(int i = 0; i < w; i++){
      xo += increase;
      yo = start;
      for(int j = 0; j < h; j++){
      yo += increase;
      //noise value
      noi = noise(xo, yo);
      //noise value eq to color value
      value = pow(noi,3)*255;
      cmp.pixels[i + j * w] = color(value);
      }
      }
      cmp.updatePixels();
      //scroll up noise map
      start += 0.06;
      }
      void gradient(){
      //generate a gradient from black to white
      gr.loadPixels();
      //throw columns
      for(int i = 0; i < w; i++){
      //reset every row;
      float val = 0;
      //runing throw rows
      for(int j = 0; j < h; j++){
      int index = i + j * w;
      gr.pixels[index] = color(val);
      val += trh;
      }
      }
      gr.updatePixels();
      }
      void draw(){
      noiseMap();
      background(0);
      //combine both images
      gr.loadPixels();
      sum.loadPixels();
      for(int i = 0; i < w; i++){
      for(int j = 0; j < h; j++){
      ind = i + j * w;
      //load pixels from both maps in same position
      g = gr.pixels[ind];
      n = cmp.pixels[ind];
      //combine both colors
      c = brightness(g) - (3*brightness(n));
      //looks like smoke, so we have to divide in 2 channels
      r = (pow(c,2)/sqrt(c))/1.5;
      a = (c+(r/c))*1.2;
      if(c

  • @JohnDoe-ze8po
    @JohnDoe-ze8po Před 6 lety

    I tried implementing this with p5js, but somehow after turning on the 'smoothing' my cpu jumps to 110% and i only see my red line and some weird white/black glithcy lines through the black background (and then the whole buffer looks like it crashes) ...
    Also when running your pde with processing js inside a webpage i see some sort of animation but nothing compared to your video?

  • @tctrainconstruct2592
    @tctrainconstruct2592 Před 4 lety

    I didn't know that YOU have created this Perlin Noise Field!!!

  • @jojozak624
    @jojozak624 Před 6 lety

    Hello, I am trying to design a website header where it is made up of little squares and when the mouse hovers over or you click on one of the squares they all scatter or move out of the screen.. Could you tell me how I can do that?

  • @giselleplascencia8984
    @giselleplascencia8984 Před 6 lety

    love your videos! I have a side question... I have an ellipse as a button that links to another page using window.open('') but it links it to another tab. is there a way to open the link in the same page, rather than opening a new tab using the p5 library?
    TIA!!

    • @thimkthimk
      @thimkthimk Před 6 lety

      window.open("www.youraddress.com","_self")
      Found this on stackoverflow:
      stackoverflow.com/questions/8454510/open-url-in-same-window-and-in-same-tab

  • @adeelfarzandali
    @adeelfarzandali Před 6 lety

    How would you intersect or make union of two objects like rectangles or circles? make the intersected part new object as it is done in tools Illustrator?

  • @leozzl1310
    @leozzl1310 Před 6 lety

    Hi i have qouastion.
    Can i in p5.js make my game i mean aplication and how to do that? {If i alredy now how programing game how to "build" that i dont now how else to explane}

  • @gomo8651
    @gomo8651 Před 6 lety

    2x speed and this guy is rockin da haos :)

  • @eu123321able
    @eu123321able Před 5 lety +1

    The secret of a good pixel-based fire algorithm is in the color palette.
    Look at my version inspired by the Final DOOM algorithm:
    github.com/lsmanoel/DoomFireEffect_ProcessingVersion

    • @TheCodingTrain
      @TheCodingTrain  Před 5 lety

      Nice work! You can submit a link to the coding train website if you like!
      github.com/CodingTrain/website/wiki/Community-Contributions-Guide

  • @donfoumare
    @donfoumare Před 6 lety

    Isn't the whole point of using loadPixels() and updatePixels() to prevent you from overwriting the actual image data array while reading from it? Which basically makes the whole swaping-buffer-thing redundant?

  • @Bloom_HD
    @Bloom_HD Před 6 lety +11

    16:36
    Mister, no offence, but you're absolutely crazy!

    • @isaacchen6630
      @isaacchen6630 Před 6 lety +2

      Bloom HD ohh my gosh no! It's so beautiful!

  • @dfgchjhkbnl
    @dfgchjhkbnl Před 6 lety

    I'm a 3rd year Computer Science student with NO portfolio other than the projects we made in class. These Coding Challenges are really cool! Is there a good website/list that has a ton of these to try to code them myself (Else Ill just pick out some of my favourites from your videos)?

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      You can find the full list here: thecodingtrain.com/CodingChallenges/

  • @WilsonFerguson
    @WilsonFerguson Před 3 lety

    How are you getting intellisense for the Processing IDE?

  • @paragjagtap9220
    @paragjagtap9220 Před 6 lety

    Nice sir

  • @matheusspable
    @matheusspable Před 6 lety

    Say, just a random thought, but doesn't the shape and colors of the ending animation (yeah... the one with you on top of the train), it kiiiiinda, (and I really mean kind of), seems to spell Google?? with the colors and the blurr? Just thought I saw that... Maybe it's too late and I need sleep...

  • @mmheti
    @mmheti Před 6 lety

    The brighter (hotter) pixel is it should scroll bigger amount up (faster). That is how convection works.

  • @roizdoci
    @roizdoci Před 6 lety

    Hey Mr Shiffman, can you tell me a good channel for me to learn python?

  • @patricks5997
    @patricks5997 Před 6 lety

    Can you program C TheCodingTrain?

  • @papinkelman7695
    @papinkelman7695 Před 6 lety +7

    How did we live before map()?
    I know, I am slow.

    • @Kitulous
      @Kitulous Před 3 lety

      Map is basically lerping with time equal to inverse lerping.
      map(val, a, b, c, d) = lerp(c, d, inverseLerp(a, b, val))

  • @ezanchi5422
    @ezanchi5422 Před 6 lety

    What microphone does he use on his ear?

  • @manishbasnet8398
    @manishbasnet8398 Před 6 lety

    Not first commenter but at least Second commenter.Great sir..Can u make video on mongodb ?????

  • @xehn
    @xehn Před 3 lety

    where can i find the code base?

  • @SimonVovko
    @SimonVovko Před 3 lety

    Why newC * 0.25 instead of newC / 4? Is it faster?

  • @the_real_sliix
    @the_real_sliix Před 4 lety

    I just had flashbacks to the long Skyrim loading screens

  • @ALEXANDERMYLONAS
    @ALEXANDERMYLONAS Před 6 lety

    Fuego

  • @MrMattical123
    @MrMattical123 Před 6 lety +11

    Who dislikes this video?? Like seriously who comes on here and says "ya know what? Screw this guy" and clicks the dislike button? Must be a bunch of VisualBasic fans or something

    • @kustomweb
      @kustomweb Před 6 lety +1

      Matt Thibodeau I truly miss VB.... With VBScript and VBA, you could make wonderful things. Wish I knew Nature of Code back then.🙂

    • @MrMattical123
      @MrMattical123 Před 6 lety

      kustomweb I just meant it as a joke, it's actually a really cool little language

    • @mikelezhnin8601
      @mikelezhnin8601 Před 6 lety +1

      Nah, there is something to Dan that makes people cringe. maybe that is why ppl dislike the vid. Dunno.

    • @MrCmon113
      @MrCmon113 Před 6 lety

      Who told you that the dislike button means "screw that person"?
      Stop taking everything personally. Also the video has only FIVE downvotes even now. What more do you even want, you crazy little authoritarian?

    • @MrMattical123
      @MrMattical123 Před 6 lety

      Taxtro yikes, someone can't take a joke :P

  • @georegesef
    @georegesef Před 4 lety +1

    title "fire effect"
    join video, i just see some weird bubbles nice

  • @alejandroalfonsohernandez3766

    this is interesting, but please, I want deep learning´s videos using tensorFlow!
    What if you make a game that we can play against an AI using Deep Learning, that would be amazing!!

  • @bobpuley
    @bobpuley Před 6 lety

    big! :)

  • @darthtorus9341
    @darthtorus9341 Před 6 lety +3

    Dan, your algorithm is a bit off. You subtracted the cooling before dividing. You need to subtract the cooling after taking the average of the four neighbors

    • @renecura
      @renecura Před 6 lety

      Darth Torus haha I'm comming to say that, it's making me crazy!

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety +6

      Yes! I noticed this after the fact. The code on github is corrected. Thanks for the comment!

    • @darthtorus9341
      @darthtorus9341 Před 6 lety +3

      The Coding Train You could also add wind to blow the flames. If the wind is too much, the fire goes out

  • @dylansanderson3386
    @dylansanderson3386 Před 6 lety

    Would it help me be better at programming if I watched these speed videos and tried to follow along with my own compiler¿

    • @UnleashedDan
      @UnleashedDan Před 6 lety

      (that's how i improved my coding :D (altho i watch the entire video first, then try to recreate the project

  • @thespyinthehole1609
    @thespyinthehole1609 Před 6 lety

    How do you find the algorithms you use in the coding challenge?

  • @Tentin.Quarantino
    @Tentin.Quarantino Před 4 lety

    #Codingwithfire would've been an awesome name.

  • @framegrace1
    @framegrace1 Před 6 lety +2

    That was a common demoscene trick. One of the starter tricks noobs like me programmed Back in the day. My First Pascal/ASM code. (Yeah, that was the fashion back then, Pascal + ASM)
    I think is from 1992 or 1993. (I got it from a book). Can't remember his name, but the first guy who did it was kinda famous.

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      Thanks, I'd love to make sure I credit the original source properly!

    • @mikelezhnin8601
      @mikelezhnin8601 Před 6 lety

      It may be common, but maaan it looks so good + it is so fast!

  • @karmaindustrie
    @karmaindustrie Před 5 lety +1

    9:22 DRAIN THE SWAP!!

  • @rlasc84
    @rlasc84 Před 6 lety

    Hello Dan. Can you make a video about de es6 spread operator?

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues

  • @MaoDev
    @MaoDev Před 6 lety +1

    Why don't you use vanilla JavaScript for coding challanges?

    • @isaacchen6630
      @isaacchen6630 Před 6 lety

      MaoItsMe I can't speak for Dan, but for me it got tedious rewriting stuff like:
      let canvas = document.getElementById("myCanvas");
      let ctx = canvas.getContext("2d");
      ctx.fillStyle = "#FF0000";
      ctx.beginPath();
      ctx.arc(x+50, y+50, 50, 0, Math.PI * 2);
      ctx.closePath();
      ctx.fill();
      Over and over again instead of:
      fill(255, 0, 0);
      ellipse(x, y, 100, 100);

    • @MaoDev
      @MaoDev Před 6 lety

      Isaac Chen oke

  • @benstoffels5108
    @benstoffels5108 Před 6 lety

    You should try to make a Mastermind game

  • @simeon2396
    @simeon2396 Před 6 lety +6

    #codingflames

  • @okarakoo
    @okarakoo Před 6 lety

    Does Daniel speak with a lisp? Odd, I had never realized it before

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      I think maybe a little? I'm using a new mic here that brings it out more.

  • @PumpiPie
    @PumpiPie Před 6 lety +1

    are the source free to use?

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      Yes! You can find everything at thecodingtrain.com / github.com/CodingTrain/website

    • @PumpiPie
      @PumpiPie Před 6 lety +1

      cool :D
      Thanks and keep up the good work :D

  • @user-oc5uc3gi2p
    @user-oc5uc3gi2p Před 6 lety

    You're fucking cool dude

  • @THE16THPHANTOM
    @THE16THPHANTOM Před 6 lety +1

    i dont use twitter, i wish you could just post links here in the comments

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      You can and i'll take a look! You can submit a link to the coding train website if you like too:
      github.com/CodingTrain/website/wiki/Community-Contributions-Guide

  • @codedragon6237
    @codedragon6237 Před 6 lety

    With all due respect, that looks more like smoke than fire. But it is a good simulation of smoke

    • @UnleashedDan
      @UnleashedDan Před 6 lety

      because its an grey-scale, with orange it looks pretty good

  • @DanielBoa
    @DanielBoa Před 6 lety

    Hey Daniel, I'm currently a patreon, would it be better to sponsor you via CZcams?

    • @TheCodingTrain
      @TheCodingTrain  Před 6 lety

      It's really up to you! For now I am using both, some more explanation here: czcams.com/channels/vjgXvBlbQiydffZU7m1_aw.htmlcommunity?lb=UgyXzi4X1jxv6y08d-t4AaABCQ

    • @DanielBoa
      @DanielBoa Před 6 lety

      Thanks for the link, I thought I likely missed a discussion somewhere! In that case I'll just stick to patreon for the time being and keep an eye on how the sponsor feature pans out.

  • @tylergold6978
    @tylergold6978 Před 6 lety

    You should try to code Atari breakout...

  • @xavierbradford5528
    @xavierbradford5528 Před 4 lety +1

    Search setting: is purple
    Me: >_>

  • @rishabhbhatnagar6795
    @rishabhbhatnagar6795 Před 6 lety

    Which language is this??

  • @the9tailsupersaiyan
    @the9tailsupersaiyan Před 6 lety +5

    Do a coding challenge with python.

  • @ratkabu
    @ratkabu Před 6 lety +19

    Why is that your videos looks like not monetized?
    I challenge you to try any kind of different language, Python and create an app from it..

  • @saltzliu
    @saltzliu Před 6 lety

    code challenge recommendation: implement firefly simulation
    en.wikipedia.org/wiki/Firefly_algorithm

  • @franchello1105
    @franchello1105 Před 6 lety +1

    We didn't start the fire.

  • @yashwanthd1998
    @yashwanthd1998 Před 4 lety

    Just a reminder 🔥 is not white though

  • @jared8807
    @jared8807 Před 6 lety

    Hi

  • @dustnoiseplays
    @dustnoiseplays Před 6 lety +1

    why java tho?

  • @hii4973
    @hii4973 Před 6 lety

    first

  • @JonWKND
    @JonWKND Před 6 lety +2

    That smoke no fire :-)

  • @eliottuliocamaradonge2706

    Allumer le feu !!!!!!!!!!!!!!
    French joke (I'm French)

  • @weluvmusicz
    @weluvmusicz Před 6 lety

    Another HUGE challenge for you: Don't use Java...

  • @ilijapavlovic7498
    @ilijapavlovic7498 Před 6 lety

    What is the secret of your happiness? U are the best!!!
    P.S. dont tell me u are using drugs...

  • @Rockvik332
    @Rockvik332 Před 6 lety

    You are in use of language

  • @WyMustIGo
    @WyMustIGo Před 2 lety

    I wrote something that looked better than this about 30 years ago.