xxxxxxxxxx
let x = 200
let y = 200
let vx = 1
let vy = 1
function setup() {
createCanvas(800, 400) // pixels
background(0) // 'red' , (255,0,0), '#ff0000'
}
function writeText(x,y,col,size,msg ){
fill(col)
textSize(size)
textAlign(CENTER, CENTER)
text( msg + '(' + col + ')', x, y)
}
function draw() {
fill(0, 15)
rect(0, 0, width, height)
for (var i = 0; i < width; i+= 50) {
for (var j = 0; j < width; j+= 50) {
writeText(x+i,y+j,'maroon',9,'product')
}
}
strokeWeight(10)
stroke(random(255), 155, 215, 50)
line(x, y, mouseX, mouseY)
line(x, y, 0, 0)
line(x, y, width, height)
strokeWeight(10)
stroke(random(255), 155, 215, 50)
line(x, y, mouseY, mouseX)
line(x, y, 0, 0)
line(x, y, width, height)
strokeWeight(10)
stroke(random(255), 155, 215, 50)
line(x, y, mouseX, mouseY)
line(x, y, 0, 0)
line(x, y, width, height)
line(x, y, 0, height)
line(x, y, width, 0)
strokeWeight(10)
stroke(random(255), 155, 215, 50)
line(x, y, mouseX, mouseY)
line(x, y, 0, 0)
line(x, y, width, height)
line(x, y, 0, width)
line(x, y, height, 0)
// writeText(mouseX,mouseY,'blue',32,'product')
// writeText(mouseY,mouseX,'white',32,'product')
x = x + vx
y = y + vy
if (x < 0) {
vx *= -1
}
if (x > width) {
vx *= -1
}
if (y < 0) {
vy *= -1
}
if (y > height) {
vy *= -1
}
}
function mousePressed() {
save()
col = (random(255), random(255), random(255))
background(random(255), random(255), random(255))
x = random(width)
y = random(height)
vx = random(-2, 2)
vy = random(-2, 2)
}