float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useReducer } from "react"; | |
import ReactDOM from "react-dom"; | |
const initialState = { | |
items: [], | |
total: 0 | |
}; | |
const actions = { | |
ADD_ITEM: "ADD_ITEM", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext, useContext, useState } from "react"; | |
import ReactDOM from "react-dom"; | |
// 创建一个Context对象 | |
const ExampleContext = createContext(); | |
// 创建一个自定义的Provider组件 | |
function ExampleProvider({ children }) { | |
// 使用useState Hook创建一个状态 | |
const [value, setValue] = useState("Initial Value"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.zhihu.com/question/650059927 | |
function highestComboTest(target = 12) { | |
let combo = 0; | |
let comboArr = []; | |
let testCount = 10000; | |
for (let i = 0; i < testCount; i++) { | |
if (Math.random() >= 0.5) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function singleton(clazz) { | |
let instance; | |
return new Proxy(clazz, { | |
construct(target, args) { | |
if (instance) { | |
return instance; | |
} else { | |
instance = new target(...args); | |
return instance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Classic Perlin 3D Noise | |
// by Stefan Gustavson | |
// | |
vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);} | |
vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;} | |
vec3 fade(vec3 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);} | |
float cnoise(vec3 P){ | |
vec3 Pi0 = floor(P); // Integer part for indexing | |
vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1 |