void WaitForMouseUp() { if (TcpClient == NULL) Error("Graphics not initialized"); while (true) { if (!MouseButtonIsDown()) return; } }
void iterate(Point v1, Point v2, Point v3, Point currentPoint) { if (MouseButtonIsDown()) ExitGraphics(); MovePen(currentPoint.X, currentPoint.Y); StartFilledRegion(1); DrawArc(CIRCLE_SIZE, 0, 360); EndFilledRegion(); Point nextRand = randPoint(v1, v2, v3); currentPoint.X = 0.5 * (currentPoint.X + nextRand.X); currentPoint.Y = 0.5 * (currentPoint.Y + nextRand.Y); UpdateDisplay(); iterate(v1, v2, v3, currentPoint); }
void main (void) { worldADT world; int i; double time=InitialTimeInterval; int numcreature; speciesADT *speciesP; creatureADT *creatureP; while(TRUE) { Randomize(); InitGraphics(); InitWorldMap(NColumns,NRows); i=0; numcreature=0; world=NewWorld(NColumns,NRows); PrintInstructions1(); speciesP=SetSpecies(&numcreature); speciesP=Shuffle(speciesP,numcreature); creatureP=GetBlock( numcreature * sizeof (creatureADT) ); PlacingCreatures(world,creatureP,speciesP,numcreature); PrintInstructions2(); while ( !MouseButtonIsDown() || WantToContinue(creatureP,numcreature,&time) ) { TakeOneTurn(creatureP[i]); i=(i+1)%numcreature; Pause(time); } FreeWorld(world); FreeBlock(creatureP); if (!WantToPlayAgain()) {break;} } }
void PathfinderEventLoop() { while (true) { WaitForMouseDown(); int downButtonIndex = FindButtonIndex(GetMouseX(), GetMouseY()); if (downButtonIndex != -1) { buttons[downButtonIndex].highlighted = true; DrawButton(buttons[downButtonIndex]); UpdateDisplay(); } bool isDown = true; while (isDown) { isDown = MouseButtonIsDown(); int index = FindButtonIndex(GetMouseX(), GetMouseY()); if (index != downButtonIndex) { if (downButtonIndex != -1) { buttons[downButtonIndex].highlighted = false; DrawButton(buttons[downButtonIndex]); } if (index != -1 && isDown) { buttons[index].highlighted = true; DrawButton(buttons[index]); } downButtonIndex = index; UpdateDisplay(); } } if (downButtonIndex != -1) { buttons[downButtonIndex].highlighted = false; DrawButton(buttons[downButtonIndex]); UpdateDisplay(); buttons[downButtonIndex].callback->apply(); } else { pointT pt; pt.x = int(GetMouseX()); pt.y = int(GetMouseY()); if (pt.y < WINDOW_HEIGHT && clickHook != NULL) { clickHook->apply(pt); } } } }
int main() { pointT tri[nPOINTS]; // Get three different points from the user via mouse, connect pts as arrive cout << "Click your mouse in three different areas of the canvas." << endl; cout << "The points will be connected to form a triangle and then" << endl; cout << "the triangle will mysteriously begin to fill." << endl; cout << endl; cout << "ALERT! Click your mouse in the window to stop the fill process." << endl; InitGraphics(); GetTrianglePoints(tri); // randomly choose one of the points, i.e. pick an index from 'tri' Randomize(); int vertex; vertex = RandomInteger(0, nPOINTS-1); pointT cp = tri[vertex]; while ( ! MouseButtonIsDown() ) { //for ( int i = 0; i < 10000; i++ ) { // draw a small, filled circle around the current point DrawCircle(cp); UpdateDisplay(); // randomly choose any of the perimeter vertices vertex = RandomInteger(0, nPOINTS-1); // move the current point halfway towards the new point cp.xp = ( tri[vertex].xp + cp.xp ) / 2; cp.yp = ( tri[vertex].yp + cp.yp ) / 2; //} } return 0; }