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
161 stars 44 forks source link

Slider doesn't work #58

Open bensk opened 8 years ago

bensk commented 8 years ago

This works in p5:

var x
var y
var speed
var slider;

function setup() {
  createCanvas(windowWidth, windowHeight)
  x = windowWidth/2
  y = 30
  speed = 3
    // create a slider we can drag, from -30 to 30 and starting at 0
  slider = createSlider(-30, 30, 0);
  // set the position of the slider on the screen
  slider.position(windowWidth / 2-90, 90);
  // set the size of the slider
  slider.style('width', '180px');
}

function draw() {
  // We need to make a variable for the slider's value...
  var speed = slider.value();
  background('white')
  textSize(32)
  text("🤖", x, y)
  // ... so that we can move the robot
  x = x + speed
}

but in the widget I get

Line 12: Uncaught ReferenceError: createSlider is not defined

toolness commented 8 years ago

Thanks for the bug report!

Unfortunately, this is due to https://github.com/toolness/p5.js-widget/issues/53 being unresolved: createSlider() is part of p5.dom, and the widget doesn't currently include that library in the iframe that it executes the widget snippet in.

Do you need this functionality soon or is it not a high priority for you?

bensk commented 8 years ago

Thanks for the fast reply!

I'm teaching a bunch of 8th graders about p5.dom tomorrow, but I can have them copy and paste code into the editor.

BTW, your widget has been invaluable for teaching, so thank you!

toolness commented 8 years ago

Oh that's awesome--I love the heading OM DOM DOM :grin:

Thanks, I'm glad you find the widget useful!! Unfortunately I don't have time to add support for p5.dom by tomorrow, but I will definitely prioritize it highly as I continue work on the widget.