-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from LabVS-IM-UNAM/Giovani
Giovani
- Loading branch information
Showing
10 changed files
with
292 additions
and
30 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const VectorX = (centro, angulo, radio) => centro + cos(angulo) * radio; | ||
const VectorY = (centro, angulo, radio) => centro + sin(angulo) * radio; | ||
|
||
function CrearPoligono(numeroVertices = 3, radio = 50, centro = { x: width / 2, y: height / 2 }) { | ||
let anguloCentral = TWO_PI / numeroVertices; | ||
let vertices = []; | ||
for (let i = 0; i < numeroVertices; i++) { | ||
let angulo = anguloCentral * i; | ||
vertices.push({ x: VectorX(centro.x, angulo, radio), y: VectorY(centro.y, angulo, radio) }); | ||
} | ||
return vertices; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
let IMAGEN; | ||
let COLOR_FONDO; | ||
let COLOR_FRACTAL; | ||
let COLOR_BORDE; | ||
|
||
function InicializarColores() { | ||
COLOR_FONDO = color("#ffffff"); | ||
COLOR_FRACTAL = color("#000000"); | ||
COLOR_BORDE = color("#000000"); | ||
|
||
AsignarColores(); | ||
} | ||
|
||
function AsignarColores() { | ||
background(COLOR_FONDO) | ||
fill(COLOR_FRACTAL); | ||
stroke(COLOR_BORDE); | ||
} | ||
|
||
function DibujarPoligono(vertices) { | ||
beginShape(); | ||
for (let vertice of vertices) { | ||
vertex(vertice.x, vertice.y); | ||
} | ||
endShape(CLOSE); | ||
} | ||
function DibujarImagen(vertices, radio = 50, centro = { x: width / 2, y: height / 2 }) { | ||
const WIDTH = 2 * radio; | ||
const HEIGHT = 2 * radio; | ||
|
||
shape = createGraphics(WIDTH, HEIGHT); | ||
|
||
shape.beginShape(); | ||
for (let vertice of vertices) { | ||
shape.vertex(vertice.x - centro.x + radio, vertice.y - centro.y + radio); | ||
} | ||
shape.endShape(CLOSE); | ||
|
||
let imageScaled = createImage(WIDTH, HEIGHT); | ||
imageScaled.copy(IMAGEN, 0, 0, IMAGEN.width, IMAGEN.height, 0, 0, WIDTH, HEIGHT); | ||
imageScaled.mask(shape); | ||
|
||
imageMode(CENTER); | ||
image(imageScaled, centro.x, centro.y); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let NUMERO_VERTICES; | ||
let PROPORCION; | ||
let ZOOM; | ||
let ITERACIONES; | ||
|
||
function preload() { | ||
CreateMetronome(1); | ||
} | ||
function setup() { | ||
createCanvas(windowWidth, windowHeight); | ||
|
||
Input(); | ||
InicializarColores(); | ||
Dibujar(); | ||
|
||
} | ||
|
||
function Dibujar() { | ||
let poligono = CrearPoligono(NUMERO_VERTICES, ZOOM); | ||
|
||
if (IMAGEN) DibujarImagen(poligono, ZOOM); | ||
else DibujarPoligono(poligono); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function Input() { | ||
let sliderNumeroVertices = document.getElementById("numeroVertices"); | ||
let sliderProporcion = document.getElementById("proporcion"); | ||
let sliderZoom = document.getElementById("zoom"); | ||
let sliderIteraciones = document.getElementById("iteraciones"); | ||
|
||
let colorPickerFondo = document.getElementById("colorFondo"); | ||
let colorPickerFractal = document.getElementById("colorFractal"); | ||
let colorPickerBorde = document.getElementById("colorBorde"); | ||
|
||
let boton = document.getElementById("boton") | ||
let inputImagen = select("#imagen"); | ||
|
||
|
||
sliderProporcion.addEventListener("input", function () { | ||
PROPORCION = parseFloat(sliderProporcion.value); | ||
clear(); | ||
|
||
Dibujar(); | ||
}); | ||
sliderZoom.addEventListener("input", function () { | ||
ZOOM = parseFloat(sliderZoom.value); | ||
clear(); | ||
|
||
Dibujar(); | ||
}) | ||
sliderIteraciones.addEventListener("input", function () { | ||
ITERACIONES = parseInt(sliderIteraciones.value); | ||
clear(); | ||
|
||
Dibujar(); | ||
CreateMetronome(ITERACIONES); | ||
}) | ||
sliderNumeroVertices.addEventListener("input", function () { | ||
NUMERO_VERTICES = parseInt(sliderNumeroVertices.value); | ||
clear(); | ||
|
||
Dibujar(); | ||
}) | ||
|
||
colorPickerFondo.addEventListener("input", function () { | ||
COLOR_FONDO = this.value; | ||
clear(); | ||
|
||
AsignarColores(); | ||
Dibujar(); | ||
}) | ||
colorPickerFractal.addEventListener("input", function () { | ||
COLOR_FRACTAL = this.value; | ||
clear(); | ||
|
||
AsignarColores(); | ||
Dibujar(); | ||
}) | ||
colorPickerBorde.addEventListener("input", function () { | ||
COLOR_BORDE = this.value; | ||
clear(); | ||
|
||
AsignarColores(); | ||
Dibujar(); | ||
}) | ||
|
||
inputImagen.elt.addEventListener("change", SubirArchivo); | ||
boton.addEventListener("click", function () { saveCanvas("Fractal") }) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function SubirArchivo(event) { | ||
let file = event.target.files[0]; | ||
if (file && file.type.startsWith("image/")) { | ||
loadImage(URL.createObjectURL(file), (img) => { | ||
IMAGEN = img; | ||
console.log("Imagen cargada correctamente"); | ||
Dibujar(); | ||
}); | ||
} else { | ||
console.log("El archivo no es una imagen"); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.