JavaScript Changing color when repeat and Jquery coordinates of moving element changing color when knitting,changing color when crocheting,changing color

I'm trying to recreate some JQuery tutorials that I've seen, by myself, but I'm stuck right now.

I'm creating an object that starts at a position and ends at another position. The figure changes, but when it's repeating I want that object to change its color. I have tried creating an array and using Math.floor(Math.random() elements to do it but it doesn't work.

Also, I have tried using jQuery to do the following, i.e, when I click the figure, it gives me its position on x and y.

The thing I want to do is in the following example.

Youtube example

My code so far

<!DOCTYPE html>
<html>
<head>
  <title>Example</title>
  <meta charset="utf-8">
</head>

<body>

    <canvas id="canvas" width="400" height="400"></canvas>

    <script src="https://code.jquery.com/jquery-2.1.0.js"></script>

    <script>

    var canvas = document.getElementById("canvas");
    var ctx = canvas.getContext("2d");

    var posicion = 0;    
    var tamano = 0;

    setInterval(function () {

    ctx.clearRect(0, 0, 400, 400);
    ctx.fillRect(posicion, 0, tamano, 400-tamano);

    posicion++;
    tamano++;

    if (posicion > 400){
    posicion = 0;
    tamano = 0;
    }
    }, 30);    

    var color = ['red', 'green', 'blue', 'orange', 'yellow'];     
    ctx.fillStyle = color[Math.floor(Math.random() * color.length)];

</script>

</body>
</html>

Can anyone can help me or say what I'm doing wrong?

Answer:1

I have a JavaScript-array with objects filled in and want to remove every object with no data. It might look like this: var myArray = [ {id: "28b", text:"Phill"}, {id: "12c", text:"...

I have a JavaScript-array with objects filled in and want to remove every object with no data. It might look like this: var myArray = [ {id: "28b", text:"Phill"}, {id: "12c", text:"...

  1. remove empty objects from json
  2. remove empty objects from array javascript
  3. remove empty objects from array lodash
  4. remove empty objects from json java
  5. remove empty objects from object javascript
  6. remove empty objects lodash
  7. remove empty objects
  8. remove empty objects from array php
  9. remove empty objects from array java
  10. remove empty objects from list java
  11. remove empty objects from json c#
  12. remove empty objects from list c#
  13. remove empty objects from arraylist
  14. remove empty object mongodb
  15. remove empty objects python
  16. js remove empty objects from array
  17. jackson remove empty objects
  18. javascript remove empty objects from json
  19. powershell remove empty objects from array
  20. python remove empty objects from list

In local storage I have an object named favourites and it contains this.. "{ "id3333":{ "URL":"somewhere.comm/page1/", "TITLE":"Page 1 Title", }, "id4444":{ "URL":"...

In local storage I have an object named favourites and it contains this.. "{ "id3333":{ "URL":"somewhere.comm/page1/", "TITLE":"Page 1 Title", }, "id4444":{ "URL":"...

  1. c++ delete object within itself
  2. javascript delete key within object

I have a resources array which is full of objects. Each object has categories array full of objects. I am trying to apply a filter to only return resources that have category objects of a specific ...

I have a resources array which is full of objects. Each object has categories array full of objects. I am trying to apply a filter to only return resources that have category objects of a specific ...

How do I set up CORS on Amazon S3 to allow only approved domains to access a JS script in my S3 bucket? Currently, I have CORS set as follows on my S3 bucket: <?xml version="1.0" encoding="UTF-8"?&...

How do I set up CORS on Amazon S3 to allow only approved domains to access a JS script in my S3 bucket? Currently, I have CORS set as follows on my S3 bucket: <?xml version="1.0" encoding="UTF-8"?&...

  1. restrict access using permission set
  2. restrict access using xhost
  3. restrict access using htaccess
  4. restrict access using sql
  5. restrict access using iis
  6. restrict network access using firewall-cmd/firewall
  7. restrict internet access using group policy
  8. restrict internet access using active directory
  9. restrict ec2 access using tags
  10. restrict folder access using htaccess
  11. restrict network access using firewall-cmd/firewall rhcsa
  12. restrict internet access using dns
  13. restrict internet access using hosts file
  14. restrict access to websites using group policy
  15. restrict access to web page using web.config