gpt4 book ai didi

javascript - 无法弄清楚为什么变量在 p5.js 中未定义

转载 作者:行者123 更新时间:2023-11-27 23:08:33 28 4
gpt4 key购买 nike

我确信这是有史以来最简单的问题,但我和我的 friend 在 p5.js 中配对编码,无法弄清楚为什么下面的代码会抛出错误:Uncaught ReferenceError: RiLexicon is not Define

我们已经完成了一个类似的项目,所有代码基本上都在完全相同的位置,并且它有效。也许我们已经盯着这件事太久了,快要疯了?请帮忙!谢谢!

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."
}
}
}

最佳答案

就像评论所说,您需要确保正在加载 RiTa 库。

听起来也许您之前的草图已经加载了库,然后您将该草图中的一些代码复制到了新草图中。问题是,这还不足以让你的新草图发挥作用。您必须将该库加载到新草图中才能访问它。

Here是关于如何加载库的非常好的教程,但我将尝试在此处复制基础知识:

第 1 步:here 下载 RiTa .

第 2 步:查找名为 rita-full.min.js 的文件(您也可以直接从here下载)。

第 3 步:将该文件复制到您的 sketch 目录中。您的 html 文件应该可以访问它。

第 4 步:编辑 html 文件以加载库,将此行放入 <head> 中部分:

<script src="your/path/to/rita-full.min.js" type="text/javascript"></script>

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

您可以在 RiTaJS 的 GitHub 页面 here 上找到更多信息,或在this RiTaJS tutorial中.

关于javascript - 无法弄清楚为什么变量在 p5.js 中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36392375/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com