Hi,
I looked at a lot of timer solutions in the forum, but they don't seem to 'fit' my problem. Perhaps you can help?
I'm trying to get a sketch working where the ball starts moving horizontally at a given digital clock-time - say 9.00 ( but for the purpose of the sketch, I set it only to seconds) pauses for a few seconds, than drops vertically.
It seems to work, but I notice that the DISPLAY_DURATION is shorter than the expected 2 seconds. Also I'm not sure about the function of interval here. It does influence, but in an odd way.
What's wrong and how can it be solved?
many thanks for your time and thought
cheers
nanette
void display () {
hour = hour(); //Get the current time
minute = minute();
second = second();
hour = hour % 24; //Wrap the hour around to conform with 12-hour time
if (hour == 0) hour = 24; //Make zero-o-clock twelve-o-clock
backgroundChange ();
}
//---------------------------
void timeDisplay () {
if (second >=0 && second <30) {
fill (0);
textAlign (CENTER, BOTTOM);
textSize (15);
text ("Current Time", width/2, height/2);
textAlign (CENTER, TOP);
text (hour + ":" + minute + ":" + second + " ", width/2, height/2);
}
else
{
fill (255);
textAlign (CENTER, BOTTOM);
textSize (15);
text ("Current Time", width/2, height/2);
textAlign (CENTER, TOP);
text (hour + ":" + minute + ":" + second + " ", width/2, height/2);
}
}
//---------------------------
void backgroundChange () { // at a given time color change happens
fill (0, (second*4.25));
noStroke();
rect (20, 20, width-40, height-40);
}
//---------------------------
void moveBall()// at a stated second the ball starts moving to x=100 then stops
{
if (( second >= 10)&& (x<=100)) {
speedX=2;
x= x+speedX;
y=20;
fill (150);
ellipse ( x, y, 20, 20); // ball
}
else
{
speedX=0;
fill (0);
ellipse ( x, y, 20, 20); // ball
}
if (x>=100) { // I want it to stop for 3 seconds
startTime= 0;
if (millis() - startTime > DISPLAY_DURATION)
{
fill (0);
ellipse ( x, y, 20, 20); // ball
speedY=2;
y=y+speedY;
}
}
}
}// final bracket
Hi there,
After a day of trying I really could do with some help. I know it's a common issue but I've tried to apply almost all relevant answers I could find, but I just can't get it right.
I can get an xml feed, I can do a keyword query in twitter ( thank you Forum!!) but I can't do a keyword querie in xml feeds.
(I'm after comparing all types of data queries and experimenting with their graphic expressions)
Here is the code I've 'constructed so far':
One day I'll hopefully be able to return the favors!!!
//-------------------------------------
String[] title;
//to highten the chance for something to show up I put in "have"
String[] good= {
"good", "peace", "growth", "have"
};
//to highten the chance for something to show up I put in "no"
String[] bad = {
"bad", "war", "cuts", "not"
};
XML xml;
ArrayList <String> words = new ArrayList <String> ();
// Load RSS feed in this case BBC news
xml = loadXML( "http://feeds.bbci.co.uk/news/rss.xml");
// Get title of each element
XML[] title = xml.getChildren("channel/item/title");
//----------------------------------
try {
QueryResult result = xml.search(title); //?????
ArrayList title = (ArrayList) result.getTitles();
title = new String[titlexml.length];
for (int i = 0; i < titlexml.length; i++) {
String title = titlexml[i].getContent();
//Put each word into the words ArrayList
words.add(input[j]);
}
}
}
catch (Exception te) { // for when it goes wrong
println("Couldn't connect: " + te);
};
}
//------------------------------------------------------
void draw() {
background(255);
//Draw a word from the list of words that we've built
int i = (frameCount % words.size());
String word = words.get(i);
//show the results
if (compareWordToArray(word, good)) {
fill(0, 255, 0);
text("good", random(width), random(height));
}
if (compareWordToArray(word, bad)) {
fill(255, 0, 0);
text("bad", random(width), random(height));
}
}
//------------------------------------------------------
boolean compareWordToArray(String word, String[] wordArray) {
for (int i=0; i<wordArray.length; i++) {
if (word.equals(wordArray[i])) return true;
}
return false;
}
Hi There,
Learner driver here: I've tried various ways but I'm stuck
I've constructed a 'flower' and I want to rotate the stem+ flower from left to right ( but not the leave) I want it to move round a pivital point at the bottom of the stem. But I can't seem to make it rotate around that point.
btw I've haad simular problems with the leave, where I couldn't move the pivital point , making placement of the leave rather awkward- but I succeeded.
So this is what I'm after
this is how far I got:
float x;
float y;
float flowerAngle;
float angleChange =1.5;
final int ANGLE_LIMIT = 135;
void drawLeave (){ //draw leave
pushMatrix ();
fill (96, 255, 82);
translate (205,285);// make bottom of stem point zero
rotate(radians(45)); //rotate the leafshape
ellipse (-7, -40, 140, 20);
popMatrix();
}