Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide beta fox assets and demo #50

Merged
merged 4 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,453 changes: 1,453 additions & 0 deletions beta-fox.json

Large diffs are not rendered by default.

2,389 changes: 2,389 additions & 0 deletions docs/beta/bundle.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docs/beta/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<title>---</title>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta charset=utf-8>
</head>
<body>
<div></div>
<script src="bundle.js"></script>
<p>Press C to copy the SVG text of the image.</p>
darkwing marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>
10 changes: 4 additions & 6 deletions docs/distort/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ createDistortedLogo({
followMouse: true,
followMotion: true,
lazyRender: false,
meshJson: foxJson,
})

function createDistortedLogo (options) {
Expand All @@ -37,7 +38,7 @@ function createDistortedLogo (options) {
'Grow': distortGrow,
}
let applyDistortion = Object.values(distortionMethods)[0]

Object.entries(distortionMethods).forEach(([description, distortionFn]) => {
const button = document.createElement('button')
button.innerText = description
Expand Down Expand Up @@ -125,11 +126,6 @@ function distortFold (positions, origPositions) {
}
}

// random between (-1, 1)
function getRandom () {
return (2 * Math.random()) - 1
}

darkwing marked this conversation as resolved.
Show resolved Hide resolved
// sin between 0-1
function getSinIntensity (speed = 1000) {
return (Math.sin(Date.now() / speed) + 1) / 2
Expand Down Expand Up @@ -1962,9 +1958,11 @@ function createLogoViewer (container, renderScene, {
shouldRender = true
}
function setFollowMouse (state) {
// eslint-disable-next-line no-param-reassign
followMouse = state
}
function setFollowMotion (state) {
// eslint-disable-next-line no-param-reassign
followMotion = state
}

Expand Down
3 changes: 3 additions & 0 deletions docs/gradient/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ createGradientLogo({
height: 0.4,
followMouse: true,
followMotion: true,
meshJson: foxJson,
})

function createGradientLogo (options) {
Expand Down Expand Up @@ -2056,9 +2057,11 @@ function createLogoViewer (container, renderScene, {
shouldRender = true
}
function setFollowMouse (state) {
// eslint-disable-next-line no-param-reassign
followMouse = state
}
function setFollowMotion (state) {
// eslint-disable-next-line no-param-reassign
followMotion = state
}

Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<li><a href="./gradient/index.html">gradient</a></li>
<li><a href="./recolor/index.html">recolor</a></li>
<li><a href="./distort/index.html">distort</a></li>
<li><a href="./beta/index.html">beta</a></li>
</ol>
</body>
</html>
16 changes: 12 additions & 4 deletions docs/normal/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const copy = require('copy-to-clipboard')
const createViewer = require('..')
const { svgElementToSvgImageContent } = require('../util')
const foxJson = require('../fox.json')

document.addEventListener('keypress', function (event) {
if (event.keyCode === 99) { // the c key
Expand All @@ -16,9 +17,10 @@ createViewer({
height: 0.4,
followMouse: true,
followMotion: true,
meshJson: foxJson,
})

},{"..":3,"../util":13,"copy-to-clipboard":4}],2:[function(require,module,exports){
},{"..":3,"../fox.json":2,"../util":13,"copy-to-clipboard":4}],2:[function(require,module,exports){
module.exports={
"positions": [
[
Expand Down Expand Up @@ -1447,7 +1449,6 @@ module.exports={
}

},{}],3:[function(require,module,exports){
const foxJson = require('./fox.json')
const {
calculateSizingOptions,
createLogoViewer,
Expand All @@ -1460,15 +1461,20 @@ const {
module.exports = createLogo

function createLogo (options = {}) {
if (!options.meshJson) {
throw new Error('The meshJson parameter is required')
}

const cameraDistance = options.cameraDistance || 400
const { height, width } = calculateSizingOptions(options)
const modelJson = options.meshJson

const container = createNode('svg')
setAttribute(container, 'width', `${width}px`)
setAttribute(container, 'height', `${height}px`)
document.body.appendChild(container)

const modelObj = loadModelFromJson(foxJson)
const modelObj = loadModelFromJson(modelJson)
const renderFox = createModelRenderer(container, cameraDistance, modelObj)
const renderScene = (lookCurrent, slowDrift) => {
const rect = container.getBoundingClientRect()
Expand All @@ -1478,7 +1484,7 @@ function createLogo (options = {}) {
return createLogoViewer(container, renderScene, { cameraDistance, ...options })
}

},{"./fox.json":2,"./util.js":13}],4:[function(require,module,exports){
},{"./util.js":13}],4:[function(require,module,exports){
'use strict';

var deselectCurrent = require('toggle-selection');
Expand Down Expand Up @@ -1998,9 +2004,11 @@ function createLogoViewer (container, renderScene, {
shouldRender = true
}
function setFollowMouse (state) {
// eslint-disable-next-line no-param-reassign
followMouse = state
}
function setFollowMotion (state) {
// eslint-disable-next-line no-param-reassign
followMotion = state
}

Expand Down
3 changes: 3 additions & 0 deletions docs/recolor/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const viewer = createRecolorLogo({
height: 0.4,
followMouse: true,
followMotion: true,
meshJson: foxJson,
})

const foxDiv = document.querySelector('body div.fox')
Expand Down Expand Up @@ -2172,9 +2173,11 @@ function createLogoViewer (container, renderScene, {
shouldRender = true
}
function setFollowMouse (state) {
// eslint-disable-next-line no-param-reassign
followMouse = state
}
function setFollowMotion (state) {
// eslint-disable-next-line no-param-reassign
followMotion = state
}

Expand Down
20 changes: 20 additions & 0 deletions example/beta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const copy = require('copy-to-clipboard')
const createViewer = require('..')
const { svgElementToSvgImageContent } = require('../util')
const meshJson = require('../beta-fox.json')

document.addEventListener('keypress', function (event) {
if (event.keyCode === 99) { // the c key
const svg = document.querySelector('svg')
const content = svgElementToSvgImageContent(svg)
copy(content)
}
})

createViewer({
width: 0.4,
height: 0.4,
followMouse: true,
followMotion: true,
meshJson,
})
1 change: 1 addition & 0 deletions example/distort.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ createDistortedLogo({
followMouse: true,
followMotion: true,
lazyRender: false,
meshJson: foxJson,
})

function createDistortedLogo (options) {
Expand Down
1 change: 1 addition & 0 deletions example/gradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ createGradientLogo({
height: 0.4,
followMouse: true,
followMotion: true,
meshJson: foxJson,
})

function createGradientLogo (options) {
Expand Down
2 changes: 2 additions & 0 deletions example/normal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const copy = require('copy-to-clipboard')
const createViewer = require('..')
const { svgElementToSvgImageContent } = require('../util')
const foxJson = require('../fox.json')

document.addEventListener('keypress', function (event) {
if (event.keyCode === 99) { // the c key
Expand All @@ -15,4 +16,5 @@ createViewer({
height: 0.4,
followMouse: true,
followMotion: true,
meshJson: foxJson,
})
1 change: 1 addition & 0 deletions example/recolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const viewer = createRecolorLogo({
height: 0.4,
followMouse: true,
followMotion: true,
meshJson: foxJson,
})

const foxDiv = document.querySelector('body div.fox')
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const foxJson = require('./fox.json')
const {
calculateSizingOptions,
createLogoViewer,
Expand All @@ -11,6 +10,10 @@ const {
module.exports = createLogo

function createLogo (options = {}) {
if (!options.meshJson) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered making fox.json the default meshJson rather than making it a strict requirement? That would let us release this as a non-breaking change (I think).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, yes; I got the impression from @danfinlay's comment that we should keep this package as small as possible, but yeah, I'll go back to a default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Using fox.json by default shouldn't affect package size - it was still being included. Unless you meant to remove it.

throw new Error('The meshJson parameter is required')
}

const cameraDistance = options.cameraDistance || 400
const { height, width } = calculateSizingOptions(options)

Expand All @@ -19,7 +22,7 @@ function createLogo (options = {}) {
setAttribute(container, 'height', `${height}px`)
document.body.appendChild(container)

const modelObj = loadModelFromJson(foxJson)
const modelObj = loadModelFromJson(options.meshJson)
const renderFox = createModelRenderer(container, cameraDistance, modelObj)
const renderScene = (lookCurrent, slowDrift) => {
const rect = container.getBoundingClientRect()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": ">=12.0.0"
},
"scripts": {
"build": "yarn bundle normal && yarn bundle gradient && yarn bundle recolor && yarn bundle distort",
"build": "yarn bundle normal && yarn bundle gradient && yarn bundle recolor && yarn bundle distort && yarn bundle beta",
"bundle": "./example/build.sh",
"convert": "node convert.js > fox.json",
"lint": "eslint . --ext js,json",
Expand Down