Skip to content

Commit b9af6f2

Browse files
committed
made sizing better
1 parent ef69d00 commit b9af6f2

File tree

3 files changed

+73
-65
lines changed

3 files changed

+73
-65
lines changed

css/secrets.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
body {
22
overflow: hidden;
3+
position: relative;
4+
left: -100px;
5+
top: -100px;
6+
background: #000;
37
}
48

59
.row {
610
display: flex;
711
margin-left: 1em;
812
}
13+
.row:nth-child(2n) {
14+
position: relative;
15+
left: -75px;
16+
}
17+
18+
svg {
19+
margin: 8px;
20+
}
921

1022
.cell:hover, .cell:visited, .cell:focus {
1123
animation: loaderAnim 5s ease-in-out infinite normal forwards;
24+
padding: 0;
25+
margin: 0;
1226
}
1327

1428

@@ -17,7 +31,7 @@ body {
1731
transform:rotate(0deg);
1832
}
1933
50% {
20-
transform:rotate(180deg);
34+
transform:rotate(90deg);
2135
}
2236
100% {
2337
transform:rotate(0deg);

js/2secrets.js

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,53 @@
1-
document.body.style.background = 'black';
2-
31
var height = $('body').height();
42
var width = $('body').width();
5-
var mobileSize = 200;
6-
var desktopSize = 150;
7-
var radius = 0, rows = 0, cols = 0, size;
3+
// var mobileSize = 200;
4+
// var desktopSize = 150;
5+
var radius = 0, rows = 0, cols = 0, size = 150;
86

97
// Define rows, colnums, and shape radius based on document size
10-
// var isMobile = window.matchMedia("only screen and (max-width: 850px)").matches ||
11-
// /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
12-
// var isOtherMediaQuery = window.matchMedia("only screen and (min-width:1080px)").matches;
13-
size = desktopSize;
8+
var isMobile = window.matchMedia("only screen and (max-width: 850px)").matches ||
9+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
10+
var isOtherMediaQuery = window.matchMedia("only screen and (min-width:1080px)").matches;
11+
if(isMobile && !isOtherMediaQuery) {
12+
size = 200;
13+
} else {
14+
size = 150;
15+
}
16+
1417
rows = Math.floor(height / size);
1518
cols = Math.floor(width / size);
1619
radius = Math.floor(Math.max(width, height) / Math.max(rows, cols)) / 2;
1720

18-
var shapes = makeFlowers();
19-
var flowers = [];
21+
console.log(rows);
22+
console.log(cols);
2023

2124
for (var r = 0; r < rows; r++) {
2225
var rowId = "row" + r;
2326
var row = $("<div/>").addClass("row").attr("id", rowId).appendTo('body');
24-
// even rows have an offset of 0.5
25-
var even = !!(r % 2);
2627
var vi = r / (rows - 1);
2728
for (var c = 0; c < cols; c++) {
28-
// var cell = $("<div/>").addClass("cell").appendTo(row);
2929
var cellId = "cell" + ((r * rows) + c);
30-
$(row).append('<div class="cell" id="' + cellId + '"></div>')
31-
var k = c;
32-
if (even) {
33-
k += 0.5;
34-
// we skip the final col on even rows to avoid overflow
35-
if (c >= cols - 1) {
36-
continue;
37-
}
38-
} else {
39-
row.css("position", "relative");
40-
row.css("left", (size / 2 * -1 + "px"));
41-
}
42-
var hi = k /(cols - 1);
43-
var shape = pickFlower(shapes);
44-
shape.translation.set((size + 25) / 2, (size + 25) / 2);
45-
// shape.translation.set(hi * width, vi * height);
46-
// Setup the canvas
47-
var two = new Two({
48-
width: size + 25,
49-
height:size + 25
50-
}).appendTo(document.getElementById(cellId));
51-
52-
// $(cellId).click(function(e) {
53-
// document.getElementById(cellId)
54-
// }
55-
56-
two.add(shape);
57-
two.update();
58-
flowers.push(shape);
30+
$(row).append('<div class="cell" id="' + cellId + '"></div>');
5931
}
6032
}
6133

62-
//
34+
35+
var flowers = [];
36+
var shapes = makeFlowers();
37+
38+
$(".cell").each(function (index, object) {
39+
var two = new Two({
40+
width: size + 20,
41+
height:size + 20
42+
}).appendTo(object);
43+
var shape = pickFlower(shapes);
44+
shape.translation.set(two.width / 2, two.height / 2);
45+
two.add(shape);
46+
two.update();
47+
flowers.push(shape);
48+
});
49+
50+
//
6351
// for (var f in flowers) {
6452
// var flower = flowers[f];
6553
// $(flower._renderer.elem)
@@ -68,7 +56,6 @@ for (var r = 0; r < rows; r++) {
6856
// })
6957
// }
7058

71-
7259
function roseMath(v, k, t) {
7360
v.x = radius * Math.cos(k * t) * Math.cos(t);
7461
v.y = radius * Math.cos(k * t) * Math.sin(t);
@@ -95,7 +82,7 @@ function pickFlower(flowers) {
9582
var f = Math.floor(Math.random() * flowers.length);
9683
var flower = flowers[f].clone();
9784
// Style the shape
98-
var colors = ['tomato', 'orangered',
85+
var colors = ['tomato', 'orangered', 'floralwhite',
9986
'gold', 'red', 'darkorange'];
10087
var color = colors[Math.floor(Math.random() * colors.length)];
10188
flower.stroke = color;

js/secrets.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ var two = new Two({
55
fullscreen: true,
66
autostart: true
77
}).appendTo(document.body);
8-
document.body.style.background = 'black';
8+
// document.body.style.background = 'black';
99

1010

11-
var radius = 0, rows = 0, cols = 0;
11+
var radius = 0, rows = 0, cols = 0, size;
1212
var isMobile = window.matchMedia("only screen and (max-width: 850px)").matches ||
1313
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1414
var isOtherMediaQuery = window.matchMedia("only screen and (min-width:1080px)").matches;
1515
if(isMobile && !isOtherMediaQuery) {
16-
rows = Math.floor(two.height / 200);
17-
cols = Math.floor(two.width / 200);
18-
radius = Math.floor(two.height / rows) * .62;
16+
size = 200;
1917
} else {
20-
rows = Math.floor(two.height / 150);
21-
cols = Math.floor(two.width / 150);
22-
radius = Math.floor(Math.max(two.width, two.height) / Math.max(rows, cols)) / 2;
18+
size = 150;
2319
}
24-
var shapes = makeFlowers();
20+
rows = Math.floor(two.height / size);
21+
cols = Math.floor(two.width / size);
22+
radius = Math.floor(Math.max(two.width, two.height) / Math.max(rows, cols)) / 2;
2523
var flowers = [];
24+
var shapes = makeFlowers();
25+
2626

2727
for (var r = 0; r < rows; r++) {
2828
// even rows have an offset of 0.5
@@ -77,21 +77,28 @@ function makeFlowers() {
7777
}
7878
return flowers;
7979
}
80-
80+
var f = 0;
8181
function pickFlower(flowers) {
82-
var f = Math.floor(Math.random() * flowers.length);
82+
// var f = Math.floor(Math.random() * flowers.length);
83+
if (f == flowers.length) {
84+
f = 0;
85+
}
86+
if (typeof flowers[f] === 'undefined') {
87+
f++;
88+
}
8389
var flower = flowers[f].clone();
90+
f++;
8491
// Style the shape
85-
var colors = ['tomato', 'lightsalmon', 'floralwhite', 'orangered',
86-
'gold', 'red', 'darkorange'];
87-
var color = colors[Math.floor(Math.random() * colors.length)];
88-
flower.stroke = color;
89-
flower.fill = color;
92+
// var colors = ['tomato', 'lightsalmon', 'floralwhite', 'orangered',
93+
// 'gold', 'red', 'darkorange'];
94+
// var color = colors[Math.floor(Math.random() * colors.length)];
95+
// flower.stroke = color;
96+
// flower.fill = color;
9097
flower.linewidth = 4;
9198
flower.cap = 'round';
9299
// flower.rotation = Math.floor(Math.random() * 4) * Math.PI / 2 + Math.PI / 4;
93100
// For animation later on
94-
flower.step = (Math.floor(Math.random() * 8) / 8) * Math.PI / 60;
95-
flower.step *= Math.random() > 0.5 ? - 1 : 1;
101+
// flower.step = (Math.floor(Math.random() * 8) / 8) * Math.PI / 60;
102+
// flower.step *= Math.random() > 0.5 ? - 1 : 1;
96103
return flower;
97104
}

0 commit comments

Comments
 (0)