xxxxxxxxxx
62
const points =[]
const AMT=40;
var CENTRE_MAX_OFFSET = 75;
var MAX_OFF = 55;
var DATAPOINT_SIZE = 10;
var dataslope;
var dataintercept;
function setup() {
createCanvas(400, 400);
resetBtn = createButton('reset').mouseReleased(reset)
s= createSlider(1, 300, CENTRE_MAX_OFFSET,1)
s.input((e)=>{
CENTRE_MAX_OFFSET = s.value(); reset();
})
s = createSlider(-100, 100, MAX_OFF, 1)
s.input((e)=>{
MAX_OFF = s.value(); reset();
})
reset();
}
function reset(){
points.splice(0, points.length);
do {
dataslope = random(-2,2);
dataintercept = random(0,400);
line(200, dataintercept+(dataslope*200), 200, 200)
} while ( dist(200, dataintercept+(dataslope*200), 200, 200) > CENTRE_MAX_OFFSET) ;
for (var i=0; i<AMT;i++){
x = i*(width/AMT) + random(-1,1)*MAX_OFF
y = random(-1,1)*MAX_OFF + (i*dataslope) + dataintercept
points.push(createVector(x,y))
}
loop();
}
function regresALine(){
}
function draw() {
background(220);
// draw the points
for (const v of points){
circle(v.x, v.y, DATAPOINT_SIZE);
}
regresALine();
noLoop();
}