Skip to content

Commit

Permalink
🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
1cgonza committed Aug 30, 2024
1 parent 6312bd6 commit 3be61fe
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 244 deletions.
4 changes: 2 additions & 2 deletions src/componentes/Arch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { invertir } from '@/utilidades/ayudas';
import type { Punto } from '@/tipos';
import { div, stroke } from '@/utilidades/cosas';
import { noise } from '@/utilidades/Perlin';
import { midPt } from '@/utilidades/Polytools';
import { centro } from '@/utilidades/Polytools';
import { normRand, poly, randChoice } from '@/utilidades/Util';
import caja from '@/componentes/caja';
import chozaTecho from '@/componentes/chozaTecho';
Expand Down Expand Up @@ -326,7 +326,7 @@ var roof = function (xoff, yoff, args) {
pp = [pp[1], pp[0]];
}

const mp = midPt(pp);
const mp = centro(pp);
const a = Math.atan2(pp[1][1] - pp[0][1], pp[1][0] - pp[0][0]);
const adeg = (a * 180) / Math.PI;
canv += `<text font-size='${alto * 0.6}' font-family='Verdana' style='fill:rgba(100,100,100,0.9)' text-anchor='middle' transform='translate(${mp[0] + xoff},${mp[1] + yoff}) rotate(${adeg})'>${pla[1]}</text>`;
Expand Down
132 changes: 72 additions & 60 deletions src/componentes/Mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { normRand, poly, randChoice } from '@/utilidades/Util';
import roca from './roca';
import { tree02, tree04, tree05, tree06, tree07, tree08 } from './Tree';
import { arch01 } from './Arch';
import type { Punto } from '@/tipos';

export function flatMount(
xoff: number,
Expand All @@ -22,20 +23,19 @@ export function flatMount(
const { alto, ancho, tex, cho } = { ...predeterminados, ...args };

let canv = '';
const ptlist: number[][] = [];
const puntos: Punto[][] = [];
const reso = [5, 50];
let hoff = 0;
const flat: number[][] = [];
const flat: Punto[][] = [];

for (let j = 0; j < reso[0]; j++) {
hoff += (Math.random() * yoff) / 100;
ptlist.push([]);
puntos.push([]);
flat.push([]);

for (let i = 0; i < reso[1]; i++) {
const x = (i / reso[1] - 0.5) * Math.PI;
let y = Math.cos(x * 2) + 1;
y *= noise(x + 10, j * 0.1, seed);
const y = (Math.cos(x * 2) + 1) * noise(x + 10, j * 0.1, seed);
const p = 1 - (j / reso[0]) * 0.6;
const nx = (x / Math.PI) * ancho * p;
let ny = -y * alto * p + hoff;
Expand All @@ -48,28 +48,29 @@ export function flatMount(
}
} else {
if (flat[flat.length - 1].length % 2 == 1) {
flat[flat.length - 1].push(ptlist[ptlist.length - 1][ptlist[ptlist.length - 1].length - 1]);
flat[flat.length - 1].push(puntos[puntos.length - 1][puntos[puntos.length - 1].length - 1]);
}
}

ptlist[ptlist.length - 1].push([nx, ny]);
puntos[puntos.length - 1].push([nx, ny]);
}
}

//WHITE BG
canv += poly(ptlist[0].concat([[0, reso[0] * 4]]), {
canv += poly(puntos[0].concat([[0, reso[0] * 4]]), {
xof: xoff,
yof: yoff,
fil: 'white',
str: 'none',
});

//OUTLINE
canv += stroke(
ptlist[0].map((x) => [x[0] + xoff, x[1] + yoff]),
puntos[0].map((x) => [x[0] + xoff, x[1] + yoff]),
{ col: 'rgba(100,100,100,0.3)', noi: 1, ancho: 3 }
);

canv += texture(ptlist, {
canv += texture(puntos, {
xof: xoff,
yof: yoff,
tex: tex,
Expand All @@ -82,9 +83,11 @@ export function flatMount(
}
},
});
var grlist1 = [];
var grlist2 = [];
for (var i = 0; i < flat.length; i += 2) {

let grlist1: Punto[] = [];
let grlist2: Punto[] = [];

for (let i = 0; i < flat.length; i += 2) {
if (flat[i].length >= 2) {
grlist1.push(flat[i][0]);
grlist2.push(flat[i][flat[i].length - 1]);
Expand All @@ -94,30 +97,34 @@ export function flatMount(
if (grlist1.length == 0) {
return canv;
}
var wb = [grlist1[0][0], grlist2[0][0]];
for (var i = 0; i < 3; i++) {
var p = 0.8 - i * 0.2;

let wb = [grlist1[0][0], grlist2[0][0]];

for (let i = 0; i < 3; i++) {
const p = 0.8 - i * 0.2;
grlist1.unshift([wb[0] * p, grlist1[0][1] - 5]);
grlist2.unshift([wb[1] * p, grlist2[0][1] - 5]);
}

wb = [grlist1[grlist1.length - 1][0], grlist2[grlist2.length - 1][0]];
for (var i = 0; i < 3; i++) {
var p = 0.6 - i * i * 0.1;

for (let i = 0; i < 3; i++) {
const p = 0.6 - i * i * 0.1;
grlist1.push([wb[0] * p, grlist1[grlist1.length - 1][1] + 1]);
grlist2.push([wb[1] * p, grlist2[grlist2.length - 1][1] + 1]);
}

var d = 5;
const d = 5;
grlist1 = div(grlist1, d);
grlist2 = div(grlist2, d);

var grlist = grlist1.reverse().concat(grlist2.concat([grlist1[0]]));
for (var i = 0; i < grlist.length; i++) {
var v = (1 - Math.abs((i % d) - d / 2) / (d / 2)) * 0.12;
const grlist = grlist1.reverse().concat(grlist2.concat([grlist1[0]]));

for (let i = 0; i < grlist.length; i++) {
const v = (1 - Math.abs((i % d) - d / 2) / (d / 2)) * 0.12;
grlist[i][0] *= 1 - v + noise(grlist[i][1] * 0.5) * v;
}
/* for (var i = 0; i < ptlist.length; i++){
/* for (let i = 0; i < ptlist.length; i++){
canv += poly(ptlist[i],{xof:xoff,yof:yoff,str:"red",fil:"none",ancho:2})
}
*/
Expand All @@ -128,6 +135,7 @@ export function flatMount(
fil: 'white',
ancho: 2,
});

canv += stroke(
grlist.map((x) => [x[0] + xoff, x[1] + yoff]),
{
Expand All @@ -136,36 +144,30 @@ export function flatMount(
}
);

const bound = (plist: number[][]) => {
let xmin;
let xmax;
let ymin;
let ymax;

for (let i = 0; i < plist.length; i++) {
if (xmin == undefined || plist[i][0] < xmin) {
xmin = plist[i][0];
}
if (xmax == undefined || plist[i][0] > xmax) {
xmax = plist[i][0];
}
if (ymin == undefined || plist[i][1] < ymin) {
ymin = plist[i][1];
}
if (ymax == undefined || plist[i][1] > ymax) {
ymax = plist[i][1];
}
}
const bound = (puntos: Punto[]) => {
let xmin = Infinity;
let xmax = 0;
let ymin = Infinity;
let ymax = 0;

puntos.forEach(([x, y]) => {
if (x < xmin) xmin = x;
if (x > xmax) xmax = x;
if (y < ymin) ymin = y;
if (y > ymax) ymax = y;
});
console.log({ xmin, xmax, ymin, ymax });
return { xmin, xmax, ymin, ymax };
};

canv += flatDec(xoff, yoff, bound(grlist));
const svg = flatDec(xoff, yoff, bound(grlist));
// if (svg.includes('NaN')) console.log(svg);
canv += svg;

return canv;
}

export function flatDec(xoff, yoff, grbd) {
export function flatDec(xoff: number, yoff: number, grbd: { xmin: number; xmax: number; ymin: number; ymax: number }) {
let canv = '';
const tt = randChoice([0, 0, 1, 2, 3, 4]);

Expand All @@ -181,18 +183,22 @@ export function flatDec(xoff, yoff, grbd) {
}
);
}

if (canv.includes('NaN')) console.log(canv);

for (let j = 0; j < +randChoice([0, 0, 1, 2]); j++) {
var xr = xoff + normRand(grbd.xmin, grbd.xmax);
var yr = yoff + (grbd.ymin + grbd.ymax) / 2 + normRand(-5, 5) + 20;
for (var k = 0; k < 2 + Math.random() * 3; k++) {
const xr = xoff + normRand(grbd.xmin, grbd.xmax);
const yr = yoff + (grbd.ymin + grbd.ymax) / 2 + normRand(-5, 5) + 20;

for (let k = 0; k < 2 + Math.random() * 3; k++) {
canv += tree08(xr + Math.min(Math.max(normRand(-30, 30), grbd.xmin), grbd.xmax), yr, {
alto: 60 + Math.random() * 40,
});
}
}

if (canv.includes('NaN')) console.log(canv);
if (tt == 0) {
for (var j = 0; j < Math.random() * 3; j++) {
for (let j = 0; j < Math.random() * 3; j++) {
canv += roca(
xoff + normRand(grbd.xmin, grbd.xmax),
yoff + (grbd.ymin + grbd.ymax) / 2 + normRand(-5, 5) + 20,
Expand All @@ -205,17 +211,20 @@ export function flatDec(xoff, yoff, grbd) {
);
}
}
if (canv.includes('NaN')) console.log(canv);
if (tt == 1) {
var pmin = Math.random() * 0.5;
var pmax = Math.random() * 0.5 + 0.5;
var xmin = grbd.xmin * (1 - pmin) + grbd.xmax * pmin;
var xmax = grbd.xmin * (1 - pmax) + grbd.xmax * pmax;
for (var i = xmin; i < xmax; i += 30) {
const pmin = Math.random() * 0.5;
const pmax = Math.random() * 0.5 + 0.5;
const xmin = grbd.xmin * (1 - pmin) + grbd.xmax * pmin;
const xmax = grbd.xmin * (1 - pmax) + grbd.xmax * pmax;

for (let i = xmin; i < xmax; i += 30) {
canv += tree05(xoff + i + 20 * normRand(-1, 1), yoff + (grbd.ymin + grbd.ymax) / 2 + 20, {
alto: 100 + Math.random() * 200,
});
}
for (var j = 0; j < Math.random() * 4; j++) {
if (canv.includes('NaN')) console.log(canv);
for (let j = 0; j < Math.random() * 4; j++) {
canv += roca(
xoff + normRand(grbd.xmin, grbd.xmax),
yoff + (grbd.ymin + grbd.ymax) / 2 + normRand(-5, 5) + 20,
Expand All @@ -227,12 +236,13 @@ export function flatDec(xoff, yoff, grbd) {
}
);
}
if (canv.includes('NaN')) console.log(canv);
} else if (tt == 2) {
for (let i = 0; i < +randChoice([1, 1, 1, 1, 2, 2, 3]); i++) {
const xr = normRand(grbd.xmin, grbd.xmax);
const yr = (grbd.ymin + grbd.ymax) / 2;
canv += tree04(xoff + xr, yoff + yr + 20, {});

if (canv.includes('NaN')) console.log(canv);
for (let j = 0; j < Math.random() * 2; j++) {
canv += roca(
xoff + Math.max(grbd.xmin, Math.min(grbd.xmax, xr + normRand(-50, 50))),
Expand All @@ -246,12 +256,14 @@ export function flatDec(xoff, yoff, grbd) {
);
}
}
if (canv.includes('NaN')) console.log(canv);
} else if (tt == 3) {
for (let i = 0; i < +randChoice([1, 1, 1, 1, 2, 2, 3]); i++) {
canv += tree06(xoff + normRand(grbd.xmin, grbd.xmax), yoff + (grbd.ymin + grbd.ymax) / 2, {
alto: 60 + Math.random() * 60,
});
}
if (canv.includes('NaN')) console.log(canv);
} else if (tt == 4) {
const pmin = Math.random() * 0.5;
const pmax = Math.random() * 0.5 + 0.5;
Expand All @@ -263,11 +275,11 @@ export function flatDec(xoff, yoff, grbd) {
});
}
}

if (canv.includes('NaN')) console.log(canv);
for (let i = 0; i < 50 * Math.random(); i++) {
canv += tree02(xoff + normRand(grbd.xmin, grbd.xmax), yoff + normRand(grbd.ymin, grbd.ymax));
}

if (canv.includes('NaN')) console.log(canv);
const ts = randChoice([0, 0, 0, 0, 1]);
if (ts == 1 && tt != 4) {
canv += arch01(xoff + normRand(grbd.xmin, grbd.xmax), yoff + (grbd.ymin + grbd.ymax) / 2 + 20, Math.random(), {
Expand All @@ -276,6 +288,6 @@ export function flatDec(xoff, yoff, grbd) {
per: Math.random(),
});
}

if (canv.includes('NaN')) console.log(canv);
return canv;
}
4 changes: 2 additions & 2 deletions src/componentes/Tree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ArgsArbol1, ArgsArbol2, ArgsArbol3, ArgsTwig } from '@/tipos';
import { blob, div, stroke } from '@/utilidades/cosas';
import { noise } from '@/utilidades/Perlin';
import { midPt, triangulate } from '@/utilidades/Polytools';
import { centro, triangulate } from '@/utilidades/Polytools';
import { distance, loopNoise, normRand, poly, randChoice, randGaussian } from '@/utilidades/Util';

export function tree01(x: number, y: number, args: ArgsArbol1) {
Expand Down Expand Up @@ -719,7 +719,7 @@ export function tree07(x, y, args) {
}).concat(T);

for (var k = 0; k < T.length; k++) {
var m = midPt(T[k]);
var m = centro(T[k]);
var c = (noise(m[0] * 0.02, m[1] * 0.02) * 200 + 50) | 0;
var co = 'rgba(' + c + ',' + c + ',' + c + ',0.8)';
canv += poly(T[k], { fil: co, str: co, ancho: 0 });
Expand Down
10 changes: 5 additions & 5 deletions src/componentes/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function toggleText(id: string, a: string, b: string) {
const elemento = document.getElementById(id);

if (elemento) {
var v = elemento.innerHTML;
const v = elemento.innerHTML;
elemento.innerHTML = v == '' || v == b ? a : b;
}
}

var lastScrollX = 0;
var pFrame = 0;
let lastScrollX = 0;
let pFrame = 0;

export function present() {
const currScrollX = window.scrollX;
Expand All @@ -36,8 +36,8 @@ export function present() {
}
}

export function reloadWSeed(s) {
export function reloadWSeed(s: number) {
const u = window.location.href.split('?')[0];
window.location.href = u + '?seed=' + s;
window.location.href = `${u}?seed=${s}`;
//window.location.reload(true)
}
Loading

0 comments on commit 3be61fe

Please sign in to comment.