These are chat archives for FreeCodeCamp/HelpJavaScript

5th
Mar 2018
mstellaluna
@mstellaluna
Mar 05 2018 05:00
Hello. Please be aware FreeCodeCamp.org is experiencing intermittent connectivity issues. This is due to issues at Digital Ocean. We are currently aware of the issue and actively monitoring it. Thanks ! Happy Coding !
Brian
@BrianCodes33
Mar 05 2018 05:01

i am trying to solve this. i have no idea what an imaginary number is.

function pofi(n){

}
Test.describe('Basic Tests', function(){
  Test.it('powers 0 through 10', function(){
    Test.assertEquals(pofi(0),'1');
    Test.assertEquals(pofi(1),'i');
    Test.assertEquals(pofi(2),'-1');
    Test.assertEquals(pofi(3),'-i');
    Test.assertEquals(pofi(4),'1');
    Test.assertEquals(pofi(5),'i');
    Test.assertEquals(pofi(6),'-1');
    Test.assertEquals(pofi(7),'-i');
    Test.assertEquals(pofi(8),'1');
    Test.assertEquals(pofi(9),'i');
    Test.assertEquals(pofi(10),'-1');
  });
});

i is an imaginary defined as i² = -1, therefore it is a solution to x²+1=0.

Your Task
is to write a function pofi that returns i to the power of a given non-negative integer in its simplest form as a string (answer may contain i).

Brad
@bradtaniguchi
Mar 05 2018 05:03
@BrianCodes33 Well for starters imaginary numbers aren't real. Try to solve the equation it gave you and you can see why
Now the challenge is kinda wack tho, not sure about how pofi(10) = -1 or any of the other answers
Brian
@BrianCodes33
Mar 05 2018 05:05
yea i see a pattern but don’t really understand imaginary numbers.
Brad
@bradtaniguchi
Mar 05 2018 05:05
I don't see the pattern (but then I'm only half paying attention haha)
Pieter Stokkink
@forkerino
Mar 05 2018 06:35
It just says i^10 is -1...
@BrianCodes33 you don't have to understand imaginary numbers to solve this kata. Just see the pattern and write code that returns the correct value in the pattern. You can use switch/case or even define an array and return an index of it.
h1tag
@h1tag
Mar 05 2018 07:47
Hello, is there an array method in js that traverses an array and has a callback function that accepts the current (element being processed) and the next element as parameters?
Markus Kiili
@Masd925
Mar 05 2018 07:48
@h1tag All the iterator methods can use index as a parameter, so that way you can access also the next or previous element.
But no built-in method that has two elements as parameters.
h1tag
@h1tag
Mar 05 2018 07:50
@Masd925 I see. I'm trying to solve a problem on leetcode and it seems not to be working the way I want it to or the way I think it should
you have to remove duplicates from the array, but you have to do it in-place (without using additional arrays)
Markus Kiili
@Masd925
Mar 05 2018 07:58
@h1tag Filter would be the most logical way there, but not sure if that is forbidden.
h1tag
@h1tag
Mar 05 2018 08:00
@Masd925 I don't think it's forbidden. The only rules are you have to do in-place and with O(1) extra memory
Markus Kiili
@Masd925
Mar 05 2018 08:01
@h1tag Filter makes an another array that it returns, so I would not call that in-place.
h1tag
@h1tag
Mar 05 2018 08:02
@Masd925 but you can pass its callback function the original array and edit it, but yea it still returns another array
so I think I'll have to use a for loop (which I don't think it'll work, because you're editing the original array), or choose another programming language
Claudio Restifo
@Marmiz
Mar 05 2018 08:06
@h1tag forEach executes a callback modifying the current array
it also accepts the current array being traversed as arg
so it's perfect foe what you want to do
h1tag
@h1tag
Mar 05 2018 08:08
@Marmiz and its dynamic (I mean if the array length changes, it will not skip elements)?
Claudio Restifo
@Marmiz
Mar 05 2018 08:09
@h1tag each iterator will skip elements if you change the structure under it
or at least won't be consistent
h1tag
@h1tag
Mar 05 2018 08:09
I see :/
Claudio Restifo
@Marmiz
Mar 05 2018 08:10
try do that in C and admire the segmentation fault in all its beauty :)
Markus Kiili
@Masd925
Mar 05 2018 08:10
@h1tag forEach is not really meant for that and also confuses the reader.
h1tag
@h1tag
Mar 05 2018 08:10
I don't know C, I'll try C++ or Java
Claudio Restifo
@Marmiz
Mar 05 2018 08:11
@Masd925 oh right, he wants to modify the array... forget forEach @h1tag
Markus Kiili
@Masd925
Mar 05 2018 08:12
@h1tag Some loop or recursive solution can do what you need. With JS I would skip the recursion.
Claudio Restifo
@Marmiz
Mar 05 2018 08:12
@Masd925 perhaps a recursive solution?
Markus Kiili
@Masd925
Mar 05 2018 08:13
@Marmiz Yes, that could be elegant as usual.
Claudio Restifo
@Marmiz
Mar 05 2018 08:13
I cannot think of any built in method to achieve what he wants tho. So a custom one is in order I suppose
h1tag
@h1tag
Mar 05 2018 08:13
But I recall that Array.map and its sisters being better than a for loop in JS, in that they adapt to changes in the array
Claudio Restifo
@Marmiz
Mar 05 2018 08:14
@h1tag they all create a new array
reduce, map, filter
h1tag
@h1tag
Mar 05 2018 08:14
true :cry: :laughing:
I'll give it a try in another language then, but I havent used the other languages in a long time, so I may end up checking the solution :smile:
Claudio Restifo
@Marmiz
Mar 05 2018 08:15
you can do it in JS as well
h1tag
@h1tag
Mar 05 2018 08:16
yea, or that
@Masd925 and @Marmiz thank you for taking the time! :smile:
CamperBot
@camperbot
Mar 05 2018 08:16
h1tag sends brownie points to @masd925 and @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1183 | @marmiz |http://www.freecodecamp.org/marmiz
:star2: 4712 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Mar 05 2018 08:21
@h1tag I think that a simple way is a while loop that goes up the indices and keeps count of the elements that have been encountered, and removes those elements that have been seen bofore.
h1tag
@h1tag
Mar 05 2018 08:25
@Masd925 but you'll have to use another array this way?
Markus Kiili
@Masd925
Mar 05 2018 08:25
@h1tag No.
h1tag
@h1tag
Mar 05 2018 08:26
@Masd925 how you're going to keep track of the elements encountered?
Markus Kiili
@Masd925
Mar 05 2018 08:26
@h1tag You can use an object for that.
h1tag
@h1tag
Mar 05 2018 08:26
I see
Claudio Restifo
@Marmiz
Mar 05 2018 08:27
@Masd925 PM
Alsalman78
@Alsalman78
Mar 05 2018 12:47
hi..
i need help.
Fabien SHAN
@X140hu4
Mar 05 2018 12:48
@Alsalman78 What's your problem?
Alsalman78
@Alsalman78
Mar 05 2018 12:59
im stuck at 153.
Markus Kiili
@Masd925
Mar 05 2018 13:00
@Alsalman78 There are no challenge numbers, only names.
That number is your Brownie point total.
alpox
@alpox
Mar 05 2018 13:05
@Masd925 Maybe he is stuck at 153 brownies and wants more? :D
Markus Kiili
@Masd925
Mar 05 2018 13:06
@alpox We will give him one when he explains why Object.length is 1.
alpox
@alpox
Mar 05 2018 13:08
@Masd925 Lol :D bad one
Markus Kiili
@Masd925
Mar 05 2018 13:12
@alpox A bit hard, but what would free browzniez do to the economy?
alpox
@alpox
Mar 05 2018 13:13
@Masd925 Yea, better not to throw them around :D
We already had people get banned from initiating cookie parties
Jen
@jenniredfield
Mar 05 2018 14:27
Hi all
Ken Haduch
@khaduch
Mar 05 2018 14:46
@jenniredfield - hey there - how's it going?
Jen
@jenniredfield
Mar 05 2018 14:47
@khaduch Hello

Hi

So the definition of FP --> Functional programming (often abbreviated FP) is the process of building software by composing pure functions, avoiding shared state
Avoiding shared state... but React has 'states'
so is React not FP?

Ken Haduch
@khaduch
Mar 05 2018 14:51
@jenniredfield - I don't know the answer to that, perhaps someone here does... Here is an article that talks about Javascript / React / functional programming... I'm going to be reading it over to get a better understanding of it... let me know what you think? The article is from 2016, perhaps there will be something that supersedes it with newer versions of React? It's an interesting question...
I would think that you must have "state" somewhere in your application, so that's got to happen somehow, I would think? Even in functional programming?
Ken Haduch
@khaduch
Mar 05 2018 15:26
@jenniredfield - here is another interesting article about functional javascript - more reading / study material! :)
Christopher McCormack
@cmccormack
Mar 05 2018 15:41

Functional programming must have initial state or else there would be nothing to work with.
In Ken's linked article they summed up the State piece pretty well:

An immutable object’s state cannot be changed once it is created. If we want to change the object, we can’t simply set a property on the object - we have to return a whole new object with that one property changed.

I believe that's precisely what React setState does @jenniredfield
Jen
@jenniredfield
Mar 05 2018 15:42
So it makes a copy of the object with that new property and returns it?
Kaz Baig
@kbaig
Mar 05 2018 15:42
Yep
jusgoose
@gusd773
Mar 05 2018 16:26
nvm
Jason Luboff
@JLuboff
Mar 05 2018 16:26
:wave: morning
DistinctWolf
@DistinctWolf
Mar 05 2018 16:32
Sup y'all
Koohyar Movassagh
@Koohyar-m
Mar 05 2018 16:35
afternoon :wave:
Jason Luboff
@JLuboff
Mar 05 2018 16:36
Just another monday..
Nazar
@IsaakNazar
Mar 05 2018 16:43
help with a little problem
function sortedList(n){
  //this function turns number into string and sorts number ascending order
  let arr = n.toString().split('');
  arr.sort((a,b) => a-b);
  return arr;
}
//this function should return the next smaller number of given number
//example: 531 returns 513 , 153 -> 135
function nextSmaller(n) {
  let arr = sortedList(n);
  var min = parseInt(arr.join(''));

  for (var i = n-1; i >= min; i--) {
    if ( sortedList(i).every( (x,j) => x === arr[j] )) {
        return i;
    }
  }
  return -1;
}
console.log(nextSmaller(1027));
//returns 210 (wtf???), should return -1,
Christopher McCormack
@cmccormack
Mar 05 2018 17:07
@JLuboff yo
Stephen James
@sjames1958gm
Mar 05 2018 17:10
@IsaakNazar Your sorted array of 210 is the same as the front of arr [0, 1, 2]
Christopher McCormack
@cmccormack
Mar 05 2018 17:10
@IsaakNazar before we dig into the code - why don't you add some more console.log statements in your function that include what you expect the value to be as well as the actual value
Nazar
@IsaakNazar
Mar 05 2018 17:17
@sjames1958gm @cmccormack my sortedList function is not correct?
Stephen James
@sjames1958gm
Mar 05 2018 17:18
@IsaakNazar Your algorithm is incorrect. You will pass values that do not include all the numbers such as 210
Jason Luboff
@JLuboff
Mar 05 2018 17:30
@cmccormack What up
Christopher McCormack
@cmccormack
Mar 05 2018 17:35
@JLuboff trying to figure out why my nginx config for cross-origin never seems to work correctly
Jason Luboff
@JLuboff
Mar 05 2018 17:36
@cmccormack Can't help you there :D
Christopher McCormack
@cmccormack
Mar 05 2018 17:36
@JLuboff why not?? mean man, mean...
Jason Luboff
@JLuboff
Mar 05 2018 17:37
:P
I'm trying to figure out why my fleet management app is giving an error when "uploading" a pdf
Christopher McCormack
@cmccormack
Mar 05 2018 17:40
@JLuboff try reading the error!
Jason Luboff
@JLuboff
Mar 05 2018 17:42
@cmccormack I am! Its a SQL issue actually. The file still "uploads" but the record doesn't get placed into the database
Christopher McCormack
@cmccormack
Mar 05 2018 17:42
@JLuboff there's your issue!
Jason Luboff
@JLuboff
Mar 05 2018 17:43
It's just wierd.. .docx and .jpg files will get inserted just fine but pdf is being a bitch
Christopher McCormack
@cmccormack
Mar 05 2018 17:43
I just figured out mine - apparently I get a CORS issue if trying to access a resource on my server from another origin, but only if the target doesn't exist on the server
@JLuboff are they too big or something?
Jason Luboff
@JLuboff
Mar 05 2018 17:44
The file itself does not get saved in the database
Christopher McCormack
@cmccormack
Mar 05 2018 17:44
Sure but maybe too big for the server so it's not finishing
Jason Luboff
@JLuboff
Mar 05 2018 17:44
essentially what happens is the file gets copied to a folder on our shared network location, and the "link" gets saved in the database
Files are coping ok
Might be the string length but... it's not particularly long. Lets debug!
Christopher McCormack
@cmccormack
Mar 05 2018 17:46
Yeah!
Jason Luboff
@JLuboff
Mar 05 2018 17:48
I wish I had a console.log like method for windows app, but gotta use breakpoints instead
...Yup it's the string length. Need to change the length in the databse
Jason Luboff
@JLuboff
Mar 05 2018 17:55
Fixed!
Christopher McCormack
@cmccormack
Mar 05 2018 17:56
@JLuboff nice!
Jason Luboff
@JLuboff
Mar 05 2018 17:56
Wasn't a programming bug either :D
Had to change the database column from varchar(100) to varchar(175)
Christopher McCormack
@cmccormack
Mar 05 2018 18:15
varchar is a fun word to say out loud
like a pokemon or something
Jason Luboff
@JLuboff
Mar 05 2018 18:16
lol
now say nvarchar!
Christopher McCormack
@cmccormack
Mar 05 2018 18:17
... no
Jason Luboff
@JLuboff
Mar 05 2018 18:19
:(
Koohyar Movassagh
@Koohyar-m
Mar 05 2018 18:32
Hi guys, I’m stuck in Symmetric Difference challenge: Create a function that takes two or more arrays and returns an array of the symmetric difference of the provided arrays.
I tried reduce() with if inside it if(acc.indexOf(curr) === -1)to return unique values but that doesn't work because curr in acc.indexOf(curr) needs to be one element not the whole array. So I tried reduce and than .filter() to create new acc and curr with unique values and acc.concat (curr) them. But I only get the first filter to work, whichever comes first. I realize its because I returned but if I don’t, filter wont work. I have few console.logs but no luck.
https://codepen.io/Codeconnect/pen/BmdELq
Mackenzie Miller
@mackmmiller
Mar 05 2018 18:38
Anyone a Redux genius here? I’m interested in learning it, but I don’t really get the point of it. Who does Redux benefit, the developer or the user? I’ve been using Apollo recently, and don’t understand if Redux is worth integrating with Apollo. Or, do they serve the same purpose (which they seem to, to me).
alpox
@alpox
Mar 05 2018 18:46
@mackmmiller appollo solves partly the same as redux. I dont think there is much of a point in combining them therefore. Redux is there to keep applicationstate at one place instead of spreading it all over your components. This is good when lots of deeper child components would need a shared state which would have to be kept in an ancestor and passed down througj props through all levels. In this case, redux is your choice because it keeps the state at one place and can inject it into all components which need it.
Apollo goes one step further and mainly exists for communication with the server - even though its caching mechanism can be used as redux replacement - and it is used for communication through GraphQL instead of REST.
Mackenzie Miller
@mackmmiller
Mar 05 2018 18:50
Thanks, @alpox! So Apollo kind of cuts out the middleman? Whereas Redux still requires you to set up some communication with the database?
CamperBot
@camperbot
Mar 05 2018 18:50
mackmmiller sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1570 | @alpox |http://www.freecodecamp.org/alpox
alpox
@alpox
Mar 05 2018 18:51
Apollo does not make a connection to the database directly. It serves the communication with the server. Where the server gets its data which it presents to apollo... Depends.
Redux is a state management library only, much much smaller than apollo and serves that only case of holding state at one place and giving a special way to treat/update it which allows for better reasoning about state changes in your application
With redux, there is no integrated way to ask the server for data and when you need data, you gotta get it as you are used to with ajax or similar and put the data into the redux store yourself
With apollo you state also queries which are there for asking for data, apollo cares about the how and when of getting it.
Mackenzie Miller
@mackmmiller
Mar 05 2018 18:53
Got it. So Apollo is more comprehensive, and Redux requires some more pieces to be functional.
alpox
@alpox
Mar 05 2018 18:54
Hmm you cannot generally say that. Apollo also takes a lot and its bigger when it comes to depende
Dependency size
Also, you can only use apollo if your server presents its data through graphql
In general i would say: Server uses graphql? - use Apollo. It does not? Use redux
Mackenzie Miller
@mackmmiller
Mar 05 2018 18:56
Hmmm so Redux is more versatile? You might consider adding Redux to an existing project, but wouldn’t do that with Apollo. Ideally, you’d want to start from the ground up with Apollo.
alpox
@alpox
Mar 05 2018 18:56
Yes. And only if you are in control of the server
Then you an use apollo
Can*
Mackenzie Miller
@mackmmiller
Mar 05 2018 18:58
Gotcha. Thanks, @alpox! That clears things up a lot!
CamperBot
@camperbot
Mar 05 2018 18:58
mackmmiller sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
api offline
Adel
@AdelMahjoub
Mar 05 2018 19:05
is there someone to quickly explain interpolation for dumb ?
Nate Mallison
@NJM8
Mar 05 2018 19:26
inserting something into something different
like:
const name = "nate";
console.log(`Hi my name is ${name}!`);
using template strings we are inserting one string into a different string
Adel
@AdelMahjoub
Mar 05 2018 20:13
I guess 'overall' it means approximation like for this [circle motio]https://codepen.io/SultanCodeCamper/pen/BYgNMK?editors=0010) using linear interpolation on X and circular interpolation on Y
alpox
@alpox
Mar 05 2018 20:17
@AdelMahjoub Yea generally interpolation means that if you have a number of datapoints, you want to interpolate to find another datapoint which kind of follows the same rule/correlation of x to y. This means that you can imagine a function which approximates the positions of the datapoints and with which you can find new datapoints which follow the same rules
So you just take a row of datapoints, find a function which approximates them the best, and find new points through that function
But i don't see much interpolation in your example :D
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:35
@alpox around?
alpox
@alpox
Mar 05 2018 20:35
@tiagocorreiaalmeida Nope duck
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:35
:D
alpox
@alpox
Mar 05 2018 20:36
:P
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:36
one question, I got a collection where the avatar I would like to set a default in this case a base64 of a default imagine I own, is that bad?
pratice*
alpox
@alpox
Mar 05 2018 20:37
Depends a bit on the size of the avatar. base64 can get quite big but as long as its not that bad its ok
Avatars are usually small enough to fit
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:37
not fully sure how it works but the file has 5kb
I think we are ok with that
:D
alpox
@alpox
Mar 05 2018 20:38
Okay :) You can still restructure if problems come up.
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:39
makes more sense to hold the image or allready the base64 of it on a file and just import it?
since its to set the default value on a schema
alpox
@alpox
Mar 05 2018 20:39

makes more sense to hold the image or allready the base64 of it on a file and just import it?

I'm not sure i understand that

Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:40
so im setting the default value of a a collection field on mongo, should I import the image and turn it into 64 based orjust have the 64based value allready and import the string and set it?
hope it didnt got more confusing :D
alpox
@alpox
Mar 05 2018 20:41
I wouldn't save base64 to disk as string
Better import the image as normal
And turn it into base64 on the fly
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:42
all good thanks :D
Adel
@AdelMahjoub
Mar 05 2018 20:42
@alpox yeah , in that example the tweenTimeline is responsible for the interpolation, according to the easing functions, all began when I wanted to understand this Centripetal Catmull–Rom spline to create some random / complex curves
@alpox and yeah, thanks, your explanation is clear
CamperBot
@camperbot
Mar 05 2018 20:42
adelmahjoub sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1572 | @alpox |http://www.freecodecamp.org/alpox
alpox
@alpox
Mar 05 2018 20:43
@AdelMahjoub Correct me if i'm wrong, but it doesn't look like an interpolation there, but just like applying a function
As you don't have predefined datapoints (discrete data) which you have to interpolate to find a function for
Adel
@AdelMahjoub
Mar 05 2018 20:44
@alpox yes, yes that Tween class is responsible for the interpolation, or else how it moves that square from x1, y1 to x2, y2
alpox
@alpox
Mar 05 2018 20:45
@AdelMahjoub Ah ok. Yea looking at your link i see what you originally meant with it - thats clearly interpolation. I didn't see it in the pen much :D
Adel
@AdelMahjoub
Mar 05 2018 20:46
@alpox I guess for more complex curves I'll chain multiple tweens then
alpox
@alpox
Mar 05 2018 20:46
Hmm i don't know tweens :D maybe yes
Adel
@AdelMahjoub
Mar 05 2018 20:47
@alpox those equations in wikepedia are frightening :laughing:
alpox
@alpox
Mar 05 2018 20:47
Wiki makes some things a bit hard to read :D
CamperBot
@camperbot
Mar 05 2018 20:47

freeCodeCamp Wiki:

:point_right: The freeCodeCamp wiki can be found on our forum.
Please follow the link and search there.
alpox
@alpox
Mar 05 2018 20:47
But yes that is lots of maths
@AdelMahjoub I could only tell you about how to apply polynomial datafitting and interpolation but i'm not sure if that would be all too good for animations :D
Adel
@AdelMahjoub
Mar 05 2018 20:51
@alpox I think that is handled by that Circular.easeIn/out
alpox
@alpox
Mar 05 2018 20:52
@AdelMahjoub The interpolation?
Adel
@AdelMahjoub
Mar 05 2018 20:52
@alpox the polynomial interpolation , or maybe I'm at west :laughing:
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 20:52
image.png
@alpox if wanna give me an hand :D when trying ot set the default value this happens
const defaultAvatar = fs.readFileSync(path.join(process.cwd(), "media", "user.png"), "base64");
    avatar: {
        data: Buffer,
        contentType: String,
        default: defaultAvatar
    },
alpox
@alpox
Mar 05 2018 20:53
I see they have 3 kinds of interpolation:
  • TWEEN.Interpolation.Linear
  • TWEEN.Interpolation.Bezier
  • TWEEN.Interpolation.CatmullRom
    And the Circular.easIn/out tells mostly the curve (where its fast and where its slow)
@AdelMahjoub http://tweenjs.github.io/tween.js/examples/03_graphs.html here you see what i mean by that. These graphs show how the animation flow goes. y value means speed, x is time
@AdelMahjoub http://tweenjs.github.io/tween.js/examples/06_array_interpolation.html here you see how the interpolation is done - Linear is direct interpolation on a line, CatmullRom is smoother but still covers fully all points, Bezier is very smooth and does not necessarily cover all points exactly - except the beginning and the end. Bezier middle points are more anchors or "gravity" points
Adel
@AdelMahjoub
Mar 05 2018 20:57
@alpox for liner.none on x, Sinusoidal.In on y draw a quarter of circle, the naming on phaser tweens are diffrent but I think by circ.easeIn they mean Sinusoidal.In
@alpox I guess I 'll read the original tween lib, phaser must be extending that lib
@alpox but do you know how CatmullRom works, that's the most interesting part
alpox
@alpox
Mar 05 2018 20:59
image.png
I don't know what Phaser names this stuff :D
@AdelMahjoub I just read the Phaser docs. Circ.easeIn is the same as Circular.In
Adel
@AdelMahjoub
Mar 05 2018 21:03
@alpox if you have time some days, take a look at this waveforms it generate any curve using CatmullRom, I'm trying to understand how it works :laughing:
alpox
@alpox
Mar 05 2018 21:03
As you can put there the string "Circ.easeIn" OR Phaser.Easing.Circular.In
@AdelMahjoub I'll take a look at it now :D for short. I don't have much time these days - got lots to do
Adel
@AdelMahjoub
Mar 05 2018 21:06
@alpox when you click save it generate some datapoints
alpox
@alpox
Mar 05 2018 21:09
@AdelMahjoub Ah i got it how it works
Kinda
Its just a bit of a longer calculation
The more datapoints the longer the calculations goes
I could once try to program it myself
You basically just apply the method they show on the wiki page
Mainly you have your datapoints P which consist of an xand an y (They identify with the i which point it is and to which point the x or y belong)
The t1, t2 etc. can be calculated by the function below
image.png
Alpha is a number you can choose and which makes the curve a bit different - uniform, centripetal or whatever.
Adel
@AdelMahjoub
Mar 05 2018 21:14
@alpox Nice, I guess I'm close to fully understand it now, thanks a lot :sparkles:
CamperBot
@camperbot
Mar 05 2018 21:14
adelmahjoub sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
api offline
alpox
@alpox
Mar 05 2018 21:14
@AdelMahjoub t_i can be instantiated at first with 0 for t_0
Then you just calculate t_1 with the above function
and all other t_x you have
And you form a recursive function which calculates the new points A, B, C etc.
using the t values you created
Its quite easy actually
The last function you get - in this case, with 4 points, Cwill be your interpolation function. You can put any value in it and get an interpolation :)
Adel
@AdelMahjoub
Mar 05 2018 21:16
@alpox yes, and in phaser the time is intantiated using Phaser.Time, I was wondering how it was calculated buy it is just a bunch of datapoints and applied that function
alpox
@alpox
Mar 05 2018 21:17
Yup
You have time - the easing function gives you the speed at the current time - the interpolation function gives you the position at a certain time
And there you have your animation
Adel
@AdelMahjoub
Mar 05 2018 21:18
@alpox this is very good, the rest is all about imagination and inspiration :laughing:
alpox
@alpox
Mar 05 2018 21:22
@tiagocorreiaalmeida Gosh sry, i somehow thought i already answered. It seems that you define datatypes in your schema - but you already try to set data in there. Try to put String as datatype
@AdelMahjoub :thumbsup: :D
I guess you're about to make a game then? :D
Adel
@AdelMahjoub
Mar 05 2018 21:23
@alpox yes, the first game always 'sucks' they say, so I published it and I'm working on a new one
alpox
@alpox
Mar 05 2018 21:23
@AdelMahjoub Nice :D
I did some graphics programming at university, but didn't go further with it
But games would surely be nice to make. Atm i'm more stuck in more formal things though :D
Adel
@AdelMahjoub
Mar 05 2018 21:24
@alpox front invaders I made a lot of mistakes while building it, despite the fact it is really really simple, next time I'll be more serious
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 21:24
@alpox sadly doesnt work :\
alpox
@alpox
Mar 05 2018 21:26
@AdelMahjoub Thats pretty old-school-cool :D it works nice though! I don't see mistakes :D
Adel
@AdelMahjoub
Mar 05 2018 21:26
@alpox if that link don't work here it is on itch.io, and here the repo, next one I'm building using typescript for better structure
alpox
@alpox
Mar 05 2018 21:26
@tiagocorreiaalmeida :/ still errors?
@AdelMahjoub It did work well :D
Adel
@AdelMahjoub
Mar 05 2018 21:26
@alpox mostly misconception, assets not packed in an atlas etc
alpox
@alpox
Mar 05 2018 21:27
@AdelMahjoub Ah code-like errors
@AdelMahjoub Maybe take a look at good architectures for games like the Entity Component System
I think it works quite well for games
Ofc. its mostly for bigger ones :D
Adel
@AdelMahjoub
Mar 05 2018 21:31
@alpox yes, I used that, those prefabs classes, all the entity data for each screen were loaded from some json files, so to create a screen / scene I only need to add more data on those json files and the entities will be created automatically, along with their behaviors
alpox
@alpox
Mar 05 2018 21:31
@AdelMahjoub Thats good :)
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 21:31
@alpox yeah same mate
one*
alpox
@alpox
Mar 05 2018 21:32
@tiagocorreiaalmeida With what code?
Adel
@AdelMahjoub
Mar 05 2018 21:33
@alpox thanks for the all help !
CamperBot
@camperbot
Mar 05 2018 21:33
adelmahjoub sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
api offline
alpox
@alpox
Mar 05 2018 21:33
@AdelMahjoub No problem :)
@AdelMahjoub I'll give catmull-rom a shot now :D
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 21:34
    avatar: {
        type: String,
        default: defaultAvatar
    },
done
:D
had a little typo
alpox
@alpox
Mar 05 2018 21:34
@tiagocorreiaalmeida ah good :D
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 21:34
eheh thanks @alpox cookies incomign
CamperBot
@camperbot
Mar 05 2018 21:34
tiagocorreiaalmeida sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1573 | @alpox |http://www.freecodecamp.org/alpox
Adel
@AdelMahjoub
Mar 05 2018 21:37
@alpox here it is https://github.com/photonstorm/phaser/blob/v2.6.2/src/math/Math.js#L791, this is used by Phaser.Tween
alpox
@alpox
Mar 05 2018 21:38
@AdelMahjoub I'm not looking :D i do that myself now
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 21:47
so was checking how to render an image as base64 seems that react does it natively
<img src={"data:image/jpeg;" + imageBase64} />
my only question would be do I really need to force the iamge type=
?
cause I might have 10 image types
Adel
@AdelMahjoub
Mar 05 2018 21:53
@tiagocorreiaalmeida if you want you can Intantiate Image objects, set their src to the image url, and when loaded draw it in a 'virtual canvas', then set the img tag src to canvas.toDataURL(), so you don't need to load a base64 image since it is bigger in size. Or pack all those images in a spritesheet, and draw each part in canvas, so you get all your images in one http request
Tiago Correia
@tiagocorreiaalmeida
Mar 05 2018 21:56
thanks @AdelMahjoub
CamperBot
@camperbot
Mar 05 2018 21:56
tiagocorreiaalmeida sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
:cookie: 665 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
Took some time, but finally :D
I made it a bit complicated - and also not very structured because i wanted it to work :D but it does now
I know that it could have been done easier than this :P