Skip to content

Commit

Permalink
Created outside board layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ErickPetru committed Sep 11, 2019
1 parent dc11ba2 commit 9622f98
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 35 deletions.
92 changes: 85 additions & 7 deletions src/css/base.styl
Original file line number Diff line number Diff line change
@@ -1,18 +1,96 @@
vendors = official webkit

@import './functions'

html, body
height: 100%
overflow: hidden

body
position: relative
margin: 0
padding: 0
background: #000
font: 400 1.15em / 1.1 fantasy

#background
position: absolute
width: 100%
height: 100%
background: radial-gradient(ellipse at center, #0869ad 0%, (#2aa9e0 - 70%) 100%)
overflow: hidden
z-index: 1

#content
position: relative
display: flex
flex-flow: column
justify-content: center
align-items: center
z-index: 2
@media (orientation: landscape)
flex-flow: row

header, main, section
display: flex
flex: 2
justify-content: center
align-items: center
margin: 0
padding: 0
height: 100vh
font: 1.15em / 1.3 sans-serif
background: linear-gradient(to bottom, #1e528e 0%,#728a7c 50%,#e9ce5d 100%)
overflow: auto

.transitions-off
transition: none !important
header, section
flex: 1
flex-flow: column
color: #fff
font-size: 2em
h1
text-align: right
font: 400 1.5em / .85 fantasy
span
display: block
strong
font-size: 2em

section
@media (orientation: portrait)
margin-top: 1.25rem

#message
position: fixed
top: 0
right: 0
bottom: 0
left: 0
z-index: 3
display: flex
justify-content: center
align-items: center
background: #000b
backdrop-filter: sepia(.5) brightness(.75) blur(10px)
font-size: 3.5em
z-index: 3
display: none

.text-shine
geometric-pattern: #daefff #fff5 #bdd5 10px 17.5px
position: relative
color: transparent
-webkit-background-clip: text
background-clip: text
&::before
position: absolute
top: 0
left: 0
width: 100%
height: 100%
background: linear-gradient(45deg, rgba(255, 255, 255, 0) 45%, rgba(255, 255, 255, .8) 50%, rgba(255, 255, 255, 0) 55%, rgba(255, 255, 255, 0) 100%)
background-size: 250%
color: transparent
content: attr(data-text)
text-shadow: 0 1px 2px #0009, -2px 2px 20px #0001, 2px 2px 20px #0001, 0 15px 35px #0003
animation: text-shine 3.5s ease-in 2s infinite both
-webkit-background-clip: text
mix-blend-mode: screen

@import './keyframes'
@import './board'
Expand Down
2 changes: 1 addition & 1 deletion src/css/board.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ game-board
border-radius: 10px
cursor: default
box-shadow: inset 0 5px 30px #0007
// backdrop-filter: blur(20px)
backdrop-filter: blur(7px)
&[grabbing]
cursor: grabbing !important
&:not([animating]) board-slot:not(:empty)
Expand Down
13 changes: 13 additions & 0 deletions src/css/functions.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
geometric-pattern(args...)
background-color: args[0]
background-image: linear-gradient(30deg, args[2] 12%, transparent 12.5%, transparent 87%, args[2] 87.5%, args[2]), linear-gradient(150deg, args[2] 12%, transparent 12.5%, transparent 87%, args[2] 87.5%, args[2]), linear-gradient(30deg, args[2] 12%, transparent 12.5%, transparent 87%, args[2] 87.5%, args[2]), linear-gradient(150deg, args[2] 12%, transparent 12.5%, transparent 87%, args[2] 87.5%, args[2]), linear-gradient(60deg, args[1] 25%, transparent 25.5%, transparent 75%, args[1] 75%, args[1]), linear-gradient(60deg, args[1] 25%, transparent 25.5%, transparent 75%, args[1] 75%, args[1])
background-position: 0 0, 0 0, args[3] args[4], args[3] args[4], 0 0, args[3] args[4]
background-size: args[3] args[4]

conic-background($c, $deg = 45deg)
$arr = ($c + 12%), $c, ($c - 7%), ($c + 8%), $c, ($c - 5%), ($c + 12%), $c, ($c - 5%), ($c + 7%), $c, ($c - 7%), ($c + 15%)
background: radial-gradient(($c + 45%), ($c - 25%))
background: conic-gradient(from $deg, $arr)

random(min, max)
return floor(math(0, 'random') * (max - min + 1) + min)
13 changes: 4 additions & 9 deletions src/css/jewels.styl
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,15 @@ jewel-piece
content: ''
display: block
&.arriving
animation: jewel-arriving .25s cubic-bezier(.25, .25, .5, 1.1) forwards
animation: jewel-arriving .2s cubic-bezier(.25, .25, .5, 1.1) forwards
&.falling
transition: transform .25s cubic-bezier(.25, .25, .5, 1.1)
transition: transform .1s cubic-bezier(.25, .25, .5, 1.1)
&.moving
transition: transform .25s cubic-bezier(.25, .25, .5, 1.1)
transition: transform .1s cubic-bezier(.25, .25, .5, 1.1)
&.flipping
transition: transform .15s ease-in
&.exploding
animation: jewel-exploding .25s ease-out forwards

conic-background($c, $deg = 45deg)
$arr = ($c + 12%), $c, ($c - 7%), ($c + 8%), $c, ($c - 5%), ($c + 12%), $c, ($c - 5%), ($c + 7%), $c, ($c - 7%), ($c + 15%)
background: radial-gradient(($c + 45%), ($c - 25%))
background: conic-gradient(from $deg, $arr)
animation: jewel-exploding .35s ease-out forwards

jewel-piece:not([promoted='rainbow']):not([promoted='nebula'])
&[type='square']
Expand Down
13 changes: 11 additions & 2 deletions src/css/keyframes.styl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@keyframes text-shine
0%
background-position: -200%
100%
background-position: 125%

@keyframes slot-selected
0%
outline-color: #8be5
Expand Down Expand Up @@ -29,10 +35,13 @@
@keyframes jewel-exploding
0%
opacity: 1
transform: scale(1) translateY(0)
transform: scale(1)
75%
opacity: 1
transform: scale(1.15)
100%
opacity: 0
transform: scale(0.25) translateY(5%)
transform: scale(0.25) translate3d(0, 5%, 0)

@keyframes jewel-brightening
0%
Expand Down
3 changes: 3 additions & 0 deletions src/css/specials.styl

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ html(lang="en")
title Jewelsback
link(rel="stylesheet", href="css/base.styl")
body
main
div#background
div#content
header
h1
span.text-shine(data-text="Jewels") Jewels
span.text-shine(data-text="back") back
main
section
label.text-shine(data-text="Score:") Score:
strong#score.text-shine(data-text="0") 0
aside#message
span.text-shine(data-text="Game over") Game over
script(src="js/index.js")
141 changes: 141 additions & 0 deletions src/js/Background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Animated background with low-poly triangles art
// Credits: Samuel Marchal (https://www.bypeople.com/svg-low-poly-background-css-js-snippet/)

export default function () {
const refreshDuration = 10000
let refreshTimeout
let numPointsX
let numPointsY
let unitWidth
let unitHeight
let points

function onLoad() {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg.setAttribute('width', window.innerWidth)
svg.setAttribute('height', window.innerHeight)
document.querySelector('#background').appendChild(svg)

const unitSize = (window.innerWidth + window.innerHeight) / 20
numPointsX = Math.ceil(window.innerWidth / unitSize) + 1
numPointsY = Math.ceil(window.innerHeight / unitSize) + 1
unitWidth = Math.ceil(window.innerWidth / (numPointsX - 1))
unitHeight = Math.ceil(window.innerHeight / (numPointsY - 1))

points = []

for (let y = 0; y < numPointsY; y++) {
for (let x = 0; x < numPointsX; x++) {
points.push(
{ x: unitWidth * x, y: unitHeight * y, originX: unitWidth * x, originY: unitHeight * y }
)
}
}

randomize()

for (let i = 0; i < points.length; i++) {
if (points[i].originX !== unitWidth * (numPointsX - 1) && points[i].originY !== unitHeight * (numPointsY - 1)) {
const topLeftX = points[i].x
const topLeftY = points[i].y
const topRightX = points[i + 1].x
const topRightY = points[i + 1].y
const bottomLeftX = points[i + numPointsX].x
const bottomLeftY = points[i + numPointsX].y
const bottomRightX = points[i + numPointsX + 1].x
const bottomRightY = points[i + numPointsX + 1].y

const rnd = Math.floor(Math.random() * 2)

for (let n = 0; n < 2; n++) {
const polygon = document.createElementNS(svg.namespaceURI, 'polygon')

if (rnd === 0) {
if (n === 0) {
polygon.point1 = i
polygon.point2 = i + numPointsX
polygon.point3 = i + numPointsX + 1
polygon.setAttribute(
'points',
`${topLeftX},${topLeftY} ${bottomLeftX},${bottomLeftY} ${bottomRightX},${bottomRightY}`
)
} else if (n === 1) {
polygon.point1 = i
polygon.point2 = i + 1
polygon.point3 = i + numPointsX + 1
polygon.setAttribute(
'points',
`${topLeftX},${topLeftY} ${topRightX},${topRightY} ${bottomRightX},${bottomRightY}`
)
}
} else if (rnd === 1) {
if (n === 0) {
polygon.point1 = i
polygon.point2 = i + numPointsX
polygon.point3 = i + 1
polygon.setAttribute(
'points',
`${topLeftX},${topLeftY} ${bottomLeftX},${bottomLeftY} ${topRightX},${topRightY}`
)
} else if (n === 1) {
polygon.point1 = i + numPointsX
polygon.point2 = i + 1
polygon.point3 = i + numPointsX + 1
polygon.setAttribute(
'points',
`${bottomLeftX},${bottomLeftY} ${topRightX},${topRightY} ${bottomRightX},${bottomRightY}`
)
}
}
polygon.setAttribute('fill', `rgba(0,0,0,${Math.random() / 3})`)
const animate = document.createElementNS('http://www.w3.org/2000/svg', 'animate')
animate.setAttribute('fill', 'freeze')
animate.setAttribute('attributeName', 'points')
animate.setAttribute('dur', `${refreshDuration}ms`)
animate.setAttribute('calcMode', 'linear')
polygon.appendChild(animate)
svg.appendChild(polygon)
}
}
}

refresh()
}

function randomize() {
for (let i = 0; i < points.length; i++) {
if (points[i].originX !== 0 && points[i].originX !== unitWidth * (numPointsX - 1)) {
points[i].x = points[i].originX + Math.random() * unitWidth - unitWidth / 2
}
if (points[i].originY !== 0 && points[i].originY !== unitHeight * (numPointsY - 1)) {
points[i].y = points[i].originY + Math.random() * unitHeight - unitHeight / 2
}
}
}

function refresh() {
randomize()
for (let i = 0; i < document.querySelector('#background svg').childNodes.length; i++) {
const polygon = document.querySelector('#background svg').childNodes[i]
const animate = polygon.childNodes[0]
if (animate.getAttribute('to')) {
animate.setAttribute('from', animate.getAttribute('to'))
}
animate.setAttribute(
'to',
`${points[polygon.point1].x},${points[polygon.point1].y} ${points[polygon.point2].x},${points[polygon.point2].y} ${points[polygon.point3].x},${points[polygon.point3].y}`
)
animate.beginElement()
}
refreshTimeout = setTimeout(() => { refresh() }, refreshDuration)
}

function onResize() {
document.querySelector('#background svg').remove()
clearTimeout(refreshTimeout)
onLoad()
}

window.onload = onLoad
window.onresize = onResize
}
Loading

0 comments on commit 9622f98

Please sign in to comment.