Click here to Skip to main content
15,897,360 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: i have created 3 widgets using jquery ui - header, footer, textarea. i am observing abnormal behavior because of the footer widget. Pin
n.podbielski31-Oct-12 6:11
n.podbielski31-Oct-12 6:11 
QuestionWorking example for Javascript to call a java webservice Pin
sekhar48429-Oct-12 23:50
sekhar48429-Oct-12 23:50 
AnswerRe: Working example for Javascript to call a java webservice Pin
Richard MacCutchan30-Oct-12 0:54
mveRichard MacCutchan30-Oct-12 0:54 
AnswerRe: Working example for Javascript to call a java webservice Pin
ZurdoDev2-Nov-12 11:04
professionalZurdoDev2-Nov-12 11:04 
GeneralRe: Working example for Javascript to call a java webservice Pin
Member 946160725-Nov-12 19:32
Member 946160725-Nov-12 19:32 
QuestionJS::Page a serious fault Pin
lsw52131425-Oct-12 21:14
lsw52131425-Oct-12 21:14 
AnswerRe: JS::Page a serious fault Pin
enhzflep27-Oct-12 9:57
enhzflep27-Oct-12 9:57 
QuestionFill a "2D" Array with random values Pin
0bx24-Oct-12 12:27
0bx24-Oct-12 12:27 
I got a problem with arrays in js and I'm starting to lose it.

Every iteration generates a different value.
However, it appears that it pushes the same value in the entire row; so the entire row has the same "random" value every time.

I want to have every 'x' to have a "random" value.

JavaScript
for (var x = 0; x <= 90; x++) {
         var col = CustomRandom();
         memBlock[x, 68] = Math.floor(col.next() * 255);
         }


The "2D" Array is created with a recursive function I found on the web:

JavaScript
function createMemblock(length) {
                var a = new Array(length || 0);
                if (arguments.length > 1) {
                    var args = Array.prototype.slice(arguments, 1);
                    for (var i = 0; i < length; i++) {
                        a[i] = createMemblock.apply(this, args);
                    }
                }
                return a;
            }


And here is the entire script, just in case:

JavaScript
window.requestAnimFrame = (function (callback) {
            return window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function (callback) {
            window.setTimeout(callback, 1000 / 60);
            };
            })();

            function createMemblock(length) {
                var a = new Array(length || 0);
                if (arguments.length > 1) {
                    var args = Array.prototype.slice(arguments, 1);
                    for (var i = 0; i < length; i++) {
                        a[i] = createMemblock.apply(this, args);
                    }
                }
                return a;
            }

            var CustomRandom = function (nseed) {
                
                var seed, constant = Math.pow(2, 13) + 1, prime = 1987,
                maximum = 1000;
                if (nseed) {
                    seed = nseed;
                }
                if (seed == null) {
                    seed = (new Date()).getTime();
                }
                return {
                    next: function (min, max) {
                        seed *= constant;
                        seed += prime;
                        return min && max ? min + seed % maximum / maximum * (max - min) : seed % maximum / maximum;
  
                    }
                }
            }  

            function getColor(R, G, B) {
                var s = "#";
                if (R <= 15) {
                    s += "0";
                }
                s += R.toString(16);
                if (G <= 15) {
                    s += "0";
                }
                s += G.toString(15);
                if (B <= 15) {
                    s += "0";
                }
                s += B.toString(15);

                return s;
            }

            function animate() {
                var canvas = document.getElementById("canvas");
                var context = canvas.getContext("2d");

                //Updatephase
                for (var y = 0; y <= 67; y++) {
                    for (var x = 1; x <= 89; x++) {
                            memBlock[x, y] = (memBlock[x - 1, y + 1] + memBlock[x + 1, y + 1]) / 2;
                    }
                }
                for (var x = 0; x <= 90; x++) {
                    var col = CustomRandom();
                    memBlock[x, 68] = Math.floor(col.next() * 255);
                }
               
       
               //DrawPhase
               for (var y = 0; y <= 68; y++) {
                   for (var x = 0; x <= 90; x++) {
                        context.fillStyle = getColor(memBlock[x, y], 0, 0);
                        context.fillRect(x * 10, y * 10-10, 10, 10);
                    }
                }
                requestAnimFrame(function () {
                    animate();
                });
            }

            function InitMemblock() {
                for (var x = 0; x <= 90; x++) {
                    for (var y = 0; y <= 68; y++) {
                        memBlock[x, y] = 0;
                    }
                }
            }

            window.onload = function () {
                InitMemblock();
                animate();
            };

             var memBlock = createMemblock(90, 68);


It's just an experiment with the canvas API; but If I can't control a 2D-block of memory I pretty much can't do anything.

If I can't get it to work I suppose I could use a single Array; but that would really suck.
Giraffes are not real.

AnswerRe: Fill a "2D" Array with random values Pin
enhzflep26-Oct-12 20:52
enhzflep26-Oct-12 20:52 
QuestionFlexigrid Pin
chandra reinhart15-Oct-12 1:23
chandra reinhart15-Oct-12 1:23 
Questionpagination Pin
millekekez12-Oct-12 22:32
millekekez12-Oct-12 22:32 
QuestionProblem with IE 9 Pin
giocot11-Oct-12 7:21
giocot11-Oct-12 7:21 
AnswerRe: Problem with IE 9 Pin
Member 950758611-Oct-12 23:02
Member 950758611-Oct-12 23:02 
AnswerRe: Problem with IE 9 Pin
jkirkerx17-Oct-12 12:20
professionaljkirkerx17-Oct-12 12:20 
AnswerRe: Problem with IE 9 Pin
twseitex19-Oct-12 7:39
twseitex19-Oct-12 7:39 
Questionwindow.open not working inside frame in google chrome. Pin
Virjin Antony10-Oct-12 1:57
Virjin Antony10-Oct-12 1:57 
AnswerRe: window.open not working inside frame in google chrome. Pin
twseitex19-Oct-12 8:28
twseitex19-Oct-12 8:28 
AnswerRe: window.open not working inside frame in google chrome. Pin
saimimtiaz28-Oct-12 8:19
saimimtiaz28-Oct-12 8:19 
QuestionFileUpload Inside a Gridview ItemTemplate Pin
Member 79103609-Oct-12 19:25
Member 79103609-Oct-12 19:25 
AnswerRe: FileUpload Inside a Gridview ItemTemplate Pin
Mohibur Rashid9-Oct-12 21:22
professionalMohibur Rashid9-Oct-12 21:22 
AnswerRe: FileUpload Inside a Gridview ItemTemplate Pin
kavittrivedi16-Oct-12 2:29
kavittrivedi16-Oct-12 2:29 
QuestionFile Upload in IE Pin
ziggyfish9-Oct-12 15:26
ziggyfish9-Oct-12 15:26 
AnswerRe: File Upload in IE Pin
twseitex19-Oct-12 8:31
twseitex19-Oct-12 8:31 
Questionbitwise operator question Pin
SuperRoo29-Oct-12 13:19
SuperRoo29-Oct-12 13:19 
AnswerRe: bitwise operator question Pin
ziggyfish9-Oct-12 15:31
ziggyfish9-Oct-12 15:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.