semantic.cpp in func_draw.rar
Sponsored links
#include "semantics.h"
extern double
Parameter,
Origin_x,Origin_y,
Scale_x,Scale_y,
Rot_angle;
double GetExprValue(struct ExprNode *root);
void DrawPixel(unsigned long x,unsigned long y);
void DrawLoop(double Start,double End,double Step,struct ExprNode *HorPtr,struct ExprNode *VerPtr);
void DelExprTree(struct ExprNode *root);
static void Errmsg(char *string);
static void CalcCoord(struct ExprNode *Hor_Exp,struct ExprNode *Ver_Exp,
double &Hor_x, double &Ver_y);
void Errmsg(char *string)
{
exit(1);
}
static void CalcCoord(struct ExprNode *Hor_Exp,struct ExprNode *Ver_Exp,double &Hor_x, double &Ver_y)
{
double HorCord,VerCord,Hor_tmp;
HorCord=GetExprValue(Hor_Exp);
VerCord=GetExprValue(Ver_Exp);
HorCord *=Scale_x;
VerCord *=Scale_y;
Hor_tmp=HorCord *cos(Rot_angle)+VerCord *sin(Rot_angle);
VerCord=VerCord *cos(Rot_angle)-HorCord*sin(Rot_angle);
HorCord=Hor_tmp;
HorCord+=Origin_x;
VerCord+=Origin_y;
Hor_x=HorCord;
Ver_y=VerCord;
}
void DrawLoop(double Start,
double End,
double Step,
struct ExprNode *HorPtr,
struct ExprNode *VerPtr)
{
extern double Parameter;
double x,y;
for(Parameter=Start;Parameter<=End;Parameter+=Step)
{CalcCoord(HorPtr,VerPtr,x,y);
DrawPixel((unsigned long) x,(unsigned long)y);
}
}
double GetExprValue(struct ExprNode *root)
{
if(root==NULL)return 0.0;
switch(root->OpCode)
{
case PLUS:
return GetExprValue(root->Content.CaseOperator.Left)+GetExprValue(root->Content.CaseOperator.Right);
case MINUS:
return
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.