We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › What do i need to change here?
Page Index Toggle Pages: 1
What do i need to change here??? (Read 479 times)
What do i need to change here???
Mar 20th, 2007, 5:12pm
 
Sorry guys for all the questions, but im running this code, its taken from the spring example
Do u know what do i need to change to make the text spring up and down, or left to right cause at the moment when i run it its going in a diagonal fashion....
Thanks guys...
(also if i change the size it doesnt work at all...)


import processing.core.*;
import processing.app.*;
import processing.core.PApplet;


public class effects1 extends PApplet {
 


// Spring drawing constants for top bar
int s_height = 16;     // Height
int left = 50;         // Left position
int right = 150;       // Right position
int max = 150;         // Maximum Y value
int min = 20;          // Minimum Y value
boolean over = false;  // If mouse over
boolean move = false;  // If mouse down and over

// Spring simulation constants
float mass = 2.8;   // Mass
float K = 0.2;   // Spring constant
float damping = 0.92;  // Damping
float R = 60;    // Rest position

// Spring simulation variables
float position = 60.0; // Position
float velocity = 0.0;  // Velocity
float acceleration = 5;    // Acceleration
float force = 0;     // Force

PFont font;

public void setup()
{
 size(200, 200, JAVA2D);
 //noStroke();
 frameRate(60);
 font = loadFont("data/Tahoma-48.vlw");
}

public void draw()
{
 background(102);
 updateSpring();
 drawSpring();
}

public void drawSpring()
{
 // Draw base
 fill(20);
 float b_width = 0.5 * position + -8;
 
 //rect(width/2 - b_width, ps + s_height, width/2 + b_width, 150);

 // Set color and draw top bar
 if(over || move)
 {
   fill(0);
 }
 else
 {
   fill(255);
 }
 textFont(font);
 text("String",width/2 - b_width, position + s_height);
 //rect(left, position, right, position + s_height);

}


public void updateSpring()
{
 // Update the spring position
 if(!move) {
   force = -K * (position - R);    // force=-ky
   acceleration = force / mass;           // Set the acceleration, force=ma == acceleration=force/m
   velocity = damping * (velocity + acceleration);   // Set the velocity
   position = position + velocity;         // Updated position
 }
 if(abs(velocity) < 0.1) {
   velocity = 0.0;
 }





 // Test if mouse is over the top bar
 if(mouseX > left && mouseX < right && mouseY > position && mouseY < position + s_height) {
   over = true;
 } else {
   over = false;
 }
 
 
 
 
 
 
 // Set and constrain the position of top bar
 if(move) {
   position = mouseY - s_height/2;
   if (position < min) { position = min; }
   if (position > max) { position = max; }
 }

}






void mousePressed() {
 if(over) {
   move = true;
 }
}

void mouseReleased()
{
 move = false;
}
}
Re: What do i need to change here???
Reply #1 - Mar 21st, 2007, 3:13pm
 
figured this out... =)
Page Index Toggle Pages: 1