A simple mechanical toy controlled by the mouse
~ move left-right to rotate left and right
~ move up-down to raise and lower rotation intensity
~ click and move to change the point of view
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
Archived Sketch
This sketch is created with an older version of Processing,
and doesn't work on browsers anymore.
View Source Code
Altalena (see-saw)
Minudel
xxxxxxxxxx
FKBox seeSaw;
float rotx = -PI / 2 + PI / 20f;
float roty = -PI / 2 - PI / 10f;
float mouseXwhenNotPressed = width / 2;
float mouseYhenNotPressed = 0;
void setup() {
size(600, 600, P3D);
//smooth();
rectMode(CORNERS);
int W = color(255);
seeSaw = new FKBox(this, -50f, -10f, 50f, 10f, 0f, W);
addNode(addNode(addNode(addNode(addNode(seeSaw)))));
}
FKBox addNode(FKBox parent) {
FKBox aNewNode = new FKBox(this, -2f, 0, 2f, 90f, 0f, color(128));
parent.attach(aNewNode, 0, parent.h / 2f);
return aNewNode;
}
void draw() {
background(99);
stroke(0);
// Change height of the camera with mouseY
float distZ = 575.0f;
float xCam = 300 + distZ * sin(rotx) * cos(roty);
float yCam = 300 + distZ * cos(rotx);
float zCam = distZ * sin(rotx) * sin(roty);
camera(xCam, yCam, zCam, // eyeX, eyeY, eyeZ
300f, 300f, 0.0f, // centerX, centerY, centerZ
0.0f, 1.0f, 0.0f); // upX, upY, upZ
// Orange point light on the right
pointLight(150, 100, 0, // Color
300, -150, 0); // Position
// Blue directional light from the left
directionalLight(0, 102, 255, // Color
-1, 0, 0); // The x-, y-, z-axis direction
// Yellow spotlight from the front
spotLight(255, 255, 109, // Color
400, 250, 375, // Position
0f, -0.5f, -0.5f, // Direction
PI, 0.1f); // Angle, concentration
ellipseMode(CENTER);
ellipse(width / 2, height / 2, 80, 80);
translate(width / 2, height / 2);
strokeWeight(2);
if (mousePressed == false) {
mouseXwhenNotPressed = mouseX;
mouseYhenNotPressed = mouseY;
}
if (mousePressed == false || mouseButton == LEFT) {
float force = (float) (mouseXwhenNotPressed) / (float) (width)
* 0.4f - 0.2f;
float decay = (float) (mouseYhenNotPressed) / (float) (height)
* 0.02f + 0.01f;
seeSaw.impulse(force, decay);
float friction = 0.92f;
seeSaw.move(friction);
}
seeSaw.draw();
}
void mouseDragged() {
float dy = mouseX - pmouseX;
float dx = mouseY - pmouseY;
float rate = 0.008f;
if (abs(dx) > abs(dy)) {
rotx -= (dx) * rate;
rotx = java.lang.Math.min(rotx, 0 - 0.01f);
rotx = java.lang.Math.max(rotx, -PI + 0.01f);
}
else {
roty += (dy) * rate;
}
}
See More Shortcuts