surprisingSpaceGeomatry
by Yiler_Huang
CSS
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background: #EBDFB9;
}
JavaScript
let draw = SVG().addTo('body').size(1920, 1080);
function randomRange(min, max) {
return min + ((max - min) * Math.random())
}
function buildArray(n, fillFunction) {
let outputArray = [];
for (let i = 0; i < n; i++) {
outputArray.push(fillFunction(i));
}
return outputArray;
}
class GComet {
constructor(x,y) {
this.x = x;
this.y = y;
}
addToSVG(drawing) {
let cometGroup = draw.group();
let cometb = draw.polygon('130,0 650,520 624,650');
cometb.fill(new SVG.Color({
r: 43,
g: 100,
b: 143
})).move(20, 20);
let cometr = draw.polygon('130,0 728,676 702,806');
cometr.fill(new SVG.Color({
r: 171,
g: 2,
b: 37
})).move(20, 20);
cometGroup.add(cometb)
cometGroup.add(cometr)
cometGroup.move(this.x,this.y)
}
}
class Robot {
constructor (x,y){
this.x = x;
this.y = y;
}
addToSVG(drawing){
let robotGroup = draw.group();
let s1 = draw.rect(10,60).move(this.x + 73,this.y -60);
s1.fill(new SVG.Color({r:4, g:25, b:51}))
let rRect = draw.rect(160,100).move(this.x,this.y)
rRect.fill(new SVG.Color({r:145, g:161, b:173}))
let rEye = draw.ellipse(30,30).move(this.x + 20,this.y + 20)
rEye.fill(new SVG.Color({r:171, g:2, b:37}))
let lEye = draw.ellipse(30,30).move(this.x + 105,this.y + 20)
lEye.fill(new SVG.Color({r:171, g:2, b:37}))
robotGroup.add(rRect);
robotGroup.add(rEye);
robotGroup.add(lEye);
}
}
class SmallStars {
constructor(x) {
if (x == 1){this.color = new SVG.Color({r:196, g:158, b:55})}
else if (x == 2){this.color = new SVG.Color({r:167, g:207, b:203})}
this.size = randomRange(0.1, 0.3)
this.xPosition = randomRange(0, 1920)
this.yPosition = randomRange(0, 1080)
if (x == 1){this.randomAdjustment = randomRange(0,40)}
else if (x == 2){this.randomAdjustment = randomRange(0,40) * -1}
}
addToSVG(drawing) {
return drawing.polygon(`${this.xPosition},${this.yPosition}...