xxxxxxxxxx
121
// Creating a model for generating points
class RandomPoints {
constructor () {
// Setting up random starting position on canvas
this.xPos = random(0,600);
this.yPos = random(0,600);}
// The function generating the dots
pointdraw (strokeWeightnumber, RGBcolor) {
strokeWeight(strokeWeightnumber);
// Offset is used to make the change of y coordinate more smooth
let offset = 0.0;
offset = offset + .01;
let n = noise(offset) * random(-55,55);
// Change of x and y coordinates
let xChange = random(-25,25);
let yChange = random(- n - 15, n + 15);
this.xPos += xChange;
this.yPos += yChange;
// Setting up different color modes
if (RGBcolor == 'red'){
stroke( 50 * random(4, 5), random(70,90), random(80,150));
}
if (RGBcolor == 'green'){
stroke( random(100,200), 50 * random(3, 5), random(100,200));
}
if (RGBcolor == 'blue'){
stroke( random(130,150), random(130,200), 50 * random(4,5));
}
//The generation of points
point(this.xPos, this.yPos);
}
}
let points = [];
let NumberOfLines = 100;
function setup() {
createCanvas(600, 600);
frameRate(15);
// Putting the "cookies" into array
for (i = 0; i < NumberOfLines ; i += 1){
points[i] = new RandomPoints(Math.floor(random(1,2)));
}
print(points);
}
// Default color mode
let m = 'green';
// Variable for Stop function
let BreakingVariable = 0;
function draw() {
background(15,15,15,50);
// Drawing the objects from array on canvas
for (i = 0; i < NumberOfLines; i += 1){
if (BreakingVariable == 1){
return;
}
points[i].pointdraw(15, m);
}
}
// Changing of color modes by mouse clicking
function mouseClicked() {
if (m == 'red'){
m = 'green'
}
else if (m == 'green'){
m = 'blue'
}
else if (m == 'blue'){
m = 'red'
}
}
// Stop function
function keyPressed() {
if (keyCode === UP_ARROW) {
if (BreakingVariable == 0){
BreakingVariable = 1;
} else if (BreakingVariable == 1){
BreakingVariable = 0;
}
}
}
// Function for saving the picture of canvas
function keyTyped() {
if (key === 's') {
saveCanvas('myCanvas', 'jpg');
}
}