Jump to content

musicman

Members
  • Posts

    62
  • Joined

  • Last visited

Previous Fields

  • Languages
    HTML, Javascript, CSS, XML, PHP

musicman's Achievements

Newbie

Newbie (1/7)

5

Reputation

  1. No. no error, console just tell the result that it is false and you're right, this method is not efficient. But I found another way and it works well. I create a regexp obj like this: var regex = /\bab\b|\babc\b|\babcd\b/gi; regex has more than 20k items, this replacing the dictionary array on the above code. And then, to match the obj.txt with dictionary items, I'm looping a conditional function like this: if ( arr.txt.match( regex ) ){ arr.isRoot = true; } else { arr.isRoot = false; } console.log( arr[1].isRoot ); // finally true It works now. Maybe the problem was something to do with the recursion on previous code but I'm not sure. Thanks @justsomeguy!
  2. Thanks @justsomeguy and Happy New Year! now I've found a little bit strange fact that the code above is actually works! However, in my original javascript file, the 'dictionary' has more than 20k items. It won't work if the item of the 'dictionary' is more than 20 items.. ??? how is that happen? is it the browser or my pc spec maybe?
  3. /* Merry Christmas everyone! */ I have an array of objects: arr = [ obj1, obj2 ]; Each object has prototypes: obj1.txt = "az"; obj2.txt = "abc"; obj1.isRoot = false; obj2.isRoot = false; And there's an array called dictionary, it formed like this: var dictionary = [ ["a","(n)"], ["ab","(n)"], ["abc","(n)"], ["abcd","(n)"] ] What I try to achieve is when obj.txt is similar to dictionary[x][0], then obj.isRoot turn to TRUE. I've made the function below so far but it doesn't work. function go(){ for ( i=0; i<arr.length; i++ ){ txt_source = arr[i].txt.replace( /\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\-|\+|\=|\{|\}|\[|\]|\:|\;|\"|\'|<|\>|\,|\.|\?|\/|\\|(0-9)/g, "" ); ori = txt_source.toLowerCase(); regex = new RegExp( '\\b' + ori, 'gi'); for ( m=0; m<dictionary.length; m++ ){ if ( dictionary[m][0].match(regex) ){ arr[i].isRoot = true; // I want this happen for obj2.txt = "abc". } else { arr[i].isRoot = false; } } } console.log( ahoc_arr[x].isRoot ); // all objects always FALSE } Please help! Thanks!
  4. Specify the decimal number using toFixed(): var dec= 9.999 * 9.999; var specdec = dec.toFixed(6) console.log( specdec ); //99.980001 but the value will be a string.
  5. Oh I see. It said that : so balls originY = D or can we have more descriptive sentence for this.. Thanks for pointing this.
  6. Yes, I agree. It's just the same sine equation. The y1 is required on the canvas to have the center point of the ball, if y1 is not defined, the ball always start at (0,0) of the canvas. You guys rocks! I'm going to need a lot of beer discussing this with a math teacher. lol
  7. I understand now! html canvas animation can interpret the frequency very nicely on screen. Thanks, @justsomeguy!
  8. Hi, I added some workaround for sine and ellipse motion to CODY. I used another math equation of sinusoidal function: y = A sin [b (x - C)] + D In my case: y = y1 + A sin [b (x - C)] + D Please find the html here; once you're there, please click Snippets (the book icon) and choose "Animation Motion". Both sine and ellipse motion looks great. But I still have question about relationship between Math and js/html canvas. How the 'Period' value (x) affect the speed of the animation in the canvas? also, do you have suggestion to improve the animation snippet, please drop some advice here. Thanks!
  9. I tested it, it made the motion awkward. I will play around with this and find more math! this is great.
  10. I'll remember that, thanks! how about the t, should we use Date() or we can use fixed number and increment? Thank you for your time for this @Ingolme!
  11. Awesome! thanks @Ingolme. This is great for animation understanding base. How would you write the Angular Velocity and the "t", like this? Math.radians = function(degrees) { return degrees * Math.PI / 180; }; A * Math.sin( Math.radians( av ) * t ) + k + "px"; -------------------------------------------- My bad, it should be the "c" variable I found this on the web.
  12. Hi, I saw following function: var banner = document.querySelector( '.stage div' ), a = 50, b = 50, c = 0; function sine(){ banner.style.top = a * Math.sin( start ) + b + 'px'; banner.style.left = c + "px"; c += 0.1; } window.setInterval( sine, 50 ); It is to make a sine motion in js; it works. Does anyone know the original equation of this in math that similar to: y = a sin c + b, x = c ? Thanks!
  13. You can use Tooltip or set an input placeholder attribute like: <input type="text" placeholder="this is place holder" />
  14. That works very well! Thanks again. Now I shall create some designs.
  15. Thank you @dsonesuk! I will try that method. When we change the href attribute of the stylesheet with a click, will the style changed immediately or we should refresh/reload the page first?
×
×
  • Create New...