Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*МИРОГЕНЕРАТОР*/
- //density, size, probability(плотность, размер, вероятность)
- function drawWorld(density, size, probability)
- {
- nsize = size;
- ctx.fillStyle = '#aaa'
- for(x = 0; x < cvs.width; x+=density)
- {
- for(y = 0; y < cvs.height; y+=density)
- {
- if(randomizer(x, y, 100) > probability)
- {
- osize = nsize;
- nsize = randomizer(x, y, size);
- s = (x + size - x) + (y + size - y);
- p = x + y;
- q = p / s;
- csize = interpolate(osize, nsize, q);
- ctx.fillRect(x, y, csize, csize);
- }
- }
- }
- }
- function randomizer(x, y, max)
- {
- WorldCounter++;
- if(WorldCounter == WorldConstant) WorldCounter = 0;
- return (x ^ y * WorldCounter) % max;
- }
- //Интерполяция косинусоидальная
- function interpolate(a, b, x)
- {
- return a * (1 - ((1 - Math.cos(x * Math.PI)) / 2)) + b * ((1 - Math.cos(x * 3.1415927)) / 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement