我确信这是有史以来最简单的问题,但我和我的朋友正在用p5.js对代码进行编码,无法理解为什么下面的代码会抛出错误:未定义ReferenceError: RiLexicon
我们做了一个类似的项目,所有的代码基本上都在相同的地方,而且它可以工作。也许我们盯着这个看得太久了,而且要疯了?请帮帮我!谢谢!
var mermaid = ("Fishes, both large and small, glide between the branches, as birds fly among the trees here upon land. In the deepest spot of all, stands the castle of the Sea King. Its walls are built of coral, and the long, gothic windows are of the clearest amber. The roof is formed of shells, that open and close as the water flows over them. Their appearance is very beautiful, for in each lies a glittering pearl, which would be fit for the diadem of a queen.");
var story = [];
var lexicon;
function setup() {
createCanvas(650,400);
lexicon = new RiLexicon();
story = RiTa.tokenize(mermaid);
//partsOfSpeech = RiTa.getPosTags(story);
textSize(15);
fill(255, 100, 100);
function draw(){
// background(255);
var wordPosX = 10;
var wordPosY = width/8;
for(var i=0; i < story.length; i++){
text(story[i], wordPosX, wordPosY)
textWidth(story[i]+5,30);
//we check whether each parts of speech exists
//in our array
//if(partsOfSpeech[i] != null){
// text(partsOfSpeech[i], wordPosX, wordPosY+20, textWidth(story[i]), 20);
// fill(100,175,175);
wordPosX += textWidth(story[i])+ 3;
//if wordPosX goes beyond our width,
//move the text down to a new line
if(wordPosX +30 > width){
wordPosX = 10;
wordPosY += 50;
}
}
}
function mousePressed(){
changingWords();
textSize(15);
function changingWords (){
var story = "Fishes," +
lexicon.randomWord("nn") + "" +
lexicon.randomWord("jj") +
"and" + lexicon.randomWord("jj") +
", glide between the branches, as birds fly among the trees here upon" +
lexicon.randomWord("nn") +
". In the deepest" + lexicon.randomWord("nn") +
"of all, stands the" + lexicon.randomWord("nn") +
"of the Sea King. Its walls are built of" +
lexicon.randomWord("jj") +
", and the" + lexicon.randomWord("jj") +
"," + lexicon.randomWord("jj") +
"windows are of the clearest" +
lexicon.randomWord("jj") +
". The" + lexicon.randomWord("nn") +
"is formed of shells, that" +
lexicon.randomWord("jj") +
"and close as the" +
lexicon.randomWord("nn") +
"flows over them. Their" +
lexicon.randomWord("nn") +
"is very" + lexicon.randomWord("jj") +
", for in each lies a glittering" +
lexicon.randomWord("nn") +
", which would be fit for the" +
lexicon.randomWord("nn") +
"of a queen."
}
}
}发布于 2016-04-04 16:34:22
如评论所述,您需要确保正在加载RiTa库。
听起来好像你以前的草图已经加载了库,然后你从这个草图中复制了一些代码到一个新的草图中。问题是,这还不足以让你的新素描奏效。你必须把这个库加载到你的新草图中,这样你才能访问它。
这里是一个关于如何加载库的非常好的教程,但是我将尝试在这里复制基本知识:
步骤1:从这里下载RiTa。
步骤2:找到一个名为rita-full.min.js的文件(也可以直接从这里下载)。
步骤3:将该文件复制到您的草图目录中。它应该可以由您的html文件访问。
步骤4:编辑您的html文件以加载库,方法是将这一行放在<head>部分:
<script src="your/path/to/rita-full.min.js" type="text/javascript"></script>步骤5:现在当您加载html页面时,库将被加载,您的代码将能够访问它。
您可以在RiTaJS的GitHub页面这里或本RiTaJS教程中找到更多信息。
https://stackoverflow.com/questions/36392375
复制相似问题