Coding Challenge #61: Fractal Spirograph

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 152

  • @4AneR
    @4AneR 8 лет назад +105

    I am always glad to spend 20 minutes to draw a circle together with you, Dan :D

  • @unityblitz2755
    @unityblitz2755 8 лет назад +17

    I have no idea how I found you since when I did, code wasn't even in my vocabulary.But been subbing for a while now and started to learn which was amazing! Right now I've finished my second month of a course I took for programming and absolutly love it!
    You have truly opened my eyes for math and writing code, you're my hero and idol!
    Thank you so much for creating your channel!

  • @RobLego
    @RobLego 7 лет назад +2

    Daniel is so hard on himself. He's really brilliant. Yes Dan, we are still watching... because it is amazing. I am trying to learn javascript by watching your videos. And thanks to you, I'm starting to get it. This guy has such a crazy knowledge of coding, and math, it's crazy.

  • @michalbotor
    @michalbotor 6 лет назад +3

    15:10 i actually enjoy the fact, that properties in processing can be written without the 'this' keyword, because it make the code so much more concise and readable. when i watch your p5.js tutorials it gets ridiculous sometimes , when you can't fit a function call on one line of code just because it must contain 'this' like 5 times.

  • @joem8251
    @joem8251 5 лет назад

    2 years later and your video is still helpful! I like how you took the video offline for debugging in this one and only referenced a longer segment if we want to follow your thought process. Nice challenge.

  • @nero3700
    @nero3700 8 лет назад +1

    Watched and rewatched the livestream, but I'm here to check out how this was edited :D
    Awesome work Dan, as always!

    • @gonengazit
      @gonengazit 8 лет назад +2

      nero3700 you watched it twice?!?!?! You sir, are a madman

  • @aramavlad-alican9959
    @aramavlad-alican9959 6 лет назад

    I camnot stop watchi g your videos, i have been seeing them over and over again about 5 time each

  • @DY142
    @DY142 8 лет назад +6

    Hey mate! I don't know if somebody already pointed it out-but calculating k^(n-1) for each level is equivalent to multiplying each level's ang velocity by k with respect to the previous. That is the definition of the power function!
    So that change didn't do any difference. Just leave it as it was and save some calculations, mate :D

    • @kuskus_th13
      @kuskus_th13 8 лет назад

      padronsk or just k multiplied by itself (n-1) times

  • @dawalton7435
    @dawalton7435 6 лет назад +1

    its the worst when you hear the words #codingtrainwreck and realise that there are still five more minutes of the video :) still love the videos!

  • @dogbadjaze600
    @dogbadjaze600 6 лет назад

    It was a pleasure. Thank you very much.

  • @troyanrider
    @troyanrider 6 лет назад +1

    After using the math formulas for the speed “this resembles the previous pattern really well”... There’s a really good reason for that: both calculations were the same: k^(n-1) = k*(k^(n-2)), being the previous times that constant. Hilarious 😂

  • @pbpbpbpbpbpbpbpbpb
    @pbpbpbpbpbpbpbpbpb 8 лет назад +14

    I'm always exited if you upload something with fractals. How do you find these things?
    Also, you are awesome!

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад +6

      This was a suggestion from a viewer! github.com/CodingTrain/Rainbow-Topics/issues/11

  • @JuanJAzpiroz
    @JuanJAzpiroz 8 лет назад +4

    I'm amazed with your creations David. Many thanks. Could you teach us someting using Bezier curves?

    • @jovdsss
      @jovdsss 7 лет назад +1

      whos David?

  • @robtvogel
    @robtvogel 8 лет назад +1

    I was doing this in p5js along with you and very often had to remind myself "this dot". The song was stuck in my head after awhile.
    P.S. I do see that you already converted this to p5js in your github page after i finished the video.

  • @duality4y
    @duality4y 4 года назад

    My Current project unrelated to this, but still i watch this while i work on my own project because it's all so facinating and interessting and it's good to have heard of it once like when you work on something and think need to solve this thing and i think i heard about this one thing you can look these videos up it's nice.

  • @liquidlulz1373
    @liquidlulz1373 3 года назад +1

    How would we stop this from drawing oven itself in the end? Thanks!

  • @rebornreaper194
    @rebornreaper194 3 года назад

    Reminds me of those ties with the crazy gyroscopic leaf shapes

  • @Zxios
    @Zxios 8 лет назад +40

    oh yeah. I caught this live, it was a #codingtrainwreck :P

    • @callummann4410
      @callummann4410 8 лет назад

      It's the only trainwreck you look forward to !

    • @doityourself73
      @doityourself73 8 лет назад

      Try to code a simple/basic ego shooter

  • @Quiksand101
    @Quiksand101 7 лет назад

    If you want to give the entire thing a flickering effect like in the GIF, just add noise to whole orbit

  • @Pankeekii
    @Pankeekii Год назад

    How would you stop it from drawing over itself indefinitely?

  • @asdfghjklooish
    @asdfghjklooish 6 лет назад +8

    Your data structure was perfect until you added the while loop in draw(). I think the best solution is to assign the parent the responsibility of drawing the child and likewise with update(). So instead of a while loop, just parent.draw() and in the parent have draw() { /* draw parent */ child.draw() }. You could even do the same with addChild() like { if(child == null) { this.child = new Child() } else { child.addChild() }
    Other than that, I love your videos, your charisma, and your passion so keep it up!

  • @duality4y
    @duality4y 4 года назад

    Can you trace out a mandel brot with circles?

  • @tpat90
    @tpat90 8 лет назад +1

    The moment you switched times -x parent speed to -x^k
    It not even resembled what you had before the cut, it was actually the same thing...
    In your way you just didn't had to calculated it again and again.

  • @LifEsYouTubeChannel
    @LifEsYouTubeChannel 7 лет назад +1

    Can you make Tetris tutorial in Processing?

  • @Texplanations
    @Texplanations 8 лет назад

    Yes!!! This is what I tried to do but got the idea a bit messed up... Did the program properly... But not the rotation things cause I forgot the name of this...

  • @my_virtual_officemyvritsys688
    @my_virtual_officemyvritsys688 6 лет назад

    can i run python in an email as the running program?

  • @erikmccall6577
    @erikmccall6577 8 лет назад

    sweet vid man! I was wondering if you could do more on 3d in p5? love your channel! thank you so much!

  • @trevordendel4257
    @trevordendel4257 4 года назад +1

    How is no one talking about the cardiod-like shape he drew at 35:58?!

  • @Doge317
    @Doge317 8 лет назад

    Fractals are really interesting. Can you do a program about the Mandelbrot set? Would be awesome

    • @kuskus_th13
      @kuskus_th13 8 лет назад +1

      Doge He already did it as a coding challenge in p5.js. Search the playlist!

    • @Doge317
      @Doge317 8 лет назад

      oh really? Nice thank you for pointing that out ^^

  • @BigB1Lachi
    @BigB1Lachi 4 года назад +1

    //Speed should be defined by the radii of its parents
    //this means all circles roll on the surface of their parents at the same relative speed
    if (parent.parent == null){
    speed = 1
    }{elseif( parent == null){
    speed = 0
    }else{
    speed = parent.parent.r / parent.r
    }

  • @kevinfulghum7524
    @kevinfulghum7524 8 лет назад

    what are your settings for p5.Js?

  • @ashleyburgess5923
    @ashleyburgess5923 6 лет назад

    Can this be coded in a 3D space?

  • @mouhcine4831
    @mouhcine4831 8 лет назад

    Nice !

  • @sergioflorea6063
    @sergioflorea6063 8 лет назад

    The first one is an orphan, and the last one is forever alone, how fitting.

  • @freeshavaacadooo1095
    @freeshavaacadooo1095 6 лет назад +2

    Hey Dan! I've been watching you for a while and I love to simplify any code to try to get better at programming. It's not perfect but maybe you could repurpose this code I made that can randomly generate a spirograph. It's 27 lines long and if you can shorten it, even more, it would be awesome. (Tried to use some recursion to help practice it as a skill as I am new to coding):
    var array = [], points = [];
    function setup() {
    createCanvas(600, 600);
    for(var i = 0; i < 3; i++) {
    array[i] = [];
    array[i][0] = Math.random()*20+20;
    array[i][1] = 0;
    array[i][2] = ((Math.random()*4)/180)*PI;
    }
    }
    function draw() {
    background(15, 15, 15);
    circleGraph(0, width/2, height/2);
    }
    function circleGraph(i, x, y) {
    if(i < array.length) {
    array[i][1] += array[i][2]
    return circleGraph(i+1, x+(array[i][0]*cos(array[i][1])), y+(array[i][0]*sin(array[i][1])));
    } else {
    points[points.length] = [x, y];
    for(var j = 1; j < points.length; j++) {
    stroke(255, 255, 255); line(points[j][0], points[j][1], points[j-1][0], points[j-1][1]);
    }
    }
    }

  • @masterflamaster6377
    @masterflamaster6377 8 лет назад

    Wow, you haven't abandoned Processing yet? YESSSSS

  • @ironmon9
    @ironmon9 8 лет назад

    Daaaamn Daniell

  • @wengeance8962
    @wengeance8962 8 лет назад

    what makes you choose to do some coding challenges in Java(processing) vs JavaScript (p5)? thanks

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад

      Honestly it's pretty arbitrary! I discuss some more reasons in my "comparing p5 and processing" Q&A videos.

    • @wengeance8962
      @wengeance8962 8 лет назад

      Thanks, ill check those.

  • @gloubiboulgazeblob
    @gloubiboulgazeblob 5 лет назад

    Here's an example of parent-child in Javascript, it works :
    In the main code, create a new TreeWaveVector(args are optionnals), then add childrens to it, one by one.
    class WaveVector {
    constructor(x, y, dimension, frequency, phase) {
    this.x = x === undefined ? 0 : x;
    this.y = y === undefined ? 0 : y;
    this.dim = dimension === undefined ? 1 : dimension;
    this.f = frequency === undefined ? 1 : frequency;
    this.phase = phase === undefined ? 0 : phase;
    }
    }
    class TreeWaveVector {
    constructor(x, y, dimension, frequency, phase) {
    this.waveVector = new WaveVector(x, y, dimension, frequency, phase);
    this.child = null;
    }
    add(waveVector) {
    //get last child of this entire tree
    let last = this.lastChild();
    last.child = new TreeWaveVector(
    last.waveVector.x + last.waveVector.dim * cos(last.waveVector.phase),
    last.waveVector.y + last.waveVector.dim * sin(last.waveVector.phase),
    waveVector.dim,
    waveVector.f,
    waveVector.phase
    );
    }
    lastChild() {
    let last = this;
    while (last.child) {
    last = last.child;
    }
    return last;
    }
    }

  • @rosslahive
    @rosslahive 7 лет назад

    Got through it from start to end :)

  • @vitalchance1032
    @vitalchance1032 3 года назад

    Wonder how many times he has programmed this same thing over and over and over again... So this video could be produced in fluidity and give the effect that this man is a god darn genius... Come on, tell usssss. tell usss. How many times..?? Give it up.. Tell us your deepest secrets..

  • @hamzanasab1713
    @hamzanasab1713 8 лет назад +2

    you livestream on youtube ?

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад +5

      yes indeed! Every Friday (and sometimes more often)

    • @liviuiosim1870
      @liviuiosim1870 8 лет назад

      The Coding Train do you have specific hours?

    • @kuskus_th13
      @kuskus_th13 8 лет назад

      Liviu Iosim 10:30 his time (~15:30 GMT)

  • @progfr9097
    @progfr9097 6 лет назад

    For a coding challenge coul'd you code a game that use gps data like the well known pokemonGo game. and if possible making it as an android app.

  • @CodingWithUnity
    @CodingWithUnity 6 лет назад

    I know this videos old and i could google it, but its an excuse to leave a comment. Instead of making another constructor in the orbit class, couldnt you just do `float x_, float y_, float r_, orbit parent_ = null` Which will default parent to null unless you set it when the constructor is called

  • @NickInts
    @NickInts 8 лет назад

    22:00 You made a linked list!

  • @alexcsillag7816
    @alexcsillag7816 8 лет назад

    I was wondering why is it not spinning.... I was searching for the mistake for about 20 minute and checked the github page, and nothing. I forgot to assign 0.1 value to the speed variable... oml

  •  8 лет назад +1

    22:02 RELIEF

  • @gustavoandre8866
    @gustavoandre8866 5 лет назад

    Speed(n) = k^(n-1), k=±2, ±3, ±4, .... what is "n" in this expression
    help please 1-1

  • @jasperdiscovers
    @jasperdiscovers 8 лет назад

    I did it! #codingtrainwreck but you fixed it :) Entertaining stuff.

  • @NonTwinBrothers
    @NonTwinBrothers 8 лет назад

    I don't think they where cheering in the hallway.. I think they were predicting the codingtrainwreck that was about to happen.

  • @naolmstead
    @naolmstead 8 лет назад

    Modify it so that the orbits alternate between being inside and outside the previous one. Say every odd level is outside it's parent and even is inside it's paerent

  • @benjamins2683
    @benjamins2683 7 лет назад

    i am going to follow your coding in c# :D

  • @MrZakrencony
    @MrZakrencony 8 лет назад +5

    watch unedited 2h of footage to see the debugging? I'm all over it :D

  • @BrunoInec
    @BrunoInec 8 лет назад

    How did you resist calling it "be nice equation"?

  • @thefiverranimator6518
    @thefiverranimator6518 8 лет назад +1

    how you make a video with background cool with zooming in real time, are you a group of people who help all this out...

    • @GABRIELFILMSTUDIOS
      @GABRIELFILMSTUDIOS 8 лет назад

      The Fiverr Animator Ähm, what exactly is your question?

    • @Trent-tr2nx
      @Trent-tr2nx 8 лет назад +1

      he uses the magnifier tool in Mac's accessibility options -- it's not a special editing tool

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад +1

      indeed!

  • @Holobrine
    @Holobrine 6 лет назад

    You can draw any image with “fractal spirographs”, if you are curious, see GoldPlatedGoof’s video on Fourier transformations.

    • @JackFlashTech
      @JackFlashTech 5 лет назад

      There might be a difference because Spirographs roll on each other, and Fourier representations can rotate the children as fast as they need.

  • @icode2206
    @icode2206 7 лет назад

    What is the app?

  • @ninjaclantech6421
    @ninjaclantech6421 8 лет назад

    Can you code conways game of life?

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад

      I'm thinking of doing it soon yes!

    • @KnakuanaRka
      @KnakuanaRka 6 лет назад

      He’s done that; check his challenges.

  • @JBFFSK18
    @JBFFSK18 8 лет назад

    #codingtrainrek or sth like that xDD
    as always great video, keep it up :D

  • @charbelsarkis3567
    @charbelsarkis3567 8 лет назад

    has he made this in p5?

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад

      Check the github repo I believe there are some ports listed in the README. If not, file a github issue!

  • @CrispySpicyChickenWings
    @CrispySpicyChickenWings 5 лет назад +1

    27:37 Hmmmmmmmteresting.................

  • @raegnald
    @raegnald 6 лет назад +1

    22:23 Awesome! With twenty-three minutes of video we have managed to draw two circles (But what he does he does well).

  • @StormCraftable
    @StormCraftable 7 лет назад

    I am Just sitting in front of my PC and kindly saying: "good sir, why not use a chain of responsibility?"

  • @michalbotor
    @michalbotor 6 лет назад

    29:48 piston! ;)

  • @damiandassen7763
    @damiandassen7763 7 лет назад

    that moment at 3:10

  • @lemonlordminecraft
    @lemonlordminecraft 7 лет назад +1

    "'parent'; 'child'. No I could call this 'sun';'moon'."
    What does the moon orbit...?

  • @NathanBreunig
    @NathanBreunig 7 лет назад

    I literally started adding con after all constructor variable names. I know how you feel. hahaha

  • @sprajapati566
    @sprajapati566 8 лет назад

    coding challenge : make a glitch effect video/image or anything.

  • @duality4y
    @duality4y 4 года назад

    Couldn't you do this.x = x; to indicated i am going to assign to this class attribute the value that is in parameter x. instead of doing x = x_; that is the convention i use in my code.

  • @mctuble
    @mctuble 8 лет назад

    Yeah I made it all the way through easily. It was very interesting to me #-1codingtrainwreck

  • @vitalchance1032
    @vitalchance1032 3 года назад

    "Coding challenge in an attempt" It's not a "challenge" when you mastered it, and already produced it multiple times before you act like you are giving it a "wing" -- Impressive none the less but come onnnnnnnnnnn, no way.. If this is a first "attempt", I might as well bury myself is junk food until I am no longer capable of thinking how unbelievable this is.

  • @angelcaru
    @angelcaru 5 лет назад +1

    The way I would do the "show everything" is, in the Orbit class:
    void show() {
    stroke(255);
    strokeWeight(2);
    noFill();
    circle(x, y, r * 2);
    if(child != null) {
    child.show();
    }
    }

  • @BrunoPontoTxT
    @BrunoPontoTxT 8 лет назад

    use trackingjs.com/ to "learn", "recognize" and display objects name in the screen

  • @charliejulietdavies8715
    @charliejulietdavies8715 8 лет назад +1

    heya, daniel! i got inspired by this idea so i paused and had a go before coming back and watching how you did it. i'm surprised how many things i ended up doing similarly to you!
    my code: www.openprocessing.org/sketch/409963
    a couple of interesting things i did differently:
    - made the draw function use the linked structure; each orbiter draws itself and tells the child to draw.
    - made each object dumb to it's position, putting that information in the draw function's parameters. unintentionally, that's how i avoided keeping a reference to the parent
    - just a small one and a question: i tend to want to put draw() and update() code in one method. is there a particular reason you always write it with two separate functions?
    excellent video as always.

  • @liquidexw
    @liquidexw 6 лет назад

    1:13 P🅱ector, huh?

  • @ALLCAPS
    @ALLCAPS 8 лет назад +1

    326 likes, 0 dislikes. WOW.... Impressive! (dislikes) xD jkjk

  • @MINHHOANG-hl7gp
    @MINHHOANG-hl7gp 8 лет назад +28

    like if you learn programing more from coding train than in school

    • @kuskus_th13
      @kuskus_th13 7 лет назад +4

      I don't know if schools even teach programming. Most don't. At all.

    • @dennisvaningen3827
      @dennisvaningen3827 7 лет назад

      KusKusPL in the netherlands many highschools do some basic coding but programming is very rare now I'm in college now and learn programming because thats my major🤷‍♂️

    • @Kitulous
      @Kitulous 6 лет назад

      KusKusPL we were learning programming in 9th grade by using algorithmic language (some really weird and useless language that consisted of RUSSIAN words and abbreviations (I live in Russia), it only had variables (with explicit types), loops and conditionals and custom procedures declarations. And that's all. No functions whatsoever. That was as bad as it could be, so I used Pascal while others tortured to use this weird algorythmic language (thankfully my teacher knew Pascal).

    • @purpleice2343
      @purpleice2343 6 лет назад

      If you """learn""" to program in any way than by doing it yourself you do it wrong.

    • @asston712
      @asston712 6 лет назад

      In grade 8 we had a coding elective and all we did was play video games and all I learned was variables and if statements in Java. I was hoping they would teach C# or C++

  • @ayushman_sr
    @ayushman_sr 7 лет назад

    He is too funny

  • @ChenHuang
    @ChenHuang 6 лет назад

    be nice equation.

  • @gerhardbiebl9778
    @gerhardbiebl9778 4 года назад +1

    Implemented an alternative Version in C# /.Net Forms without visible Circle Objects:
    github.com/bieblsoft/Spiro.
    Though your Implementation showing the Circles is interesting thanks to the possibility to create multiple Circle levels.

  • @GABRIELFILMSTUDIOS
    @GABRIELFILMSTUDIOS 8 лет назад

    You say your way if labeling constructor arguments is annoying and cryptic. I actually like it very much, a lot of people here in Germany use "pvariable", so e. g. "px", "py", etc. (p standing for "parameter"). I find that much more annoying, your way is so nicer, because it 1. Doesn't change the beginning of the variable name, 2. Doesn't add a letter, which distracts from the actual name

  • @bastibob660
    @bastibob660 4 года назад

    I made the same thing in 32 lines of code

    • @cassandradawn780
      @cassandradawn780 4 года назад +1

      Github page? Or source code?

    • @bastibob660
      @bastibob660 4 года назад +1

      HHRD how can i send you the code?
      Just paste it in the comments

    • @krccmsitp2884
      @krccmsitp2884 2 года назад

      LInks or it didn't happen.

    • @bastibob660
      @bastibob660 2 года назад

      @@krccmsitp2884
      int iterations = 5;
      float time = 0;
      ArrayList path = new ArrayList();
      void setup() {
      size(900, 900);
      }
      void draw() {
      for (int i = 0; i < 20; i++) {
      background(0);
      orbit(width/2, height/2, 150, 0);
      time += TWO_PI / 200;
      }
      stroke(255, 0, 255);
      beginShape();
      for (int i = 0; i < path.size(); i++) {
      vertex(path.get(i).x, path.get(i).y);
      }
      endShape();
      }
      void orbit(float x, float y, float r, float n) {
      if (n > iterations) return;
      noFill();
      stroke(255, 150);
      ellipse(x, y, 2*r, 2*r);
      float nspeed = pow(-4, n-1) / 10;
      float nr = r + r/2.5f;
      float nx = x + cos(nspeed * time - HALF_PI) * nr;
      float ny = y + sin(nspeed * time - HALF_PI) * nr;
      orbit(nx, ny, r/2.5f, n+1);
      if (n == iterations) {
      if (path.size() < 10000) {
      path.add(new PVector(x, y));
      } else {
      path.remove(0);
      }
      }
      }

  • @simewu
    @simewu 6 лет назад

    It's painful to see you not using recursion... the code could be so much simpler

  • @dunste123
    @dunste123 8 лет назад +3

    #codingtrainwreck

  • @xPinoyTribal
    @xPinoyTribal 8 лет назад

    Hey, what should i specialized in Computer Science: Algorithms, Embedded Systems and Architecture, or Networked Systems / Security. Can you label it from 1 - 3; where 1 is the most valuable field?
    I am often confused because I feel like algorithms is superior to all branches since it focuses on solving problems, but I feel like there is a lot more math rather than actual implementation...Network Systems can teach you cyber security, hacking, cryptography (Algorithms is important for this field I guess). And lastly Embedded System seems like it's fun because it allows you to control Software / Hardware and learn how to make your own electronics etc...Although it's fun I feel like it isnt valuable lol.
    Here are the different tracks offered at my school for BS catalogue.uci.edu/donaldbrenschoolofinformationandcomputersciences/departmentofcomputerscience/#majorstext
    Thank you!!! Love all the vidoes!

    • @xPinoyTribal
      @xPinoyTribal 8 лет назад

      I know like everyone else, you'd probably say it's up to me haha. So I guess to simplify my question, what do you think which is the most valuable field of study in computer science? ( I can't have all of them, that's why /: because UC Irvine has tracks for it /:)

    • @xPinoyTribal
      @xPinoyTribal 8 лет назад

      If you were to do computer science or software engineering all over again...which field of study would you focus more on and why ?

  • @Willomane
    @Willomane 8 лет назад +1

    #codingtrainwreck sup sup sup

  • @MrEst97
    @MrEst97 6 лет назад

    It's pronounced 'be nice'

  • @Tim-Jaeger
    @Tim-Jaeger 8 лет назад

    1st, that is my first time ever

  • @ACCALLONATO
    @ACCALLONATO 8 лет назад +2

    it's pronounced "benice"... duh!

  • @Luffi98
    @Luffi98 8 лет назад

    How do you separate things with a command?
    like ellipse(x,y,z,p);
    to ellipse(x, y, z, p);

  • @Luffi98
    @Luffi98 8 лет назад +3

    Try k=+10, resolution=10 and 100
    its BEAUTIFUL

    • @anusha8085
      @anusha8085 3 года назад

      It's like those crocheted tablecloths getting spun out :D

  • @aslansi1906
    @aslansi1906 8 лет назад

    #codingtrainwreck

  • @David-jp9wv
    @David-jp9wv 8 лет назад +2

    #codingtrainwreck

  • @Daniel20030
    @Daniel20030 7 лет назад

    #codingtrainwreck

  • @Mavhawk64
    @Mavhawk64 4 года назад

    #codingtrainwreck