Imports useful elements, and assigns them to variables var canvas = document getElementById



Download 13,65 Kb.
Sana14.04.2022
Hajmi13,65 Kb.
#552202
Bog'liq
2 JAVA SCRIP


//imports useful elements, and assigns them to variables
var canvas = document.getElementById("pixelCanvas");
var color = document.getElementById("colorPicker");
var sizePicker = document.getElementById("sizePicker");
var height = document.getElementById("inputHeight");
var width = document.getElementById("inputWidth");
var toggle = document.getElementById("gridToggle");
var save = document.getElementById("saveArt");

//function to create grid and assign event listeners to all cells on creation


function makeGrid(height, width) {
for (let y = 0; y < height; y++) {
let row = canvas.insertRow(y);
for (let x = 0; x < width; x++) {
let cell = row.insertCell(x);
cell.addEventListener("mousedown", function(evt) {
cell.style.backgroundColor = color.value;
cell.addEventListener("contextmenu", function(evt) {
evt.preventDefault();
cell.style.backgroundColor = "white";
} )
} )
}
}
}

//function to toggle on/off grid within the design canvas


toggle.addEventListener("click", function() {
var elementsTd = document.getElementsByTagName("td");
var elementsTr = document.getElementsByTagName("tr");
for (var i=0; ielementsTd[i].classList.toggle("off");
}
for (var j=0; jelementsTr[j].classList.toggle("off");
}
});
//function that uses the size picker submit to call makeGrid() funtion
sizePicker.addEventListener("submit", function(evt) {
evt.preventDefault();
while (canvas.hasChildNodes()) {
canvas.removeChild(canvas.lastChild);
}
makeGrid(height.value, width.value);
});

//function that saves the art as canvas


save.addEventListener("click", function(evt) {
evt.preventDefault();
html2canvas(canvas).then(canvas => {
document.body.appendChild(canvas)
});
});
Download 13,65 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish