var sketch = function (p) {
// Global variables
var plot, i;
var step = 0;
var stepsPerCycle = 100;
var lastStepTime = 0;
var clockwise = true;
var scale = 5;
// Initial setup
p.setup = function () {
// Create the canvas
var canvas = p.createCanvas(450, 450);
// Prepare the first set of points
var nPoints1 = stepsPerCycle / 10;
var points1 = [];
for (i = 0; i < nPoints1; i++) {
points1[i] = calculatePoint(step, stepsPerCycle, scale);
step = (clockwise) ? step + 1 : step - 1;
}
lastStepTime = p.millis();
// Prepare the second set of points
var nPoints2 = stepsPerCycle + 1;
var points2 = [];
for (i = 0; i < nPoints2; i++) {
points2[i] = calculatePoint(i, stepsPerCycle, 0.9 * scale);
}
// Create the plot
plot = new GPlot(p);
plot.setPos(25, 25);
plot.setDim(300, 300);
// or all in one go
// plot = new GPlot(p, 25, 25, 300, 300);
// Set the plot limits (this will fix them)
plot.setXLim(-1.2 * scale, 1.2 * scale);
plot.setYLim(-1.2 * scale, 1.2 * scale);
// Set the plot title and the axis labels
plot.setTitleText("Clockwise movement");
plot.getXAxis().setAxisLabelText("x axis");
plot.getYAxis().setAxisLabelText("y axis");
// Activate the panning effect
plot.activatePanning();
// Add the two set of points to the plot
plot.setPoints(points1);
plot.addLayer("surface", points2);
// Change the second layer line color
plot.getLayer("surface").setLineColor(p.color(100, 255, 100));
};
// Execute the sketch
p.draw = function () {
// Clean the canvas
p.background(150);
// Draw the plot
plot.beginDraw();
plot.drawBackground();
plot.drawBox();
plot.drawXAxis();
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.