xxxxxxxxxx
108
let b=[]
let tb=[]
let w=800
let h=600
let O = [w/2, h/2];
let s = 1;
class matrix {
constructor(x1, x2, y1, y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
mul(v){
return new punkt(this.x1*v.x+this.x2*v.y,this.y1*v.x+this.y2*v.y)
}
}
class billede{
constructor(p){
this.p=p
}
drawLines(){
for (let i = 0; i < this.p.length - 1; i++) {
line(
O[0] + this.p[i].x,
O[1] - this.p[i].y,
O[0] + this.p[i + 1].x,
O[1] - this.p[i + 1].y
);
}
}
drawPoints(){
point(O[0]+this.p[i].x,O[1]-this.p[i].y)
}
transform(A){
for (let i = 0; i < this.p.length; i++) {
this.p[i].mul(A)
}
}
translate(l){
for (let i = 0; i < this.p.length; i++) {
this.p[i].x+=l[0]
this.p[i].y+=l[1]
}
}
}
class punkt {
constructor(x, y) {
this.x = x;
this.y = y;
}
tegn() {
point(O[0] + this.x, O[1] - this.y);
}
mul(A) {
let a = this.x;
let b = this.y;
this.x = A.x1 * a + A.x2 * b;
this.y = A.y1 * a + A.y2 * b;
}
}
function matmul(A, v) {
return new punkt(A.x1 * v.x + A.x2 * v.y, A.y1 * v.x + A.y2 * v.y);
}
function rot(t){
return new matrix(cos(t),-sin(t),sin(t),cos(t))
}
let uc = [];
let A;
let n = 0;
let u=0
let r=0
let tuc=[]
function setup() {
createCanvas(w, h);
A = new matrix(0, 1, 1, 0);
}
function draw() {
background(220);
if (mouseIsPressed) {
uc.push(new punkt(mouseX - O[0], O[1] - mouseY));
}else {
b.push(new billede(uc))
tb.push(new billede(uc))
tb[n].transform(A)
uc=[]
n = uc.length + 1;
}
if (keyIsDown(65)) {
for(let i=0;i<b.length;i++){
}
}
else if(keyIsDown(LEFT_ARROW)){t=-0.5}
else{t=0}
if(keyIsDown(UP_ARROW)){u=1}
else if(keyIsDown(DOWN_ARROW)){u=-1}
else{u=0;r=0}
}
function keyPressed(){
if(keyCode<59&&keyCode>47){
return keyCode
}else if(keyCode==65){
}
}