javascript den anlayanlar bakabilirmi (kolay bişeydir sanırım)

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

GrahambeLL

Koydum Çalışma Masasını
Katılım
21 Mart 2017
Mesajlar
72
Elmaslar
4
Puan
0
Yaş
24
Kod bu:
Kod:
var smoothA = [];
var smoothB = [];
var smoothC = [];
var barSmooth = [];
var audioSample = [];
var particles = {};
var particleIndex = 0;
var particleNum = 2;
var bgImg = new Image();
var barColor = '#000';
var circleColor = '#000';
var particleColor = '#000';
var barSize = 1;

for (var i = 0; i < 128; i++) {
    smoothA[i] = 0;
    smoothB[i] = 0;
    smoothC[i] = 0;
    barSmooth[i] = 0;
    audioSample[i] = 0;
}

window.wallpaperPropertyListener = {
    applyUserProperties: function (properties) {
        if(properties.theme){
            if(properties.theme.value === 1){
                barColor = '#fff';
                circleColor = '#fff';
                particleColor = '#fff';
                barSize = 1;
                bgImg.src = "space.jpg";
            }
            if (properties.theme.value === 0){
                barColor = '#000';
                circleColor = '#000';
                particleColor = '#000';
                barSize = 1;
                bgImg.src = 'file:///';
            }
        }

        if (properties.customimage) {
            bgImg.src = 'file:///' + properties.customimage.value;
        }
        
        if (properties.barcolor) {
            var a = properties.barcolor.value.split(' ');
            a = a.map(function (c) {
                return Math.ceil(c * 255);
            });
            barColor = 'rgb(' + a.join() + ')';
        }
        if (properties.circlecolor) {
            var a = properties.circlecolor.value.split(' ');
            a = a.map(function (c) {
                return Math.ceil(c * 255);
            });
            circleColor = 'rgb(' + a.join() + ')';
        }
        if (properties.particlecolor) {
            var a = properties.particlecolor.value.split(' ');
            a = a.map(function (c) {
                return Math.ceil(c * 255);
            });
            particleColor = 'rgb(' + a.join() + ')';
        }
        
        if (properties.barsize){
            barSize = properties.barsize.value;
        }
        
    }
};

function wallpaperAudioListener(audioArray) {

    for(var i = 0; i < 64;i++){
        smoothA[i] = smoothB[i];
        smoothB[i] = smoothC[i];
        if(audioArray[i]>1){
            audioArray[i] = 1;
        }
        smoothC[i] = audioArray[i];
        barSmooth[i] = (smoothA[i] + smoothB[i] + smoothC[i]) / 3;
        barSmooth[64+i]= barSmooth[i];
    }
    audioSample = barSmooth;
}

function run(){

    window.requestAnimationFrame(run);

    var x = canvas.width/2;
    var y = canvas.height/2;
    var r = 0;
    var radian= 0;
    var num = 0;
    var i = 0;
    var avg = (audioSample[0] + audioSample[1] + audioSample[2]) * 10 + 1;
    
    var maxHeight = 500;
    var minHeight = 100 + avg;
    var radius = 86 + avg;
    ctx.clearRect(0, 0, canvas.height, canvas.width);
    
    if (bgImg.src != 'file:///null' && bgImg.src != 'file:///' && bgImg.src !=

'file:///undefined') {
        ctx.drawImage(bgImg, 0, 0, canvas.width, canvas.height);
    }
    else{
        ctx.beginPath();
        ctx.rect(0, 0, canvas.width, canvas.height);
        ctx.fillStyle = "white";
        ctx.fill();
    }
    
    for(var degree = 45; degree < 405; degree = degree + 2.8125){
        
        var radian = degree * Math.PI/180;
        var minRX= minHeight * Math.cos(radian);
        var minRY= minHeight * Math.sin(radian);

        var maxRX = maxHeight * Math.cos(radian);
        var maxRY = maxHeight * Math.sin(radian);

        var barSampleX = maxRX * audioSample[i];
        var barSampleY = maxRY * audioSample[i];
        
        ctx.beginPath();
        ctx.moveTo(x + minRX, y + minRY);
        ctx.lineTo(x + minRX + barSampleX, y + minRY + barSampleY);
        ctx.strokeStyle = barColor;
        ctx.lineWidth = barSize;
        ctx.stroke();
        i++;
    }

    Particle.prototype.draw = function(){
        this.x += this.vx;
        this.y += this.vy;
        this.life++;

        
        if(this.life >= this.maxLife){
            delete particles[this.id];
        }

        ctx.beginPath();
        ctx.arc(this.x , this.y, this.radius, 0, 2 * Math.PI);
        ctx.fillStyle = particleColor;
        ctx.fill();

        this.radius = this.radius * 1.0019;
        if(((audioSample[0] + audioSample[1] + audioSample[2] + audioSample[3] +

audioSample[4])) > 0.60){
            this.vx = this.vx * 1.111;
            this.vy = this.vy * 1.111;
            this.life = this.life + 4;
        }else if(((audioSample[29] + audioSample[30] + audioSample[31] +

audioSample[32] + audioSample[33]) ) > 0.5){
            this.vx = this.vx * 1.0177;
            this.vy = this.vy * 1.0177;
            this.life = this.life + 2;
        }else{
            this.vx = this.vx * 1.0059;
            this.vy = this.vy * 1.0059;
        }
    }
    function Particle(){
        this.y = Math.random() * canvas.height;
        this.x = Math.random() * canvas.width;
        this.radius = Math.random() * 2;
        this.vx = 0;
        this.vy = 0;

        this.radians = Math.atan((canvas.height/2-this.y)/(canvas.width/2-this.x));
        this.vx = 1.5 * Math.cos(this.radians);
        this.vy = 1.5 * Math.sin(this.radians);

        if(this.x < canvas.width/2){
            this.vx = -this.vx;
            this.vy = -this.vy;
        }

        particleIndex++;
        particles[particleIndex] = this;
        this.id = particleIndex;
        this.life = 0;
        this.maxLife = 300;
    }

    for (var i = 0; i < particleNum; i++){
        new Particle();
    }
    
    for (var i in particles){
        particles[i].draw();
    }

    ctx.beginPath();
    ctx.arc(x, y, radius, 0, Math.PI * 2);
    ctx.fillStyle = circleColor;
    ctx.fill();
}


window.onload = function(){
    canvas = document.querySelector("[HASHTAG]#canvas[/HASHTAG]");
    ctx = canvas.getContext("2d");
    canvas.width = canvas.scrollWidth;
    canvas.height = canvas.scrollHeight;
    
    window.wallpaperRegisterAudioListener(wallpaperAudioListener);
    window.requestAnimationFrame(run);
}

window.onresize = function() {
    location.reload();
}[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]


Bu kodda şu ortaya çıkıyor ve sese göre hareket ediyor

Kodu ben yazmadıgım için ve javascript den anlamadıgım için (sıfırdan yazacak kadar) kendi yöntemim ile yapmaya çalıştıgımda kod bozuluyodu 4-5 kere farklı şekilde denedim yapamadım şimdi size soruyorum

Ortadaki zımbırtıları beş adet yapabilirmisiniz? konumlarını ben ayarlarım :)
[DOUBLEPOST=1495312594,1495312559][/DOUBLEPOST]resim server tarafından işlenememiş daha az bir alanı kapsıyarak tekrar çekiyorum
 
Bu forumda bilen biri olduğunu sanmıyorum
 
basit bir dil aslında peki index.html dosyasından bunu 5 kere çagırsam olmazmı?[DOUBLEPOST=1495363509,1495363291][/DOUBLEPOST]denedim ve işlemci 4 çekirdek 2 çekirdek atamıştım %50 den aşşagıya düşmedi ve çalışmadı[DOUBLEPOST=1495381490][/DOUBLEPOST]
upload_2017-5-21_18-44-42.png
 
basit bir dil aslında peki index.html dosyasından bunu 5 kere çagırsam olmazmı?
Orada zaten senin kutu dediğin şeyler yazıyor onları kendince kopyala altına yapıştır.

Örnek:
Kod:
var smoothA = [];
var smoothB = [];
var smoothC = [];
var barSmooth = [];
var audioSample = [];
var particles = {};
var particleIndex = 0;
var particleNum = 2;
var bgImg = new Image();
var barColor = '#000';
var circleColor = '#000';
var particleColor = '#000';
var barSize = 1;

for (var i = 0; i < 128; i++) {
    smoothA = 0;
    smoothB = 0;
    smoothC = 0;
    barSmooth = 0;
    audioSample = 0;
}

window.wallpaperPropertyListener = {
    applyUserProperties: function (properties) {
        if(properties.theme){
            if(properties.theme.value === 1){
                barColor = '#fff';
                circleColor = '#fff';
                particleColor = '#fff';
                barSize = 1;
                bgImg.src = "space.jpg";
            }
            if (properties.theme.value === 0){
                barColor = '#000';
                circleColor = '#000';
                particleColor = '#000';
                barSize = 1;
                bgImg.src = 'file:///';
            }
        }

        if (properties.customimage) {
            bgImg.src = 'file:///' + properties.customimage.value;
        }
        
        if (properties.barcolor) {
            var a = properties.barcolor.value.split(' ');
            a = a.map(function (c) {
                return Math.ceil(c * 255);
            });
            barColor = 'rgb(' + a.join() + ')';
        }
        if (properties.circlecolor) {
            var a = properties.circlecolor.value.split(' ');
            a = a.map(function (c) {
                return Math.ceil(c * 255);
            });
            circleColor = 'rgb(' + a.join() + ')';
        }
        if (properties.particlecolor) {
            var a = properties.particlecolor.value.split(' ');
            a = a.map(function (c) {
                return Math.ceil(c * 255);
            });
            particleColor = 'rgb(' + a.join() + ')';
        }
        
        if (properties.barsize){
            barSize = properties.barsize.value;
        }
        
    }
};

function wallpaperAudioListener(audioArray) {

    for(var i = 0; i < 64;i++){
        smoothA = smoothB;
        smoothB = smoothC;
        if(audioArray>1){
            audioArray = 1;
        }
        smoothC = audioArray;
        barSmooth = (smoothA + smoothB + smoothC) / 3;
        barSmooth[64+i]= barSmooth;
    }
    audioSample = barSmooth;
}

function run(){

    window.requestAnimationFrame(run);

    var x = canvas.width/2;
    var y = canvas.height/2;
    var r = 0;
    var radian= 0;
    var num = 0;
    var i = 0;
    var avg = (audioSample[0] + audioSample[1] + audioSample[2]) * 10 + 1;
    
    var maxHeight = 500;
    var minHeight = 100 + avg;
    var radius = 86 + avg;
    ctx.clearRect(0, 0, canvas.height, canvas.width);
    
    if (bgImg.src != 'file:///null' && bgImg.src != 'file:///' && bgImg.src !=

'file:///undefined') {
        ctx.drawImage(bgImg, 0, 0, canvas.width, canvas.height);
    }
    else{
        ctx.beginPath();
        ctx.rect(0, 0, canvas.width, canvas.height);
        ctx.fillStyle = "white";
        ctx.fill();
    }
    
    for(var degree = 45; degree < 405; degree = degree + 2.8125){
        
        var radian = degree * Math.PI/180;
        var minRX= minHeight * Math.cos(radian);
        var minRY= minHeight * Math.sin(radian);

        var maxRX = maxHeight * Math.cos(radian);
        var maxRY = maxHeight * Math.sin(radian);

        var barSampleX = maxRX * audioSample;
        var barSampleY = maxRY * audioSample[i];
        
        ctx.beginPath();
        ctx.moveTo(x + minRX, y + minRY);
        ctx.lineTo(x + minRX + barSampleX, y + minRY + barSampleY);
        ctx.strokeStyle = barColor;
        ctx.lineWidth = barSize;
        ctx.stroke();
        i++;
    }

    Particle.prototype.draw = function(){
        this.x += this.vx;
        this.y += this.vy;
        this.life++;

        
        if(this.life >= this.maxLife){
            delete particles[this.id];
        }

        ctx.beginPath();
        ctx.arc(this.x , this.y, this.radius, 0, 2 * Math.PI);
        ctx.fillStyle = particleColor;
        ctx.fill();

        this.radius = this.radius * 1.0019;
        if(((audioSample[0] + audioSample[1] + audioSample[2] + audioSample[3] +

audioSample[4])) > 0.60){
            this.vx = this.vx * 1.111;
            this.vy = this.vy * 1.111;
            this.life = this.life + 4;
        }else if(((audioSample[29] + audioSample[30] + audioSample[31] +

audioSample[32] + audioSample[33]) ) > 0.5){
            this.vx = this.vx * 1.0177;
            this.vy = this.vy * 1.0177;
            this.life = this.life + 2;
        }else{
            this.vx = this.vx * 1.0059;
            this.vy = this.vy * 1.0059;
        }
    }
    function Particle(){
        this.y = Math.random() * canvas.height;
        this.x = Math.random() * canvas.width;
        this.radius = Math.random() * 2;
        this.vx = 0;
        this.vy = 0;

        this.radians = Math.atan((canvas.height/2-this.y)/(canvas.width/2-this.x));
        this.vx = 1.5 * Math.cos(this.radians);
        this.vy = 1.5 * Math.sin(this.radians);

        if(this.x < canvas.width/2){
            this.vx = -this.vx;
            this.vy = -this.vy;
        }

        particleIndex++;
        particles[particleIndex] = this;
        this.id = particleIndex;
        this.life = 0;
        this.maxLife = 300;
    }

    for (var i = 0; i < particleNum; i++){
        new Particle();
    }
    
    for (var i in particles){
        particles[i].draw();
    }

    ctx.beginPath();
    ctx.arc(x, y, radius, 0, Math.PI * 2);
    ctx.fillStyle = circleColor;
    ctx.fill();
}


window.onload = function(){
    canvas = document.querySelector("[HASHTAG]#canvas[/HASHTAG]");
    ctx = canvas.getContext("2d");
    canvas.width = canvas.scrollWidth;
    canvas.height = canvas.scrollHeight;
    
    window.wallpaperRegisterAudioListener(wallpaperAudioListener);
    window.requestAnimationFrame(run);
}

window.onresize = function() {
    location.reload();
}[/i][/i]

Bu kodlar ama hatalı,Hatalı olan kısım şu [] buda demek oluyo ki ses ve eşyalar sadece bu kodla bağdaştırılmış.Sese gelince ise değiştirilmesi için kodun baştan yazılması gerekir.[DOUBLEPOST=1496979928,1496979850][/DOUBLEPOST]
Bu forumda bilen biri olduğunu sanmıyorum
:D kim demiş[DOUBLEPOST=1496979979][/DOUBLEPOST]Haa bu arada o smoth gibi kodları alt alta artırarak o dediğin şeyin çoğaldığını görürsün
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

Hala Discord sunucumuza katılmadın mı?

Büyük bir topluluğun parçası ol, etkinliklere katıl ve özel hediyeler kazanma şansı yakala!

Şimdi Katıl
Üst