swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw "point graphs"?


From: Marcus G. Daniels
Subject: Re: How to draw "point graphs"?
Date: 25 Jun 2000 17:40:47 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "PA" == Perrone Alessandro <address@hidden> writes:

PA> In one model I am programming, I'd like to plot some
PA> ghraphs, but instead of line graphs, "point graphs".  Is it
PA> possible with Swarm or I have to program myself the class using
PA> tcl/tk library? 

If you use the Graph interface directly (as opposed to EZGraph), you
can send the result of createElement: messages like setWidth:
(for the linewidth) and setSymbol:, or resort to sending messages to
globalTkInterp.

Here's an example:

#import <simtools.h>
#import <objectbase/SwarmObject.h>
#import <analysis.h>
#import <misc.h> // sin
#import <tkobjc/global.h>

@interface Agent: SwarmObject
- compute: xPtr: yPtr;
@end

@implementation Agent
- compute: xPtr: yPtr
{
  double x = *(double *)xPtr;
  double y = sin (x);

  *(double *)yPtr = y;
  return (id)YES;
}
@end

@interface Controller: SwarmObject
{
  id <FunctionGraph> fg;
  id <GraphElement> fe;
  id <Graph> graph;
  id agent;
  id panel;
}
- createEnd;
- graph;
- exit;
@end

@implementation Controller

- createEnd
{
  id fgd;

  agent = [Agent create: [self getZone]];

  fgd = [Frame create: [self getZone]];
  
  graph = [Graph createParent: fgd];
  [graph setWindowTitle: "FunctionGraph"];

  [graph pack];

  fe = [graph createElement];
  [fe setLabel: "myLabel"];
  [fe setColor: "red"];
  [fe setWidth: 0];    
  [fe setSymbol: "circle"];
  [globalTkInterp eval: "%s element configure %s -pixels 0.01i",
                  [graph getWidgetName],
                  [fe getName]];
  
  fg = [FunctionGraph createBegin: [self getZone]];
  [fg setElement: fe];
  [fg setDataFeed: agent];
  [fg setFunctionSelector: M(compute::)];
  [fg setXMin: 0.0 Max: 2.0 * M_PI Resolution: 100];
  [fg setResetFrequency: 0];
  fg = [fg createEnd]; 

  panel = [ButtonPanel createBegin: [self getZone]];
  [panel setButtonTarget: self];
  panel = [panel createEnd];
  [panel setWindowTitle: "ControlPanel"];
  [panel addButtonName: "Exit" method: @selector (exit)];

  return self;
}

- exit
{
  exit (0);
}

- graph
{
  [fg graph];

  return self;
}
@end

main (int argc, const char **argv)
{ 
  id controller;

  initSwarm (argc, argv);

  controller = [Controller create: globalZone];
  
  [controller graph];
  
  while (1)
    {
      while (GUI_EVENT_ASYNC ()) {}
    }  
}

/*
Local Variables:
compile-command: "gcc -DDLL -o funcgraph -g -Wno-import -I$SWARMHOME/include 
-L$SWARMHOME/lib funcgraph.m -lswarmdll -lobjcdll"
End:
*/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]