SlideShare a Scribd company logo
1 of 6
Download to read offline
I need to create a page that looks like the picture. The problem with my code is that my smile faces looks different from the example(the angle of the faces). And When you enter the negative value and value that does fit the canvas, there should be an alert message but it only alerts when I enter a negative value.
First pic is the example
Second pic is mine.
My Html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="a8.js" defer></script>
<title>Assignment 8</title>
</head>
<body>
<div>
<h1>CPSC 1045 Assignment - Smiley Rotator</h1>
<P>Enter a number of smiles to draw <input id="number" type="text"></P>
<p>Enter how far from the center of the canvas to draw them <input id="center" type="text"></p>
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;display: block;">
</canvas>
<button id="draw">Draw</button>
</div>
</body>
</html>
My Js
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
function drawSmile(x, y) {
// smile face
ctx.fillStyle = "yellow";
ctx.beginPath();
ctx.arc(x, y, 75, 0, 2 * Math.PI);
ctx.stroke();
ctx.fill();
ctx.fillStyle = "black";
ctx.beginPath();
ctx.arc(x - 20, y - 30, 15, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(x + 20, y - 30, 15, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(x, y + 5, 50, 0, Math.PI);
ctx.stroke();
}
function draw() {
var number = parseInt(document.getElementById("number").value);
var center = parseInt(document.getElementById("center").value);
if (isNaN(number) || isNaN(center) || number <= 0 || center <= 0) {
alert("You entered an invalid value.");
return;
}
ctx.clearRect(0, 0, c.width, c.height);
var centerX = c.width / 2;
var centerY = c.height / 2;
var angleIncrement = 2 * Math.PI / number;
for (var i = 0; i < number; i++) {
var angle = i * angleIncrement;
var smileX = centerX + center * Math.cos(angle);
var smileY = centerY + center * Math.sin(angle);
drawSmile(smileX, smileY);
}
}
document.getElementById("draw").addEventListener('click', draw);
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
function drawSmile(x, y) {
// smile face
ctx.fillStyle = "yellow";
ctx.beginPath();
ctx.arc(x, y, 75, 0, 2 * Math.PI);
ctx.stroke();
ctx.fill();
ctx.fillStyle = "black";
ctx.beginPath();
ctx.arc(x - 20, y - 30, 15, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(x + 20, y - 30, 15, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(x, y + 5, 50, 0, Math.PI);
ctx.stroke();
}
function draw() {
var number = parseInt(document.getElementById("number").value);
var center = parseInt(document.getElementById("center").value);
if (isNaN(number) || isNaN(center) || number <= 0 || center <= 0) {
alert("You entered an invalid value.");
return;
}
ctx.clearRect(0, 0, c.width, c.height);
var centerX = c.width / 2;
var centerY = c.height / 2;
var angleIncrement = 2 * Math.PI / number;
for (var i = 0; i < number; i++) {
var angle = i * angleIncrement;
var smileX = centerX + center * Math.cos(angle);
var smileY = centerY + center * Math.sin(angle);
drawSmile(smileX, smileY);
}
}
document.getElementById("draw").addEventListener('click', draw);
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
function drawSmile(x, y) {
// smile face
ctx.fillStyle = "yellow";
ctx.beginPath();
ctx.arc(x, y, 75, 0, 2 * Math.PI);
ctx.stroke();
ctx.fill();
ctx.fillStyle = "black";
ctx.beginPath();
ctx.arc(x - 20, y - 30, 15, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(x + 20, y - 30, 15, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.arc(x, y + 5, 50, 0, Math.PI);
ctx.stroke();
}
function draw() {
var number = parseInt(document.getElementById("number").value);
var center = parseInt(document.getElementById("center").value);
if (isNaN(number) || isNaN(center) || number <= 0 || center <= 0) {
alert("You entered an invalid value.");
return;
}
ctx.clearRect(0, 0, c.width, c.height);
var centerX = c.width / 2;
var centerY = c.height / 2;
var angleIncrement = 2 * Math.PI / number;
for (var i = 0; i < number; i++) {
var angle = i * angleIncrement;
var smileX = centerX + center * Math.cos(angle);
var smileY = centerY + center * Math.sin(angle);
drawSmile(smileX, smileY);
}
}
document.getElementById("draw").addEventListener('click', draw);
Enter a number of smiles to draw Enter a number of smiles to drav Enter how far from the center
of the canvas to draw them Enter how far from the center of the canvas to draw them CPSC 1045
A SGignn This page says You entered an invalid value. Enter a number of smiles to draw Enter
how far from the center of the canvas to uraw urmeruvoEnter a number of smiles to draw Enter
how far from the center of the canvas to draw them

More Related Content

Similar to I need to create a page that looks like the picture The pro.pdf

Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Salar Delavar Qashqai
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video gamedandylion13
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
analog clock C#
analog clock C#analog clock C#
analog clock C#omeed
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxTasnimSaimaRaita
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdfAssignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdfSamiulHaque58
 
Version1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docx
Version1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docxVersion1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docx
Version1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docxtienboileau
 
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingNonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingSalar Delavar Qashqai
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfshehabhamad_90
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvassuitzero
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Dr. Loganathan R
 

Similar to I need to create a page that looks like the picture The pro.pdf (20)

Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Statistics.cpp
Statistics.cppStatistics.cpp
Statistics.cpp
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
analog clock C#
analog clock C#analog clock C#
analog clock C#
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptx
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdfAssignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
 
Version1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docx
Version1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docxVersion1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docx
Version1.0 StartHTML000000232 EndHTML000065057 StartFragment0000.docx
 
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingNonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programming
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvas
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 

More from adianantsolutions

Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdfNancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdfadianantsolutions
 
Name this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdfName this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdfadianantsolutions
 
Name of Bacteria Observation Results E coli Yellow s.pdf
Name of Bacteria    Observation    Results  E coli Yellow s.pdfName of Bacteria    Observation    Results  E coli Yellow s.pdf
Name of Bacteria Observation Results E coli Yellow s.pdfadianantsolutions
 
Nasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdfNasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdfadianantsolutions
 
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdfMutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdfadianantsolutions
 
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdfMuthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdfadianantsolutions
 
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdfNadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdfadianantsolutions
 
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
NAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdfNAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdf
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdfadianantsolutions
 
Multi choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdfMulti choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdfadianantsolutions
 
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdfn2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdfadianantsolutions
 
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdfn Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdfadianantsolutions
 
Myra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdfMyra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdfadianantsolutions
 
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdfMycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdfadianantsolutions
 
My library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdfMy library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdfadianantsolutions
 
My code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfMy code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfadianantsolutions
 
My essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdfMy essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdfadianantsolutions
 
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdfMsrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdfadianantsolutions
 
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdfMRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdfadianantsolutions
 
Mr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdfMr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdfadianantsolutions
 
Multiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdfMultiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdfadianantsolutions
 

More from adianantsolutions (20)

Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdfNancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
 
Name this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdfName this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdf
 
Name of Bacteria Observation Results E coli Yellow s.pdf
Name of Bacteria    Observation    Results  E coli Yellow s.pdfName of Bacteria    Observation    Results  E coli Yellow s.pdf
Name of Bacteria Observation Results E coli Yellow s.pdf
 
Nasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdfNasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdf
 
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdfMutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
 
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdfMuthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
 
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdfNadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
 
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
NAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdfNAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdf
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
 
Multi choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdfMulti choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdf
 
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdfn2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
 
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdfn Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
 
Myra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdfMyra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdf
 
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdfMycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
 
My library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdfMy library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdf
 
My code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfMy code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdf
 
My essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdfMy essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdf
 
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdfMsrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
 
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdfMRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
 
Mr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdfMr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdf
 
Multiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdfMultiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdf
 

Recently uploaded

Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Dr. Mazin Mohamed alkathiri
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

I need to create a page that looks like the picture The pro.pdf

  • 1. I need to create a page that looks like the picture. The problem with my code is that my smile faces looks different from the example(the angle of the faces). And When you enter the negative value and value that does fit the canvas, there should be an alert message but it only alerts when I enter a negative value. First pic is the example Second pic is mine. My Html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="a8.js" defer></script> <title>Assignment 8</title> </head> <body> <div> <h1>CPSC 1045 Assignment - Smiley Rotator</h1> <P>Enter a number of smiles to draw <input id="number" type="text"></P> <p>Enter how far from the center of the canvas to draw them <input id="center" type="text"></p> <canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;display: block;">
  • 2. </canvas> <button id="draw">Draw</button> </div> </body> </html> My Js var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); function drawSmile(x, y) { // smile face ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.arc(x, y, 75, 0, 2 * Math.PI); ctx.stroke(); ctx.fill(); ctx.fillStyle = "black"; ctx.beginPath(); ctx.arc(x - 20, y - 30, 15, 0, 2 * Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(x + 20, y - 30, 15, 0, 2 * Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(x, y + 5, 50, 0, Math.PI); ctx.stroke(); } function draw() { var number = parseInt(document.getElementById("number").value); var center = parseInt(document.getElementById("center").value);
  • 3. if (isNaN(number) || isNaN(center) || number <= 0 || center <= 0) { alert("You entered an invalid value."); return; } ctx.clearRect(0, 0, c.width, c.height); var centerX = c.width / 2; var centerY = c.height / 2; var angleIncrement = 2 * Math.PI / number; for (var i = 0; i < number; i++) { var angle = i * angleIncrement; var smileX = centerX + center * Math.cos(angle); var smileY = centerY + center * Math.sin(angle); drawSmile(smileX, smileY); } } document.getElementById("draw").addEventListener('click', draw); var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); function drawSmile(x, y) { // smile face ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.arc(x, y, 75, 0, 2 * Math.PI); ctx.stroke(); ctx.fill(); ctx.fillStyle = "black"; ctx.beginPath(); ctx.arc(x - 20, y - 30, 15, 0, 2 * Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(x + 20, y - 30, 15, 0, 2 * Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(x, y + 5, 50, 0, Math.PI);
  • 4. ctx.stroke(); } function draw() { var number = parseInt(document.getElementById("number").value); var center = parseInt(document.getElementById("center").value); if (isNaN(number) || isNaN(center) || number <= 0 || center <= 0) { alert("You entered an invalid value."); return; } ctx.clearRect(0, 0, c.width, c.height); var centerX = c.width / 2; var centerY = c.height / 2; var angleIncrement = 2 * Math.PI / number; for (var i = 0; i < number; i++) { var angle = i * angleIncrement; var smileX = centerX + center * Math.cos(angle); var smileY = centerY + center * Math.sin(angle); drawSmile(smileX, smileY); } } document.getElementById("draw").addEventListener('click', draw); var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); function drawSmile(x, y) { // smile face ctx.fillStyle = "yellow"; ctx.beginPath(); ctx.arc(x, y, 75, 0, 2 * Math.PI); ctx.stroke();
  • 5. ctx.fill(); ctx.fillStyle = "black"; ctx.beginPath(); ctx.arc(x - 20, y - 30, 15, 0, 2 * Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(x + 20, y - 30, 15, 0, 2 * Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(x, y + 5, 50, 0, Math.PI); ctx.stroke(); } function draw() { var number = parseInt(document.getElementById("number").value); var center = parseInt(document.getElementById("center").value); if (isNaN(number) || isNaN(center) || number <= 0 || center <= 0) { alert("You entered an invalid value."); return; } ctx.clearRect(0, 0, c.width, c.height); var centerX = c.width / 2;
  • 6. var centerY = c.height / 2; var angleIncrement = 2 * Math.PI / number; for (var i = 0; i < number; i++) { var angle = i * angleIncrement; var smileX = centerX + center * Math.cos(angle); var smileY = centerY + center * Math.sin(angle); drawSmile(smileX, smileY); } } document.getElementById("draw").addEventListener('click', draw); Enter a number of smiles to draw Enter a number of smiles to drav Enter how far from the center of the canvas to draw them Enter how far from the center of the canvas to draw them CPSC 1045 A SGignn This page says You entered an invalid value. Enter a number of smiles to draw Enter how far from the center of the canvas to uraw urmeruvoEnter a number of smiles to draw Enter how far from the center of the canvas to draw them