admin管理员组文章数量:1404927
I tried to create an SimpleImage
using JavaScript. But it gives me a console error as
Uncaught ReferenceError: SimpleImage is not defined
I am unsure where the issue is ing from with the code below:
<script>
var img = new SimpleImage(200, 200);
for (var p of img.values()){
x = p.getX();
y = p.getY();
w = img.getWidth()
if (x > y){
p.setRed(255);
}
if (x + y > w)
{
p.setRed(255);
}
if (x > 20){
p.setRed(255);
}
}
print (img);
</script>
I tried to create an SimpleImage
using JavaScript. But it gives me a console error as
Uncaught ReferenceError: SimpleImage is not defined
I am unsure where the issue is ing from with the code below:
<script>
var img = new SimpleImage(200, 200);
for (var p of img.values()){
x = p.getX();
y = p.getY();
w = img.getWidth()
if (x > y){
p.setRed(255);
}
if (x + y > w)
{
p.setRed(255);
}
if (x > 20){
p.setRed(255);
}
}
print (img);
</script>
Share
Improve this question
edited Jan 25, 2018 at 14:26
sebasp
113 bronze badges
asked Jan 25, 2018 at 14:15
Rajind PamodaRajind Pamoda
1432 silver badges10 bronze badges
5
- 4 By SimpleImage you mean the library? If so, check if you're importing it correctly. Also, the SimpleImage constructor needs a Canvas and not width/height. – Fellipe Augusto da Silva Commented Jan 25, 2018 at 14:17
- I want to create a simple image using javascript.. How to include a library to my script? – Rajind Pamoda Commented Jan 25, 2018 at 14:25
- Please elaborate. What do you mean by "simple image"? – Fellipe Augusto da Silva Commented Jan 25, 2018 at 14:27
- I'm following this code here sites.google./site/tech23repo/scripting/javascript – Rajind Pamoda Commented Jan 25, 2018 at 14:28
- 2 @RajindPamoda, imo this site is for the trash bin. Because the code doesn't work without a library AND they don't mention what library they use AND the one library I found doesn't provide the functions they use. So I don't know how to make their code work – Thomas Commented Jan 25, 2018 at 14:48
3 Answers
Reset to default 2The problem here is that you first need to include a library that contains SimpleImage() function, JavaScript doesn't include a predefined library like the one you mention. In the webpage you are looking for (sites.google./site/tech23repo/scripting/javascript), it also doesn't show which library you should be including in your script. So for example, for this to work:
<script>
var img = new SimpleImage(200, 200);
for (var p of img.values()){
x = p.getX();
y = p.getY();
w = img.getWidth()
if (x > y){
p.setRed(255);
}
if (x + y > w){ //Indent this correctly
p.setRed(255);
}
if (x > 20){
p.setRed(255);
}
}
print (img);
</script>
You need to have defined the method SimpleImage() somewhere, something like this:
<script async="" src="https://www.dukelearntoprogram./course1/mon/js/image/SimpleImage.js"></script>
<script>
//Rest of the code using SimpleImage() method goes here.
var img = new SimpleImage(200, 200);
for (var p of img.values()){
x = p.getX();
y = p.getY();
w = img.getWidth()
if (x > y){
p.setRed(255);
}
if (x + y > w){ //Indent this correctly
p.setRed(255);
}
if (x > 20){
p.setRed(255);
}
}
print (img);
</script>
The library you require is from the Duke / Coursera course you can obtain it here. http://www.dukelearntoprogram./course1/mon/js/cs101/SimpleImage.js
You can find more info here http://www.dukelearntoprogram./course1/
You require the library of DLTP(Duke University CourseEra Course).You can Inject it into your code offline or by online. Online Injection of SimpleImage library:
<script src="https://www.dukelearntoprogram./course1/mon/js/image/SimpleImage.js" >
Offline Injection of SimpleImage library download link[DLTP Library Download Link]::https://www.dukelearntoprogram.//downloads/archives/cs101.zip
本文标签: imageCreate a SimpleImage on JavaScriptStack Overflow
版权声明:本文标题:image - Create a SimpleImage on JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744875639a2629898.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论