Sol Banner
Sağ Banner
  • Ekip Arkadaşları Arıyoruz!

    MinecraftTR topluluğunu birlikte büyütmek istiyoruz!
    Aktif ve gönüllü olarak katkı sağlayabilecek Editör, Yazar, Yazar Ekip Lideri, Minecraft Uzmanı, XenForo Developer ve Yönetici rollerinde ekip arkadaşları arıyoruz.

    Yeteneğine güveniyor ve topluluğa katkı sağlamak istiyorsan başvurunu bekliyoruz:

    ✅ Ekip Başvuru Formunu Doldur

ÇİZ KOMUTU (JAVASCRİPT)

Yasin Aksoy

Yeni bir Steve doğdu!
Katılım
30 Ağustos 2020
Mesajlar
10
Tepki puanı
1
Puanları
0
Merhaba, bwn Yasin bugün JavaScript ile "çiz" komutunu göstereceğim. İyi kodlamalar iyi Günler dilerim :)
(Hepsi birleşik olacaktır)

js
const { Canvas } = require("canvas-constructor");

const zoomfactor = 10;
const reactions = ["⬅️", "➡️", "⬆️", "⬇️", "✅", "", "️"];
let channels = [];

module.exports.run = (bot, message, args) => {
if (channels.includes(message.channel.id)) {
message.reply("You can't have more than one Canvas in a channel!");
return;
}
var size;
if (+args[0] >= 5 && +args[0] <= 50) {
size = +args[0];
} else {
message.reply("Boyut 5 ile 50 arasında olmalıdır!");
return;
}
message.channel.send("Yükleniyor...").then((msg) => {
channels.push(message.channel.id);
const drawing = new Drawing(msg, size, args[1], args[2]);
});
};


class Drawing {
constructor(msg, size, fg, bg) {
this.msg = msg;
this.canvasmsg;
this.size = size;
this.realsize = size * zoomfactor;
this.penx = Math.floor(size / 2);
this.peny = this.penx;
this.penstate = false; // true: on, false: off
this.fcolor = fg || "rgb(0, 0, 0)";
this.bcolor = bg || "rgb(255, 255, 255)";

this.initPixels();
this.c = new Canvas(this.realsize, this.realsize).setColor(this.bcolor).addRect(0, 0, this.realsize, this.realsize);
this.drawCanvas();
js
self.stop("\nSebep: Zaman aşımı (2 dakika)");
}, 120000);
}

handleReaction(reaction) {
// console.log(`${reaction.emoji.name} from ${reaction.users.last().username}`);
const rid = reactions.indexOf(reaction.emoji.name);
if (rid < 4) this.movePen(rid);
else if (rid === 4) this.stop();
else this.togglePenstate();
reaction.remove(reaction.users.last()).catch(e => {
if (e.code === 50013) reaction.message.channel.send("Düzgün çalışması için 'Mesajları Yönet' iznine ihtiyacım var!");
});
this.drawCanvas();
}

/*
* 0: Left
* 1: Right
* 2: Up
* 3: Down
*/
movePen(dir) {
const xactions = [-1, 1, 0, 0];
const yactions = [0, 0, -1, 1];
if ((this.penx > 0 || xactions[dir] === 1) && (this.penx < this.size || xactions[dir] === -1)) this.penx += xactions[dir];
if ((this.peny > 0 || yactions[dir] === 1) && (this.peny < this.size || yactions[dir] === -1)) this.peny += yactions[dir];
}

togglePenstate() {
this.penstate = !this.penstate;
if (this.penstate) {
this.msg.reactions.find(val => val.emoji.name === reactions[5]).remove();
this.msg.react(reactions[6]);
} else {
this.msg.reactions.find(val => val.emoji.name === reactions[6]).remove();
this.msg.react(reactions[5]);
}
}

initPixels() {
this.pixels = [];
for (let i = 0; i < Math.pow(this.size, 2); i++) {
this.pixels.push(false);
}
}

setPixel(x, y) {
this.pixels[x + (y * this.size)] = true;
}

setCanvasPixel(x, y, color) {
this.c.setColor(color).addRect(x * zoomfactor, y * zoomfactor, zoomfactor, zoomfactor);
}

drawCanvas(end = false) {
js
if (this.penstate) this.setPixel(this.penx, this.peny);
for (let x = 0; x < this.size; x++) {
for (let y = 0; y < this.size; y++) {
this.setCanvasPixel(x, y, this.pixels[x + (y * this.size)] ? this.fcolor : this.bcolor);
}
}
if (!end) {
this.setCanvasPixel(this.penx, this.peny, this.pixels[this.penx + (this.peny * this.size)] ? "#5A0000" : "red");
this.renewTimeout();
}
this.sendCanvas();
}

async sendCanvas() {
if (this.canvasmsg) this.canvasmsg.delete().catch(e => console.error(e));
this.msg.channel.send(`Canvas: ${this.size}px`, {
files: [
this.c.toBuffer()
]
}).then(msg => {
this.canvasmsg = msg;
});
}

reactArrows(arrow) {
if (arrow === 6) return;

this.msg.react(reactions[arrow]).then(_ => {
this.reactArrows(arrow + 1);
}).catch(
e => console.error(`Reaction Error: ${e}`)
);
}
}

module.exports.conf = {
enabled: true,
guildOnly: false,
aliases: ["rçiz","draw","resimciz"],
permLevel: 0
};

module.exports.help = {
name: "resimçiz",
description: "Resim çizersiniz.",
usage: "resimçiz"
};
Bu kadar iyi Akşamlar iyi kodlamalar :D
 

Sabinushka

Seçkin madenci.
Katılım
30 Mart 2019
Mesajlar
121
Tepki puanı
21
Puanları
1,185
Yaş
21
Güzel Konu Olmuş Bunu Eclipse üzerinden giriyoruz değil mi kodları yanlış bilmiyorsam ?
 

Üst Alt