xxxxxxxxxx
70
//zrobić to obiektowo - klasa "skaczący kwadrat"(XD?) z funkcją update()
//lista obiektów - foreach {update()}
//unfinished - to be completed after more meaningful projects are finalized
let x,y;
let Vx = 0;
let Vy = 0;
const g = 3.81;
let rectSajz = 50;
function setup() {
createCanvas(400, 400);
frameRate(60);
x=width/2;
y=50;
rectMode(CENTER);
stroke(255);
strokeWeight(1);
fill(0,255,100);
}
function draw() {
background(0);
rect(x,y,rectSajz,rectSajz);
x+=Vx;
y+=Vy;
Vy+=g;
if (y+rectSajz>=height){
Vy*=-0.9;//formuła
Vx = random(-10,10);
//add colour
/*
* 4 1
*
* 3 2
*/
}
if (x+rectSajz<=0 || x+rectSajz>=width){
Vx*=-1;
}
}
class SkaczącyKwadrat {
constructor(x,y,Vx,Vy,c) {
this.x=x;
this.y=y;
this.Vx=Vx;
this.Vy=Vy;
this.colour=c;
}
update(){
x+=Vx;
y+=Vy;
if (x<0||x>width){
Vx*=-1;
}
if (y<0||y>height){
Vy*=-0.9;
}
}
}