3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Using the Tweak Processing Library

Step 2Adding Tweak to your own sketches

Adding Tweak to your own sketches
Tweak can be added to your own sketches by copying the Tweak.pde file to your sketch's folder and adding a few lines of code to initialize it.  The Tweak.pde file can be found in either of the example sketches.

Once you have added the Tweak.pde file to your sketch's folder, you can use Tweak variables for the things you want to be able to change while your program is running.  If your sketch isn't finding the Tweak.pde file, just close and reopen your sketch (Processing looks for other .pde files in your sketch's folder when it is opened).

There are currently four basic Tweak variables: TweakFloat, TweakInt, TweakBool, and TweakPoint.  These can each be used as standard Float, Int, Boolean, and Point types; just use the "new" operator to create them and get their value via the "val" property. 

Perhaps an example will help at this point.  Here we create a number (of type TweakInt) in the setup method and then get its value in the draw loop.  The number's initial value is 100 and its description is "My changeable number".   We then use that number to set the amount of red in the sketch's background.

----------------------------
TweakInt myNumber;

void setup(){
  myNumber = new TweakInt("My changeable number", 100);
}

void draw(){
  background(myNumber.val, 0, 0);
}
----------------------------


You can also set bounds on your Tweak variables.  The example above works fine, but colors should normally stay between 0 and 255.  In some cases, letting a variable go out of bounds may do unexpected things, so let's add in some limits to the example.  The "1" in the TweakInt's instantiation specifies the step size (in other words, how quickly the number changes when you are adjusting the variable).

----------------------------
TweakInt myNumber;

void setup(){
  myNumber = new TweakInt("My changeable number", 100, 1, 0, 255);
}

void draw(){
  background(myNumber.val, 0, 0);
}
----------------------------



Finally, let's add all three color channels to our example.

----------------------------
TweakInt myNumberR;
TweakInt myNumberG;
TweakInt myNumberB;

void setup(){
  myNumberR = new TweakInt("Background Red",   100, 1, 0, 255);
  myNumberG = new TweakInt("Background Green", 100, 1, 0, 255);
  myNumberB = new TweakInt("Background Blue",  100, 1, 0, 255);
}

void draw(){
  background(myNumberR.val,
myNumberG.val, myNumberB.val);
}
----------------------------


« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
37
Followers
8
Author:adamkumpf(dsLabs)
Background in Electrical Engineering, Computer Science, Robotics, and Tangible Interfaces from MIT. Currently working at Teague as a Physical Prototyper and regularly contributing to dsLabs. Other p...
more »