简体   繁体   中英

p5.js Shape Adjustments Leaving Previous Outlines Visible

I am trying to simply adjust the shape of an object using a value derived from a slider on a screen using p5.js.

The issue I am having is that the outline of the previously drawn shapes remain, giving an after-trail effect.

I have tried the noStroke() modifier but that simply does not draw the shape. As well the noFill() gives an even weirder, yet still incorrect, behavoir.

Code Example: https://codepen.io/galleywest/pen/oejxyY

var slider

function setup() {
  createCanvas(600, 600)
  slider = createSlider(0, 50, 0)
}

function draw() {
  rect(10, 10, 80, 80, slider.value())
}

How can I mitigate this behavior?

You need to call the background() function to clear out old frames.

var slider

function setup() {
  createCanvas(600, 600)
  slider = createSlider(0, 50, 0)
}

function draw() {
  background(255, 0, 0); //draws a red background
  rect(10, 10, 80, 80, slider.value())
}

More info can be found in the reference .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM