How to smooth out the trails of the particles in a p5js simulation

I want to turn this halting, discontinuous trails in the particle on this simulation

enter image description here

to something worth staring at as in this beautiful field flow in here (not my work, but I don’t remember where I got it from).

I have tried different permutations of the code in the accomplished field flow without getting anything remotely close to the smoothness in the transitions that I was aiming for. I suspect I am mishandling the updates or the placement of the black rectangle that seems to circumvent the need for a black background, which would erase the wake of the particles.

const scl = 45;
var cols, rows;
var particles = [];
var flowfield;

function setup() {

    createCanvas(750, 750);
    cols = ceil( width / scl );
    rows = ceil( height / scl );


    flowfield = new Array( cols * rows );

    for (var i = 0; i < 1000; i ++ ) {
        particles[i] = new Particle();
    }
}

function draw() {
    
    translate(height / 2, height / 2); //moves the origin to center
    scale( 1, - 1 ); //flips the y values so y increases "up"

    rect(-width,-height,2*width,2*height);
    for ( var y = 0; y < rows; y ++ ) { 
        for ( var x = 0; x < cols; x ++ ) { 
      
      var index = x + y * cols;

      let vX = x * 2 - cols;
      let vY = y * 2 - rows;
                
     
      var v = createVector( vY, -vX );
      v.normalize();
          
      flowfield[index] = v;
      
      // The following push() / pull() affects only the arrows     
      push();
      translate(x*scl-width/2,y*scl-height/2);

      fill(255);
      stroke(255);
      rotate(v.heading());
      line(0,0,0.5*scl,0);
      let arrowSize = 7;
      translate(0.5*scl - arrowSize, 0);
      triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
      pop();
// The preceding push() / pull() affects only the arrows     
    }// Closes inner loop
  }// Closes outer loop to create vectors and index.
  
//This next loop actually creates the desired particles:
    for (var i = 0; i < particles.length; i++) {
    particles[i].follow(flowfield);
    particles[i].update();
    particles[i].edges();
    particles[i].show();
  }
} // End of the function draw

class Particle {

    constructor() {


        // changed startpostion. Since the origin is in the center of the canvas,
        // the x goes from -width/2 to width/2
        // the y goes from -height/2 to height/2
        // i also changed this in this.edges().

        this.pos = createVector( random( - width / 2, width / 2 ),
            random( - height / 2, height / 2 ) );
        this.vel = createVector( 0, 0 );
        this.acc = createVector( 0, 0 );
        this.maxspeed = 4;
        this.steerStrength = 30;
        this.prevPos = this.pos.copy();
        this.size = 2;

    }

    update() {

        this.vel.add( this.acc );
        this.vel.limit( this.maxspeed );
        this.pos.add( this.vel );
        this.acc.mult( 0 );
        fill(255)
        circle( this.pos.x, this.pos.y, this.size );
      

    }

    follow( vectors ) {

        var x = floor( map( this.pos.x, - width / 2, width / 2, 0, cols - 1, true ) );
        var y = floor( map( this.pos.y, - height / 2, height / 2, 0, rows - 1, true ) );
        var index = ( y * cols ) + x;

        var force = vectors[ index ].copy();
        force.mult( this.steerStrength );
        this.applyForce( force );

    }

    applyForce( force ) {

        this.acc.add( force );

    }

    show() {


        noStroke();
        fill(0,5)
        // you can just draw on the position.


        this.updatePrev();


    }

    updatePrev() {

        this.prevPos.x = this.pos.x;
        this.prevPos.y = this.pos.y;

    }

    edges() {

        //clamp between -width/2 and width/2. -height/2 and height/2
        if ( this.pos.x > width / 2 ) {

            this.pos.x = - width / 2;
            this.updatePrev();

        }
        if ( this.pos.x < - width / 2 ) {

            this.pos.x = width / 2;
            this.updatePrev();

        }
        if ( this.pos.y > height / 2 ) {

            this.pos.y = - height / 2;
            this.updatePrev();

        }
        if ( this.pos.y < - height / 2 ) {

            this.pos.y = height / 2;
            this.updatePrev();

        }
    }
}

Showing a red alert text near an input if the input does not match what we want

So basically I want to display some red text in a website if the content of an input is not what I want the person to put
I know how to check for that with jquery, but to show the red text I was thinking of having it already in the html with a hidden class and then removing the hidden class when the input is not correct, but it seems a bit dirty ? Is there a better way to make some text appear in that case ?

3 progress bar in one html file using js

How to display 3 progress bar that have different data using js and html.
First of all, sorry for my poor English, I hope you will understand me after all
I want 3 same circle to show 3 different data.
When I add 3 of the same js codes in which I change the “radialprogress” ID, I always see one progress bar.
I have this code

Html:

<div class="row">
<div>
<div style="width: 160px;float: left;margin-right: 0px;" id="radialprogress" ></div>
</div>
<div>
<div style="width: 160px;float: left;margin-right: 0px;" id="radialprogress" ></div>
</div>
<div>
<div style="width: 160px;float: left;margin-right: 0px;" id="radialprogress" ></div>
</div>
</div>

JS code which I also put in html:

    <script>
    var svg ;

function drawProgress(end){ 
d3.select("svg").remove() 
  if(svg){
  svg.selectAll("*").remove();
  
}
var wrapper = document.getElementById('radialprogress');
var start = 0;
 
var colours = {
  fill: '#12ea8d',
  track: '#555555',
  text: '#00C0FF',
  stroke: '#172b4d',
}

var radius = 80;
var border = 12;
var strokeSpacing = 4;
var endAngle = Math.PI * 2;
var formatText = d3.format('.0%');
var boxSize = radius * 2;
var count = end;
var progress = start;
var step = end < start ? -0.01 : 0.01;

//Define the circle
var circle = d3.svg.arc()
  .startAngle(0)
  .innerRadius(radius)
  .outerRadius(radius - border);

//setup SVG wrapper
svg = d3.select(wrapper)
  .append('svg')
  .attr('width', boxSize)
  .attr('height', boxSize);

  
// ADD Group container
var g = svg.append('g')
  .attr('transform', 'translate(' + boxSize / 2 + ',' + boxSize / 2 + ')');

//Setup track
var track = g.append('g').attr('class', 'radial-progress');
track.append('path')
  .attr('fill', colours.track)
  .attr('stroke', colours.stroke)
  .attr('stroke-width', strokeSpacing + 'px')
  .attr('d', circle.endAngle(endAngle));

//Add colour fill
var value = track.append('path')
  .attr('fill', colours.fill)
  .attr('stroke', colours.stroke)
  .attr('stroke-width', strokeSpacing + 'px');

//Add text value
var numberText = track.append('text')
  .attr('fill', colours.text)
  .attr('text-anchor', 'middle')
  .attr('dy', '.5rem'); 

  //update position of endAngle
  value.attr('d', circle.endAngle(endAngle * end));
  //update text value
  numberText.text(formatText(end));
  
}
 
drawProgress(14/100)
</script>

Thank You

NTLM in CYPress

I want to access a link that is protected with username and password through a windows authentication popup.

I read that this requires an NTLM plugin for CYPRESS. I want to access a form link https://etc.domain.com/dirlisting/notifications and here i want to login

 it('loginpopup', () => {
    cy.ntlm(["https://etc.domain.com/dirlisting/notifications"], "Administrator", "password");
    cy.visit("https://etc.domain.com/dirlisting/notifications");
  })

I tried this code but i have error: “Invalid host [https://etc.domain.com/dirlisting/notifications ] in ntlmHosts, must be one of: 1) a hostname or FQDN, wildcards accepted. 2) hostname or FQDN with port, wildcards not accepted (localhost:8080 or www.google.com or *.acme.com are ok, https://www.google.com:443/search is not ok).

I tried also without https

I tried cy.visit('https://username:[email protected]') but isn’t work

Rewrite vanilla JS forEach into jQuery Each()

I am trying to keep my code consistent as I’m using jQuery for my project, however, I’m a bit confused about the each() method of jQuery.

let cells=$(".cell").toArray();

my Vanilla JS code is here:

cells.forEach(function(cell,index){
    cell.addEventListener('click',function(){
        console.log(cell,index);
    })
})

my jQuery is here:

cells.each(function(index,cell){
    cell.click(function(){
        console.log(cell,index);
    })
})

I know the code is wrong, as the console shows Uncaught TypeError: cells.each is not a function but I checked the jQuery Document, it says the each method is the forEach method in JS, I am really confused now.

display input value in div

I have an input with values and I want to add a value to a div every time I select it.

so that I can add more than one value

Thanks in advance.

HTML

<div [formGroup]="form">
 <select name="test id="test">
   <option value="one">One</option>
   <option value="two">Two</option>
 </select>
</div>

// i want display the input value here

<div> {{this.form.value}} </div> // this way does not work

JavaScripts read an array that was sent from PHP

Hello I am starting to use JavaScript, I explain my problem, i send array to give from PHP to my JavaScript but when I want to read my array in JavaScript, it reads letter by letter and not words by words.

erreur image

function update(json)
{

    console.log(json);
    var result = JSON.stringify(json);
    console.log(result);

    for (let i =0;i< result.length;i++)
    {
        chart.data.datasets[0].data[i]=result[i];
        console.log(result[i]);
    }
    chart.update();
}
<button data-values="<?php  echo preg_replace('/"/',"'", preg_replace("/'/","'", json_encode($tab[$row]))); ?>" onclick="update(this.getAttribute('data-values'))"><?php echo $worksheet->getCell('A'.$row)->getValue(); ?></button>

How do you fetch data from an API and inject that same data into a link that points to another API (JavaScript)

The movie.imdbID return a string of IDs which is then used as an argument for the getMovieIMDBID function. In my code when the element is created, it looks fine as the id looks to be properly inserted like so

a onclick=”getMovieIMDBID(tt4853102)”>Batman: The Killing Joke

yet on the console it tells me ReferenceError: tt4853102 is not defined when i click on the UI.

and if I ctrl+click the link i get this error message in a pop up window

{“Response”:”False”,”Error”:”Conversion from string “${movieID}” to type ‘Double’ is not valid.”}

let movies = movieItems.map(function (movie) {
   return `  <a onclick="getMovieIMDBID(${movie.imdbID})">${movie.Title}</a> 
                <img src="${movie.Poster}">

              `;
    });

function getMovieIMDBID(movieID) {
  let movieInfo = new XMLHttpRequest();
  movieInfo.addEventListener("load", function () {
    let movieInfoParsed = JSON.parse(this.responseText);
    let movieInfoItems = movieInfoParsed.map(function (data) {
      return `<h1>${data.Title}</h1>`;
    });
    movieInfoContainer.innerHTML = movieInfoItems;
  });
  movieInfo.open(
    "GET",
    `https://www.omdbapi.com/?i=${movieID}&apikey=564727fa`
  );
  movieInfo.send();
}

Delete only div containers inside a container

The aim is to delete all div containers within a container and leave two anhchor tags untouched.

<div id="container">
  <div id="wrapper" class="slider">

    <div><img src=""></div>
    <div><img src=""></div>
    <div><img src=""></div>

    <!-- Next and previous buttons -->
    <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
    <a class="next" onclick="plusSlides(1)">&#10095;</a>

  </div>
</div>

expected / goal

<div id="container">
  <div id="wrapper" class="slider">
    <!-- Next and previous buttons -->
    <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
    <a class="next" onclick="plusSlides(1)">&#10095;</a>

  </div>
</div>

With innerHTML everything is deleted and therefore also the a tags. Is there an elegant and simple solution?

HTML input type=’range’ not moving

I have an Options component containing a slider input.
I don’t understand why the thumb of the slider doesn’t move if I set the “value” parameter, but i need it.

Here the code:

interface Props {
    value?: number
}

const Options: React.FC<Props> = ({ value }) => {

    return (
        <div className='options'>
            <span className='boh'>CUSTOMIZE YOUR PASSWORD</span>
            <div className='slider-container'>
                <input type="range" id="slider" min="1" max="100" value={value} />
                <label htmlFor="slider">Length</label>
            </div>
        </div>
    )
}

export default Options

I thank anyone who gives me a hand

Splitting sheet text using an array to mantain unique ID

I’m using this: How to transpose and split in Google Apps Script?

Which works great in the first part (I use it to copy data an split it) but then I would need to redo it since I have 2 different separators, first time “;” second time “,”.

The issue and I’m guessing it’s more JS related than anything else, is that if I use the same for it splits the 2nd column vertically. I’ll post examples.

Column A has the ID, Column B has the comma separated text

If I use it again to reformat it gives this:

enter image description here

I would like it to be split into Column B and C.

I figured it was because the for loop only pushes 2 rows, but I can’t solve adding a third.

Passing an object to a component as prop

I’m very green at react, and I’m trying to learn the library by messing around a bit.

I’m having problems passing an object to another component.
Ive created an array of objects that holds 2 string variables, 1 function and 1 int.

I’m trying to populate this inside a Grid container(Material UI framework).

When I pass the object to the other react component, it arrives as undefined. Ive tried to check if I’m passing a valid object by logging it to the console first, and it is valid.

I’ve also tried to refer to the properties in the component that receives the object, but the browser console throws Uncaught TypeError: Cannot read properties of undefined (reading 'person').

Does anyone know why it is being sent as undefined?

PersonList.js:

const personListe = [
    {
        firstName:'testFirstname',
        lastName:'testLastName',
        getFullName:function()
        {
            return `${this.firstName} ${this.lastName}`
        },
        age:28
    }
]

export default function PersonList() {
    
  return (
      <>
        <Grid container spacing={3}>
            {personListe.map((person) => {
                 return(
                    <Grid item xs={3} key={person.firstName}>
                    <PersonCard person={person} />   
                    </Grid>
                )
            })}
        </Grid>
    </>
  );
}

PersonCard.js:

export default function PersonCard({props})
{
    return (<>
        {console.log(props)}
    </>)
}

One submit button works on my form the other one refreshes the website while updating the url

Im trying to make a quiz using forms and the top submit button works perfectly while the bottom button does not work it ends up refreshing the page and it says the field selected in the address bar this is for a project for college and im a beginner to JavaScript if someone could help me out and explain how it works that would be great I understand how the script works with one from and one button and what the code does but im confused when it comes to 2 forms

var form = document.querySelector("form");
var log = document.querySelector("#log");
var points = 0;
var q1QuizAns = 0;
var q2QuizAns = 0;

form.addEventListener("submit", function(event) {
  var data = new FormData(form);
  var output = "";
  for (const entry of data) {
    output = output + entry[0] + "=" + entry[1] + "r";
    q1QuizAns = entry[1];
    q2QuzAns = entry[1];
  };
  log.innerText = output;
  event.preventDefault();
  pointsAdd();
}, false);

function pointsAdd() {
  if (q1QuizAns == 1) {
    points = points + 1;
    logPoints.innerText = points;
  } else if (q2QuizAns == 1) {
    points = points + 1;
    logPoints.innerText = points;
  }
}
<header>
  <ul class="navbar">
    <li><a href="Home.html">Home</a></li>
    <li><a href="Poland.html" class="active">Poland</a></li>
    <li><a href="Russia.html">Russia</a></li>
    <li><a href="Uzbekistan.html">Uzbekistan</a></li>
  </ul>
</header>

<div class="testBody">
  <div class="bodyText">
    <h1>Poland Test</h1>

    <form>
      <p>Please select your preferred contact method:</p>
      <div>
        <input type="radio" id="contactChoice1" name="question1" value="1">
        <label for="contactChoice1">Warsaw</label>
        <input type="radio" id="contactChoice2" name="question1" value="2">
        <label for="contactChoice2">Krakow</label>
        <input type="radio" id="contactChoice3" name="question1" value="3">
        <label for="contactChoice3">Straszyn</label>
      </div>
      <div>
        <button type="submit">Submit</button>
      </div>
    </form>
    <!-------------------------------------------------------------------------->
    <form>
      <p>What is the national animal of Poland</p>
      <div>
        <input type="radio" id="Question2Choice1" name="question2" value="1">
        <label for="Question2Choice1">White-Tailed Eagle</label>
        <input type="radio" id="Question2Choice2" name="question2" value="2">
        <label for="Question2Choice1">Black-Tailed Eagle</label>
      </div>
      <div>
        <button type="submit">Submit</button>
      </div>
    </form>
    <!-------------------------------------------------------------------------->
    <pre id="log">
        </pre>
    <pre id="logPoints"></pre>
    <!-------------------------------------------------------------------------->

  </div>
</div>

How to add Markes to a Leaflet-map with coordinates from Supabase database?

i want to add some Markers from coordinates stored in a supabase database colomn.
Here is my vue code:

<l-marker v-for="(marker, index) in markers" :key="index" ref="markersRef" :lat-lng="marker.position"></l-marker>

im script:

  export default {
   async created() {
    const { data: events, error } = await this.$supabase
     .from('events')
     .select('coordinates')
    this.markers = events
    this.loaded = true
    console.log(this.markers)
    
   },
  data: () => ({
   markers: [],
  }),
 }

if i output markes, the rusult is:

[ { “coordinates”: “lat: 59.339025, lng: 18.065818” }, { “coordinates”: “lat: 59.923043, lng: 10.752839” } ]

i hope you can help me. thanks.

Safari jquery select option .hide() alternative

I have a jquery script which at first hide all select options:

$('option[data-start="1"]').hide();

and then shows options based on user select of other input.

$('option[data-variable1="' + variable1x + '"][data-variable2="' + variable2x + '"]').show();

Everything works great, but on Safari .hide() doesn’t work.
I know about workaround:

$('option[data-start="1"]').prop('disabled', true);
$('option[data-variable1="' + variable1x + '"][data-variable2="' + variable2x + '"]').prop('disabled', false);

But this only turns off some options. I have dozens of options, so there is long list of inactive options.
I tried hiding inactive options, but Safari probably ignores this code:

select option[disabled="disabled"]{display:none !important;width:0;height:0;visibility: hidden;opacity:0;}
select option:disabled { display:none !important;height:0;width:0;visibility: hidden;opacity:0;}

Could you help me with some workaround for Safari?