Skip to content

Commit

Permalink
Eslinted JS code in *.js and *.html
Browse files Browse the repository at this point in the history
  • Loading branch information
boytchev committed Jun 4, 2024
1 parent 5fa581e commit d49ace1
Show file tree
Hide file tree
Showing 51 changed files with 5,434 additions and 1,953 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
## 1.4.0
* Added fordite texture design via *fordite.js*
* `noiseSeed` from *noise.js* has optionsl scaling parameter
* Using DeepScan to fix code
* Using eslint to format code

## 1.3.0
* Added clouds texture design via *clouds.js*
Expand Down
13 changes: 13 additions & 0 deletions REBUILD.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
rem next if is used to not close the window in case of error
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )

@call npx eslint --fix src\*.js

@call npx eslint --fix src\patterns\*.js

@call npx eslint --fix online\*.js

@call npx eslint --fix online\*.html

@call npx eslint --fix examples\*.html
101 changes: 101 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import globals from "globals";
import html from "eslint-plugin-html";

export default [
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
globals: {
...globals.browser,
}
},

files: ["**/*.html"],
plugins: {html},

"rules": {
"array-bracket-spacing": ["error", "always", { "singleValue": true, "arraysInArrays": false }],
"block-spacing": ["error", "always"],
"brace-style": [ "error", "1tbs", { "allowSingleLine": true } ],
"comma-spacing": ["error", { "before": false, "after": true }],
"comma-style": [ 2, "last" ],
"computed-property-spacing": ["error", "always"],
"eol-last": ["error", "always"],
"func-call-spacing": ["error", "never"],
"indent": ["error", "tab", { "SwitchCase": 1 }],
"key-spacing": ["error", { "beforeColon": false }],

"new-parens": ["error"],
"no-trailing-spaces": ["error", { "skipBlankLines": false }],
"no-whitespace-before-property": ["error"],

"object-curly-spacing": ["error", "always"],

"padded-blocks": ["error", {
"blocks": "always",
"switches": "always",
"classes": "always"
}],

"semi": ["error", "always", { "omitLastInOneLineBlock": true }],
"semi-spacing": ["error", {"before": false, "after": true}],
"space-before-blocks": ["error", { "functions": "always", "keywords": "always", "classes": "always" }],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "ignore"
}],
// was: "space-in-parens": ["error", "always" ],
"space-in-parens": ["error", "always", { "exceptions": ["[]"] } ],
// was: "space-infix-ops": ["error"],
"space-unary-ops": ["error", {
"words": true,
"nonwords": false,
"overrides": {
}
}],

"keyword-spacing": ["error", { "before": true, "after": true }],
"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": "block-like", "next": "*" }
],

/* Best Practices */

// "eqeqeq": 0, // Require === and !==
// "new-cap": 0, // Disallow captialized function to be used without new.
"no-multi-spaces": 2, // Don't care if there's more than one space anywhere.
// was: // "no-unused-expressions": 0, // Don't care if there are unused experssions. eg "flag && doThing();"
"no-unused-expressions": "error", // Care if there are unused experssions. eg "flag && doThing();"
// "consistent-return": 0, // Don't care if some returns return no value

/* Variables */

"no-undef": 1,
"no-unused-vars": 1,

/* Possible Errors */

"no-extra-semi": 1, // Disallow extra semicolons. Example function foo() { };


// "camelcase": 0, // Disallow names_with_underscore
// "no-mixed-spaces-and-tabs": 0, // Disallow both spaces and tabs in the same line for indenting
// "strict": 0, // Require "use strict"

// "yoda": 0, // Don't care if it's "if (1 == v)" or "if (v == 123)".
// "no-empty": 0, // Don't care if we have empty blocks
// "no-shadow": 0, // Don't care if the same variable name is used in an inner scope.

// "dot-notation": 0, // Don't care if it's obj["prop"] instead of obj.prop
// "no-console": 0, // allow the use of console
// "curly": 0, // Don't require all if statements to have curly braces
// "no-redeclare": 0, // Don't care if var declared more than once in same scope. eg for (var x, ...) for (var x, ...);
// "quotes": 0, // Don't care if quotes are double or single
// "no-use-before-define": 0, // don't care if something is used before it's defined.
// "no-underscore-dangle": 0, // don't care if var starts with underscore
}
}
];
146 changes: 76 additions & 70 deletions examples/ao-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,84 +35,88 @@ <h3 class="white">Ambient occlusion texture is generated at runtime by <a href="
import * as PET from "pet/patterns/polka-dots.js";



// setting up the scene

var scene = new THREE.Scene();
scene.background = new THREE.Color( 0x202020 );
scene.background = new THREE.Color( 0x202020 );

var camera = new THREE.PerspectiveCamera( 40, innerWidth/innerHeight );
camera.position.set( 0, 0, 10 );
camera.lookAt( scene.position );
camera.position.set( 0, 0, 10 );
camera.lookAt( scene.position );

var renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( innerWidth, innerHeight );
renderer.setAnimationLoop( animationLoop );
document.body.appendChild( renderer.domElement );

window.addEventListener( "resize", ( /*event*/ ) => {

var renderer = new THREE.WebGLRenderer( {antialias: true} );
renderer.setSize( innerWidth, innerHeight );
renderer.setAnimationLoop( animationLoop );
document.body.appendChild( renderer.domElement );

window.addEventListener( "resize", (event) => {
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix( );
renderer.setSize( innerWidth, innerHeight );
});

} );

var hiddenCamera = camera.clone();
hiddenCamera.position.set(0,0,1);
hiddenCamera.position.set( 0, 0, 1 );

var controls = new OrbitControls( hiddenCamera, renderer.domElement );
controls.enableDamping = true;
controls.autoRotate = !true;
controls.autoRotateSpeed = 0.5;
controls.enableDamping = true;
controls.autoRotate = !true;
controls.autoRotateSpeed = 0.5;

var light = new THREE.PointLight( 'white', 30 );
light.position.set( 0, 0, 10 );
scene.add( light );
light.position.set( 0, 0, 10 );
scene.add( light );

scene.add( new THREE.AmbientLight( 'white', 2 ) );

scene.add( new THREE.AmbientLight( 'white',2 ) );



// generator of bumps
function buildBumps( positions, material )
{

function buildBumps( positions, material ) {

var bumps = new THREE.Group(),
geometry = new THREE.SphereGeometry( 0.2 ).translate(0,0,-1.05);
for( var pos of positions.points )
{
geometry = new THREE.SphereGeometry( 0.2 ).translate( 0, 0, -1.05 );

for ( var pos of positions.points ) {

var bump = new THREE.Mesh( geometry, material );
bump.position.copy( pos );
bump.lookAt( 0, 0, 0 );
bump.position.copy( pos );
bump.lookAt( 0, 0, 0 );

bumps.add( bump );

}

return bumps;

}



// left ball

var leftMaterial = new THREE.MeshPhysicalMaterial( {
color: 'white',
metalness: 1,
roughness: 0,
emissive: 'white',
emissiveIntensity: 1.5,
} );
color: 'white',
metalness: 1,
roughness: 0,
emissive: 'white',
emissiveIntensity: 1.5,
} );

var leftBall = new THREE.Mesh(
new THREE.SphereGeometry( 2 ),
PET.material(new THREE.MeshPhysicalMaterial( {
metalness: 0.5,
roughness: 1,
aoMap: PET.texture({width:256, layout:9, blur:90, scale:40}),
} ))
new THREE.SphereGeometry( 2 ),
PET.material( new THREE.MeshPhysicalMaterial( {
metalness: 0.5,
roughness: 1,
aoMap: PET.texture( { width: 256, layout: 9, blur: 90, scale: 40 } ),
} ) )
);

leftBall.add( buildBumps( PET.defaults.$layouts[8], leftMaterial ) );
leftBall.add( buildBumps( PET.defaults.$layouts[ 8 ], leftMaterial ) );
leftBall.position.x = -2.5;
scene.add( leftBall );

Expand All @@ -123,55 +127,57 @@ <h3 class="white">Ambient occlusion texture is generated at runtime by <a href="
var rightMaterial = leftMaterial.clone();

var rightBall = new THREE.Mesh(
new THREE.SphereGeometry( 2, 64, 32 ),
PET.material(new THREE.MeshPhysicalMaterial( {
metalness: 0.5,
roughness: 1,
aoMap: PET.texture({width:512, layout:10, blur:80, scale:40}),
} ))
new THREE.SphereGeometry( 2, 64, 32 ),
PET.material( new THREE.MeshPhysicalMaterial( {
metalness: 0.5,
roughness: 1,
aoMap: PET.texture( { width: 512, layout: 10, blur: 80, scale: 40 } ),
} ) )
);

rightBall.add( buildBumps( PET.defaults.$layouts[9], rightMaterial ) );
rightBall.add( buildBumps( PET.defaults.$layouts[ 9 ], rightMaterial ) );
rightBall.position.x = 2.5;
scene.add( rightBall );



// main animation loop to turn lights on-off
function animationLoop( t )
{

function animationLoop( t ) {

t = t/1300;

// control left ball
var onOff = Math.sin(t)**5 - Math.sin(3*t)**5 > 0;

var onOff = Math.sin( t )**5 - Math.sin( 3*t )**5 > 0;

leftBall.material.color.setStyle( onOff ? 'SteelBlue' : 'LightSteelBlue' );
leftBall.material.aoMapIntensity = onOff ? 2 : -8;
leftMaterial.emissiveIntensity = onOff ? 0 : 1;

// control right ball
onOff = Math.cos(3*t)**5 - Math.sin(t)**5 > 0;

onOff = Math.cos( 3*t )**5 - Math.sin( t )**5 > 0;

rightBall.material.color.setStyle( onOff ? 'SteelBlue' : 'LightSteelBlue' );
rightBall.material.aoMapIntensity = onOff ? 2 : -8;
rightMaterial.emissiveIntensity = onOff ? 0 : 1.5;

// control ball rotation

controls.update( );

for( var ball of [leftBall, rightBall])
{
for ( var ball of [ leftBall, rightBall ]) {

ball.scale.setScalar( 1/controls.getDistance() );
ball.quaternion.copy( hiddenCamera.quaternion ).conjugate();

}

renderer.render( scene, camera );

}

</script>
</body>
</html>
Loading

0 comments on commit d49ace1

Please sign in to comment.