#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Making Clock with Pendulum

This is for an assignment in my Computational Thinking class, and I am _not _ the best with Processing, so if you could try to just hint me which lines I will need to edit to accomplish certain things (not what to actually do) and/or other lines in the code that I can play with and take example from to perform other actions.

Currently I am trying to make the pendulum, so I know I need to use a draw function to draw a line oriented at the center of the frame, but I'm not sure how or where. Our teacher gave us a line of code to start us out for the pendulum but I don't know what to do with it. I apologize for the commentary in the code and, again, when it comes to processing, I am not the brightest pixel in the screen.

``````void setup()
{
size(1000, 2000);
colorMode(HSB);
background(0);
frameRate(30);
surface.setResizable(false); //I can probably take this out can't i huh

}

void draw()
{
float h, m, s;
float cx, cy;

float clockface;
float minuteDotSize, hourDotSize;

String months[] = {"XXX", "Jan", "Feb", "Mar", "Apr"};
String days[] = {};

cx = width/2.0;
cy = height/4.0;

s = second();
m = minute();
h = hour()%12; //Will handle this last because it's kiiinda difficult to know if it broke the function or not

fill(128);
noStroke();
ellipse(cx, cy, clockface, clockface);

textSize(150);
fill(0, 255, 255);
textAlign(CENTER, CENTER); //now how do I get it below the clockface
text(months[1+3], cx, cy); //HOW TO DAYs?

for (float pos=0; pos<60; pos+=1) {
if (pos%5==0) {
} else {
}
}

}

float handPos(float angle)
{
}

color colorPos(float angle)
{
return color(map(angle, 0, 360, 0, 255), 255, 255);
}

void drawHand(float cx, float cy, float angle, float len, float weight)
{
stroke(colorPos(angle));
strokeWeight(weight);
line(cx, cy, cx + cos(handPos(angle))*len, cy + sin(handPos(angle))*len);
}

void drawTick(float cx, float cy, float angle, float len, float size)
{
fill(colorPos(angle));
noStroke();
rectMode(CENTER);
rect(cx + cos(handPos(angle))*len, cy + sin(handPos(angle))*len, size, size);
}

// TO DO AND OR KEEP TESTING AND MESSING UP

void drawNum(float cx, float cy, float angle, float len, float weight, int num)
//should i be referring to the tick mark code i feel like I should be smart and do that

{
int maxh; //i don't even know if this is right and I already feel like a genius for trying
int n;

}

void drawPend(float cx, float cy, float angle, float len, float size, float weight)

{
//clear() for the clear every frame requirement right?

//pendSize = hourDotSize*8.0;
//pendWeight = 3;

}

// told me I had duplicate draw hand, gotta go put more commands in the one draw hand area then?
// why is coding giving me an existential crisis
``````
Tagged:

• The code you have posted runs without issue. It also draws something, and appears to even tell the time (almost)! What is not clear, however, is what you are trying to add/change to it. You want a pendulum? Drawn where? Behind the clock, below it? What does the pendulum look like? Does it swing back and forth? How fast? How far out does it swing?

I would honestly sugguest you put this body of code on-hold for right now, and instead start with a blank sketch. Then add a pendulum to it - and just a pendulum. And once you have that working, and only then, try adding it to this sketch.

• Oh, and a pendulum has a formula, one with a bit of math.

• @TurtleTeaParty -- re:

I need to use a draw function to draw a line oriented at the center of the frame

To move the frame of reference during `draw()` so that (0,0) is at the center of the sketch frame:

``````translate(width/2,height/2);
``````

Now, draw a line straight down:

``````line(0,0,0,myLength);
``````

But wait -- what if you wanted that straight line to be straight down... in a rotated direction?

``````translate(width/2,height/2);