dinsdag 12 maart 2024

Animatieles

Vandaag heb ik animatieles gegeven in de Leonardo school. Kind1 gaat hier volgend jaar ook heen. Grappig om al even de sfeer te proeven.
Ik heb ze erg veel verteld in een uur, maar ik hoorde geen klachten:
http://www.snoep.at/animation/lesson1/
We hebben zelfs al samen een animatie(tje) gemaakt om een beetje gevoel voor timing te krijgen.

zondag 19 augustus 2018

Is Trump too orange to be human?


Introduction

On several sites on the internet you can now use AI services, such as services to blow up pictures, enhance them, detect nudity and colorize black and white photos using Neural Networks.
So I thought I'd use this server, to test the theory: Is Trump too orange to be human?

Experiment 1

Ground Truth:
 I used photoshop to make a black and white version of this image. Then I asked the site to colorize it.

Result:

Normal skin color on president Trump. 



Differences:

If we make a differences image to analyse the mistakes the AI made, you can clearly see where the AI went wrong:
  • It assumed a brown suit
  • It assumed a normal Caucasian skin color, presumably because of the blond hair.

  • Experiment 2

    Ground Truth:
     I used photoshop to make a black and white version of this image. Then I asked the site to colorize it.

    Result:

    Differences:

    Again, if we make a differences image to analyse the mistakes the AI made, you can clearly see where the AI went wrong:
  • It gave the Oompa Loompa's brown hair instead of green
  • It miscolored Willy Wonka's hat.
  • With the Oompa Loompa's skin color, the same happened as with Trump's. The biggest mistakes (darkest area in differences image) were with the skincolor.



  • Conclusion

    If you classify Oompa Loompa's or Trump as normal human beings, you end up getting the wrong picture.

    Sources

    Photo's:
    • http://hollywood-elsewhere.com/2005/07/charlie-smells/
    • https://isitfunnyoroffensive.com/stop-calling-me-orange/
    Colorizing algorithm:
    • https://demos.algorithmia.com/colorize-photos/

    maandag 9 juli 2018

    Bitcoin, again?

    Hi.. remember when I predicted BitCoin would drop all the way to 5000,- euro. And then it would continue climbing.

    Well it's happened.

    About a month ago Bitcoin was at 5041,- euro. And again at 30/6 it was 5050
    Since then it has been climbing and is now at 5700,-
    Not the steep climb that it had earlier, but that wasn't healthy, like I predicted: it had to collapse..

    Meanwhile a lot has been happening taking care of the drawbacks of bitcoin.

    • The Lightning network makes cheap and fast payments possible.
    • Segwit is widely adopted
    • Regulations are in place in most places, so we get a more stable course. Pump and Dump is less easy.
    • OffChain transactions are being made more safe (revokable!) and easier and even faster and
    • More and more businesses are looking into blockChain, understanding it and aren't affraid of bitCoin anymore.
    So a lot can happen, but I'd say by the end of 2018 we will be back above the 10.000,- and steadily climbing.


    Just saying.




    dinsdag 17 april 2018

    Ultimate HTML color sanitation in PHP

    How to sanitise a HTML-COLOR in PHP?

    That's become rather difficult, with rgb and hsl colors, as well as short color values and long color values. It took me a 20 minutes, but this regex is ALMOST perfect..

    https://regex101.com/r/A2IjNO/26

    in PHP:

    $col="#fff";
    $col=preg_replace("/[^a-fA-F0-9\#(),.%rgbhsl]/",'',$col); // only leave legal characters!
    if(!preg_match("/^(\#[\da-f]{3}|\#[\da-f]{6}|rgba\(((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)(,\s*(0\.\d+|1))\)|hsla\(\s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,\s*((\d{1,2}|100)\s*%)\s*,\s*((\d{1,2}|100)\s*%)(,\s*(0\.\d+|1))\)|rgb\(((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)\)|hsl\(\s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,\s*((\d{1,2}|100)\s*%)\s*,\s*((\d{1,2}|100)\s*%)\))$/i",$col))
    {
     $col="notacolor";
    }
    echo "COLOR: $col";
    /* just to make that VERY long regex a little clearer!
    if(!preg_match("
    ^(
      \#[\da-f]{3}
     |\#[\da-f]{6}
     |rgba\(
             ((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}
             ((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)
             (,\s*(0\.\d+|1))
          \)
     |hsla\(
           \s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,
           \s*((\d{1,2}|100)\s*%)\s*,
           \s*((\d{1,2}|100)\s*%)
           (,\s*(0\.\d+|1))
         \)
     |rgb\(
             ((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}
             ((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)
          \)
     |hsl\(
           \s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,
           \s*((\d{1,2}|100)\s*%)\s*,
           \s*((\d{1,2}|100)\s*%)
         \)
    )$i
    ",$col)); 
    */
    
    How do you use it?
    User can input ANY string and ONLY valid colorstring parts will pass. So it will pass:
    #fff;
    #ff8800
    rgb(255,15,0)
    rgba(255,15,0,0.5)
    hsla(208, 56%, 46%, 1)
    hsl(0, 100%, 100%)

    If it doesn't pass in the above example the string: notacolor is given to $col.

    HOW IT WORKS

    We work in two steps, first step is to ONLY allow the characters: abcdefgrABCDEFGR.()hlsHLS #0123456789. We replace anything that is not those characters with a "".

    Then we match the result with ANY of the legal color patterns. If that doesn't work, then BANG, you get 'notacolor'.

    This way, if the user makes an obvious typo, it will be forgiven like "#000" => #000 would still work, but get's cleaned up.. Also things like: rgb( 5 , 15 , 255 ) which is legal will be rewritten as:  rgb(5,15,255) saving precious bytes.

    Now in theory a hacker could still do a thing like: rgba(0,0,0,0.000000000000000......), which would pass as legal, so if you REALLY want to make it safe from overflow-type-attacks, checking the length of the string would be a good idea too. But that goes without saying.. that's always a good idea..

    You cannot do it with a match alone, because then "#fff<script alert('oops')></script>" would be a legal string. In our case this would become: #fffrar()r, which is NOT a color so it would become 'notacolor'

    NOTE:
    At first I thought about using an inverse pattern of the above match to preg_replace anything NOT legal for colors.., but that proved to be more difficult than I cared for and it would probably be quite slow, because of the need to negate a | operator. Also, I don't think regex HAS a & operator, so negation might be impossible.. Anyway..

    Disclaimer:


    •  I didn't build it on my own, there where 24 tries before me to study and use parts of. But this seems to be the first to pass all tests for the above cases. I am just proud to be of use :)
    • The only thing it doesn't validate is things like: red..
      Which is a valid color code.
      The complete list is here:
      https://www.w3schools.com/tags/ref_colornames.asp
      I just think it defeats the purpose to check this list with a regex.
      It can be done much more transparent with a in_array() check.

    When do we use this?

    Not much, the color input from HTML5 will give you a nice #555555 value and doesn't even support rgba colors (yet). But the fallback is an ordinary text-input, so we need to protect ourselves.
    This regex is just for the future, when the color input will support alpha-colors and hsl colors as well.
    I am building a framework that I'd like to think I'll use for the coming 10 years.


    zondag 25 maart 2018

    Advanced platform game level generation using Neural Nets

    Basically what I want is to generate a platform game from a very limited black and white tile set, then do a pix2pix or style-transfer generation and have something similar to this as a result..
    from an input like this:

    Generating the Black and White image

    I first made an algorithm to generate the maze, there is many out there. This is a normal tilebased platform game type map. Then I made an algorithm that generates the lines that break up the boring blocks, but basically keep the same shape. It makes the level look a bit techno and at least a bit more interesting and hides the fact that it is a tile-based level.. This was a bit harder, but I think it's still pretty basic, so I'll let you figure that one out yourself. The new thing is how I got to use deeplearning, using all the great libraries out there like deeplearn.js and p5.

    Creating the environment

    I drew the first image myself, using neural nets to generate and machine-parts for this sci-fi type game from the original black and white image. The technique used is often called a style-transfer and is based on google's original deep-dream algorithm.
    I used pictures of the insides of whatches and a basic machine-texture that I found after some experimenting. It basically turns ANYTHING into a machine.
    Having a tile as a base gives a certain predictability to both level-topology and the thinnest possible lines (or smallest details in the final image)
    I got a lot of different outputs:


    Then by incepting these images and using them (or mixed versions of them) as inputs for yet another style transfer I got some even weirder, less mechanical looking ones..

    Then I used photoshop to mix all nice input together. 

    So that image is part Photoshop and part Neural net..

    Rendering in sections of 256x256

    I kind of see this as an environment. Or an athmospere. You could draw the same input in many ways, to get the different environments needed in a typical gamemap.
    For now, I limit myself to one environment. Once I have this to my liking in photoshop I export the styled level. And I do a style transfer to the next section. Pix2Pix can only do small pictures well, so I limit myself to 256x256 sections..

    Even though this is better than I ever expected (giving as I lowered the size of the test file even further for speed), the sections don't exacty line up and you get a little line in between. The answer to this is to render a section inbetween..
    This section doesn't really line up with the other two sections, but it allows me to fade out the edges and create a seamless huge map.
    Also this will in future make it possible to blend styles together seamlessly. (I hope)
    Thought I'd share how I'm trying to make even better game-art with NeuralNets.

    Memory conservation

    Now all this can be done automatically in the browser of the player, making the map that needs to be transfered to the player an ordinary tilemap, which could even be compressed as a gif.
    I see MANY advantages in this technique.

    zaterdag 10 februari 2018

    Wait until you see, the white of their eyes..

    Ok, I've been waiting for the right moment to start buying bitcoin again. Buy the dip, right?

    But that only works well, if you know when the dip ends..
    Is the end of the fall here yet..?
    I told myself when it was at 16.000,- euro's, that I'd start buying again when it hit 8000,- euro's. (or 50%) But it didn't feel right. So I didn't..
    That moment has long gone, but now I was a bit at a loss..
    So I took my original projection from 20-11-2017



    and put the most recent course on that (purple line below in the next paragraph). As you may remember, I started warning for a crash, the moment we hit that green line on top. We went way further through than I could imagine, and so I think we will see at least very close to a maximum dip right now. But what is the maximum dip (or minimum) and when will it be?

    Where and when will the minimum be?

    I still think the minimum will be at the moment we hit the red line. (yellow line projects current drop to that point) We may go a bit deeper, because the high was so high and the ensuing panic may have scared a lot of people of or poisoned them against the concept of de-centralised (non-fiat) currencies and transactions (not blockchain or DAG/tangles per se, which most people can agree upon is a good thing).
    We might also see some more regulation, which will probably scare people of.
    But the moment to start buying according to my original predictions would be:
    at 4610,- euro's which will occur at 19/02/2018 at 19:00 hours ( :) ). That is WAY to precise to be learned from such a graph, but I might be exactly right, how cool would that be?

    But.... to be honest... I have the feeling the low will be later and lower than I first predicted, because the high was so much later and higher than I predicted..

    I've decided to wait it out at least until 19/02/2018 OR 4610,- euro's, whichever comes first.
    I think 4600,- euro's must be possible considering how enormous the positive spike was and anyway it's easier to remember than 4610.

    Is that enough margin for error?

    It went 6000,- euro's over my maximum. Which at that point was 60% more than I ever expected.
    Well 60% less than expected would be 40% of 4600,- so: 1840,- euro... Jaaaaiks.

    Yes, I'll definitely hold of.. Maybe my dream of holding one complete bitcoin again will come to pass (again).

    Winklevoss Twins prediction

    The winklevoss Twins made an outrageous prediction (or so people say)..
    If anyone is still interested, if my original projections were correct, the Winklevoss twins will see their prediction of 320.000,- dollar, or about 260.000,- euro's by 1/10/2019 according to my schedule.
    Wouldn't that be amazing! But since they said by 2020, it seems I'm even a bit more positive than they are. However, they advice you to buy now.. I'm not there yet.

    Anything you put in at 1840,- (somewhere around 01/04/2018 if the present fall continues) will then be at 14100% profit by 2020.

    A quick comparison..
    So buying at 1840,- for 100,- euro will give you 14.100,- euro by 2020
    at 4600,- it will be a 5600% profit (100,- -> 5.600,- euro)
    and at 3700% profit if you buy NOW at 7000,-. (100,- -> 3.700,- euro)
    This is presuming fiat-currencies haven't crashed by 2020.. The buying power of 14.100 euro might be not much different from 1000,- euro now.. (Yes, I said that!)

    Yeah.. I'm gonna mostly wait it out...  maybe buy a bit.. to spread my risks.
    Especially because the fees are still very high, which makes it stands to reason to buy all you want to buy in one go at the lowest point.
    It's just hard to find that lowest point. But I was remarkably accurate in my predictions so far.. (only off by 60%, haha)
    Hope this helps you decide a bit what you want to do with cryptocurrency.

    I.C.O. Byteball

    I bought some byteball. Not much. Toe in the water.
    Even though the system byteball uses is wildly different from the blockchain, it still follows the bitCoin course rather closely. Way more closely than I hoped, I made some profit but it's really small. It kind of strengthens my idea that I.C.O's are not for me..

    Classic Bubble

    I don't know if you saw this graph:

    it's from the financial times of last year.. from when bitCoin was around 5000 dollars.
    It didn't turn out to be right. I don't think they took into account, bitCoin has been acting normally only on log-paper..But maybe there is still something we can learn?

    Looking at the classic bubble, this is basically what I'm talking about. I think the blue line (in my graph) is the median (the dotted line in this graph), only it's still exponential.
    The rest is pretty standard. But look at what happens AFTER the 'Despair' period... It rises again and pretty steeply. In fact, if you look at previous bubbles, we see a lot of companies went on to make a LOT of profit. (Of course a lot of them never got out of the despair phase and died, which is what happens when that line hits 0..)
    But I think there is a hard core community for bitCoin, which won't ever allow it to go below 500,- , no matter what happens. Those are the idealists and they carried the coin for 5 years already, they don't scare easily... So going to 0 isn't really an option I.M.O..

    So if I'm right, the whole question is WHERE in the despair period are we.. And I'm betting we just started it.
    But let's see what happens between now and 19/02/2018 or even april 2018, which is, unless amazing things happen in the meantime, when I hope to post about bitCoin again, telling you I just bought at 1800,- :).


    maandag 8 januari 2018

    Bitonic is wel erg positief.

    Hier boven
    zie je het verschil in interpretatie tussen bitcoin.nl en bitcoinspot.nl.
    Bitcoinspot spreekt van 1141 euro daling, bitcoin.nl van 893 euro stijging.
    Als ik de grafiek zo zie, ben ik het eens met bitcoinspot..