首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法计算为什么在p5.js中未定义变量

无法计算为什么在p5.js中未定义变量
EN

Stack Overflow用户
提问于 2016-04-03 23:06:18
回答 1查看 2.4K关注 0票数 1

我确信这是有史以来最简单的问题,但我和我的朋友正在用p5.js对代码进行编码,无法理解为什么下面的代码会抛出错误:未定义ReferenceError: RiLexicon

我们做了一个类似的项目,所有的代码基本上都在相同的地方,而且它可以工作。也许我们盯着这个看得太久了,而且要疯了?请帮帮我!谢谢!

代码语言:javascript
复制
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."
        }  
    }
 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-04 16:34:22

如评论所述,您需要确保正在加载RiTa库。

听起来好像你以前的草图已经加载了库,然后你从这个草图中复制了一些代码到一个新的草图中。问题是,这还不足以让你的新素描奏效。你必须把这个库加载到你的新草图中,这样你才能访问它。

这里是一个关于如何加载库的非常好的教程,但是我将尝试在这里复制基本知识:

步骤1:这里下载RiTa。

步骤2:找到一个名为rita-full.min.js的文件(也可以直接从这里下载)。

步骤3:将该文件复制到您的草图目录中。它应该可以由您的html文件访问。

步骤4:编辑您的html文件以加载库,方法是将这一行放在<head>部分:

代码语言:javascript
复制
<script src="your/path/to/rita-full.min.js" type="text/javascript"></script>

步骤5:现在当您加载html页面时,库将被加载,您的代码将能够访问它。

您可以在RiTaJS的GitHub页面这里本RiTaJS教程中找到更多信息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36392375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档