toolness / p5.js-widget

A reusable widget for embedding editable p5 sketches in web pages.
https://toolness.github.io/p5.js-widget/
GNU Lesser General Public License v2.1
162 stars 44 forks source link

p5 widget cound not run my code properly #75

Closed yonghuming closed 4 years ago

yonghuming commented 4 years ago

i deployed p5.widget on http://118.24.137.218/pw.html and i paste some code which could run on my windows 10 chrome browser through vscode live server extension just live below:

var colors = ['red', 'blue', 'green', 'black'];
var tip_color = '';
var tip = '';
var score = 0;

function random_index(){
  return Math.floor(Math.random() * colors.length);
}

function setup(){
  var p = createCanvas(300, 400);
  p.parent('canvas')
  tip = colors[random_index()]
  tip_color = colors[random_index()]
  // print(random_index())
}
function draw(){
  background(200);

  textSize(50)
   fill(tip_color)
   text(tip, 80, 200)

  fill('black');
  textSize(30)
  text('Wrong', 50, 380)
  text('Right', 180, 380)
  text(str(score), 50,50)
  textSize(10)
  text('Special For vicia',0, 395)

}

function mouseClicked(){

  console.log(tip)
  console.log(tip_color)
  if(mouseX>150){
    if(tip == tip_color){
      score += 1;
    }else{
      score -= 1;
    }
  }else{
    if(tip == tip_color){
      score -= 1;
    }else{
      score += 1;
    }
  }
  tip = colors[random_index()]
  tip_color = colors[random_index()]

}

but a got an error image i could not figure out anything wrong for it's too dificullt for me .

yonghuming commented 4 years ago
  p.parent('canvas') 

just del this line