Algoritmo RufoWow Cíclico
Como programar un movimiento circular
How do you can program a circle movement
Es importante conocer que la posicion de X y de Y de un punto dependera de las funciones trigonometricas sin() para la X, y cos() para la Y.
It is important to know that the position of X and Y of a point will depend on the trigonometric functions sin() for the X, and cos() for the Y.
Igualmente en cualquier movimiento orbital poseeremos las siguientes partes:
- Centro o punto central de giro.
- Sin() o Cos() del angulo multiplicado por un numero que nos devolvera la frecuencia del angulo, lo cual se traducira en la velocidad de giro.
- Radio de la orbitacion: Si ambos radios son iguales dará como resultado una orbitacion circular, pero si son distintos sera una orbitacion eliptica pudiendo ser una elipse vertical (si el radio de orbitacion de la X es menor que el radio de orbitacion de la Y); o vertical (si el radio de orbitacion de la Y es mayor que el de la X).
Likewise, in any orbital movement we will have the following parts:
- Center or central point of rotation.
- Sin() or Cos() of the angle multiplied by a number that will return the frequency of the angle, which will translate into the rotation speed.
- Radius of the orbit: If both radii are equal, it will result in a circular orbit, but if they are different it will be an elliptical orbit and may be a vertical ellipse (if the orbit radius of the X is less than the orbit radius of the Y ); or vertical (if the orbit radius of the Y is greater than that of the X).
Segun todo esto, los siguientes codigos documentan lo descrito anteriormente:
x=centroX+ sin(frameCount*VelocidadX)*radioOrbitacionX
y=centroY+ sin(frameCount*VelocidadY)*radioOrbitacionY
According to all this, the following codes document what was described above:
x=centerX+ sin(frameCount*VelocityX)*radiusOrbitationX
y=centerY+ sin(frameCount*VelocityY)*radiusOrbitationY
CÓDIGO
//(C)Sergio Salazar Latorre
//Algoritmo RufoWow Cíclico
let l = 600
let a = 0
let ctx = l/2
let cty = l/2
let RW = [0.1, 0,2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
let vtx = 1
let vty = 0.9
let rtx = (l/2)*5/8
let rty = (l/2)*5/8
let br=50
let bv=1
let bb=128
let sr = 255 - br
let sv = 255 - bv
let sb = 255 - bb
let inc = 1
function setup() {
createCanvas(l,l);
background(br,bv,bb);
angleMode(DEGREES)
}
function draw() {
push()
background(br,bv,bb,10)
strokeWeight(2)
stroke(sr,sv,sb)
ctx = l/2 + sin(frameCount*vtx)*rtx
cty = l/2 + cos(frameCount*vty)*rty
translate(ctx,cty)
rotate(a)
line(-200,0, 200,0)
a+=inc
bv = (bv+0.4)%255
sv=255-bv
bb = (bb+0.4)%255
sb=255-bb
pop()
Firma()
}
function Firma(){
push()
fill(255,0,0)
strokeWeight(4)
stroke(255)
text("(C)Sergio Salazar Latorre", 10, l-20)
text("Algoritmo RufoWow Cíclico",10, l-5)
if(frameCount>1000){
vtx = random(RW)
vty = random(RW)
frameCount = 0
}
text("RufoWow " + vtx + " - " + vty, l-150, 20)
pop()
}
Comentarios
Publicar un comentario