Quadruped Mammals

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int    seed;

void makedog(char *name);
void makecat(char *name);
void makehorse(char *name);
void makegee(char *name);
void printpart(float h, float r, int t, float axis[], float loc[]);
float bellrand(float st, float fin);
float Random(float st, float fin);
int rand3();
int rand4();
void choose();
void produce_data();

int main(int argc, char *argv[])
{
    produce_data();

    return 0;
}

void choose()
{
    switch (rand4()) {
    case 1: makedog("D"); break;
    case 2: makecat("C"); break;
    case 3: makehorse("H"); break;
    case 4: makegee("G"); break;
    default: printf("what the hell???/n"); exit(0);
    }
}

void produce_data()
{
  int seed, Nobj;

  scanf("%d %d", &seed, &Nobj);
  printf("@relation Quadruped Mammals/n");

  printf("@attribute TORSO_locX real/n");
  printf("@attribute TORSO_locY real/n");
  printf("@attribute TORSO_locZ real/n");
  printf("@attribute TORSO_axisX real/n");
  printf("@attribute TORSO_axisY real/n");
  printf("@attribute TORSO_axisZ real/n");
  printf("@attribute TORSO_height real/n");
  printf("@attribute TORSO_radius real/n");
  printf("@attribute TORSO_texture integer/n");

  printf("@attribute LEG1_locX real/n");
  printf("@attribute LEG1_locY real/n");
  printf("@attribute LEG1_locZ real/n");
  printf("@attribute LEG1_axisX real/n");
  printf("@attribute LEG1_axisY real/n");
  printf("@attribute LEG1_axisZ real/n");
  printf("@attribute LEG1_height real/n");
  printf("@attribute LEG1_radius real/n");
  printf("@attribute LEG1_texture integer/n");

  printf("@attribute LEG2_locX real/n");
  printf("@attribute LEG2_locY real/n");
  printf("@attribute LEG2_locZ real/n");
  printf("@attribute LEG2_axisX real/n");
  printf("@attribute LEG2_axisY real/n");
  printf("@attribute LEG2_axisZ real/n");
  printf("@attribute LEG2_height real/n");
  printf("@attribute LEG2_radius real/n");
  printf("@attribute LEG2_texture integer/n");

  printf("@attribute LEG3_locX real/n");
  printf("@attribute LEG3_locY real/n");
  printf("@attribute LEG3_locZ real/n");
  printf("@attribute LEG3_axisX real/n");
  printf("@attribute LEG3_axisY real/n");
  printf("@attribute LEG3_axisZ real/n");
  printf("@attribute LEG3_height real/n");
  printf("@attribute LEG3_radius real/n");
  printf("@attribute LEG3_texture integer/n");

  printf("@attribute LEG4_locX real/n");
  printf("@attribute LEG4_locY real/n");
  printf("@attribute LEG4_locZ real/n");
  printf("@attribute LEG4_axisX real/n");
  printf("@attribute LEG4_axisY real/n");
  printf("@attribute LEG4_axisZ real/n");
  printf("@attribute LEG4_height real/n");
  printf("@attribute LEG4_radius real/n");
  printf("@attribute LEG4_texture integer/n");

  printf("@attribute NECK_locX real/n");
  printf("@attribute NECK_locY real/n");
  printf("@attribute NECK_locZ real/n");
  printf("@attribute NECK_axisX real/n");
  printf("@attribute NECK_axisY real/n");
  printf("@attribute NECK_axisZ real/n");
  printf("@attribute NECK_height real/n");
  printf("@attribute NECK_radius real/n");
  printf("@attribute NECK_texture integer/n");

  printf("@attribute HEAD_locX real/n");
  printf("@attribute HEAD_locY real/n");
  printf("@attribute HEAD_locZ real/n");
  printf("@attribute HEAD_axisX real/n");
  printf("@attribute HEAD_axisY real/n");
  printf("@attribute HEAD_axisZ real/n");
  printf("@attribute HEAD_height real/n");
  printf("@attribute HEAD_radius real/n");
  printf("@attribute HEAD_texture integer/n");

  printf("@attribute TAIL_locX real/n");
  printf("@attribute TAIL_locY real/n");
  printf("@attribute TAIL_locZ real/n");
  printf("@attribute TAIL_axisX real/n");
  printf("@attribute TAIL_axisY real/n");
  printf("@attribute TAIL_axisZ real/n");
  printf("@attribute TAIL_height real/n");
  printf("@attribute TAIL_radius real/n");
  printf("@attribute TAIL_texture integer/n");

  printf("@attribute name { Giraffe, Dog, Cat, Horse }/n");

  printf("@data/n");

  int i;
  for (i = 1; i <= Nobj; ++i) {
      choose();
      printf("/n");
  }
}

void makedog(char *name)
{

    float    height, radius, axis[3], location[3];
    int texture;
    float    leglength, torsoH, torsoR;

    printf("Dog,");

    location[0]= location[1]= location[2]= 0;
    axis[0]= 1; axis[1]= 0; axis[2]= 0;
    torsoH= height= bellrand(22.0, 28.0);
    torsoR= radius= bellrand(5.5, 7.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    leglength= bellrand(10.0, 15.0);
    location[0]= torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
       /* this leg might be canted forward up to 45 degrees: */
    axis[0]= bellrand(0.0,1.0);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.8, 1.2);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.8, 1.2);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.8, 1.2);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= bellrand(0.0,1.0);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.8, 1.2);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(5.0, 6.0);
    location[0]= torsoH/2 + height/2;
    location[1]= 0;
    location[2]= torsoR;
    axis[0]= 1;
    axis[1]= 0;
    axis[2]= 1;
    radius= bellrand(2.0, 3.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2 + height; /* height is neck length */
    location[1]= 0;
    location[2]= torsoR;
    axis[0]= 1;
    axis[1]= bellrand(-1.0, 1.0);    /* he's looking to the right or left */
    axis[2]= 0;
    height= bellrand(10.0, 13.0);
    radius= bellrand(2.5, 3.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(6.0, 8.0);    /* a short tailed dog */
    location[0]= -torsoH + height;
    location[1]= 0;
    location[2]= 0;
    axis[0]= -1.0;
    axis[1]= bellrand(-1.0,1.0);   /* pointing any which way */
    axis[2]= bellrand(-1.0,1.0);
    radius= bellrand(0.2, 0.4);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

} /* end of makedog */

void makecat(char *name)
{
    float    height, radius, axis[3], location[3];
    int        texture;
    float    leglength, torsoH, torsoR;

    printf("Cat,");

    location[0]= location[1]= location[2]= 0;
    axis[0]= 1; axis[1]= 0; axis[2]= 0;
    torsoH= height= bellrand(15.0, 22.0);
    torsoR= radius= bellrand(2.5, 4.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    leglength= bellrand(4.0, 9.0);
    location[0]= torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
       /* this leg might be canted forward up to 45 degrees: */
    axis[0]= bellrand(0.0,1.0);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.4, 0.8);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.4, 0.8);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.4, 0.8);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= bellrand(0.0,1.0);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(0.4, 0.8);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(2.0, 4.0);
    location[0]= torsoH/2 + height/2;
    location[1]= 0;
    location[2]= torsoR;
    axis[0]= 1;
    axis[1]= 0;
    axis[2]= 1;
    radius= bellrand(1.5, 2.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2 + height; /* height is neck length */
    location[1]= 0;
    location[2]= torsoR;
    axis[0]= 1;
    axis[1]= bellrand(-1.0, 1.0);    /* he's looking to the right or left */
    axis[2]= 0;
    height= bellrand(3.0, 5.0);
    radius= bellrand(1.5, 2.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(10.0, 18.0);    /* a long tailed cat */
    location[0]= -torsoH + height;
    location[1]= 0;
    location[2]= 0;
    axis[0]= -1.0;
    axis[1]= bellrand(-1.0,1.0);   /* pointing any which way */
    axis[2]= bellrand(-1.0,1.0);
    radius= bellrand(0.3, 0.7);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

} /* end of makecat */

void makehorse(char *name)
{
    float    height, radius, axis[3], location[3];
    int        texture;
    float    leglength, torsoH, torsoR;

    printf("Horse,");
   
    location[0]= location[1]= location[2]= 0;
    axis[0]= 1; axis[1]= 0; axis[2]= 0;
    torsoH= height= bellrand(50.0, 60.0);
    torsoR= radius= bellrand(10.0, 14.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    leglength= bellrand(36.0, 44.0);
    location[0]= torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
       /* this leg might be canted forward up to 30 degrees: */
    axis[0]= bellrand(0.0,0.5);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 3.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 3.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 3.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= bellrand(0.0,0.5);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 3.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(12.0, 16.0);
    location[0]= torsoH/2 + height/2.828;
    location[1]= 0;
    location[2]= torsoR + height/2.828;
    axis[0]= 1;
    axis[1]= 0;
    axis[2]= 1;
    radius= bellrand(5.0, 7.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2 + height/1.414; /* height is neck length */
    location[1]= 0;
    location[2]= torsoR + height/1.414;
    axis[0]= 1;
    axis[1]= bellrand(-1.0, 1.0);    /* he's looking to the right or left */
    axis[2]= 0;
    height= bellrand(18.0, 22.0);
    radius= bellrand(4.0, 6.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(26.0, 33.0);    /* a long tailed horse */
    location[0]= -torsoH + height;
    location[1]= 0;
    location[2]= 0;
    axis[0]= -1.0;
    axis[1]= bellrand(-1.0,1.0);   /* pointing any which way */
    axis[2]= bellrand(-1.0,0.0);
    radius= bellrand(1.0, 2.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

} /* end of makehorse */

void makegee(char *name)
{
    float    height, radius, axis[3], location[3];
    int        texture;
    float    leglength, torsoH, torsoR;

    printf("Giraffe,");
   
    location[0]= location[1]= location[2]= 0;
    axis[0]= 1; axis[1]= 0; axis[2]= 0;
    torsoH= height= bellrand(60.0, 72.0);
    torsoR= radius= bellrand(12.5, 17.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    leglength= bellrand(58.0, 70.0);
    location[0]= torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
       /* this leg might be canted forward up to 30 degrees: */
    axis[0]= bellrand(0.0,0.5);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 4.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 4.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= 0;
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 4.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= -torsoH/2;
    location[1]= -torsoR;
    location[2]= -torsoR - leglength/2;
    axis[0]= bellrand(0.0,0.5);
    axis[1]= 0;
    axis[2]= -1;
    height= leglength;
    radius= bellrand(2.0, 4.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(45.0, 55.0);
    location[0]= torsoH/2 + height/2.828;
    location[1]= 0;
    location[2]= torsoR + height/2.828;
    axis[0]= 1;
    axis[1]= 0;
    axis[2]= 1;
    radius= bellrand(5.0, 9.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    location[0]= torsoH/2 + height/1.414; /* height is neck length */
    location[1]= 0;
    location[2]= torsoR + height/1.414;
    axis[0]= 1;
    axis[1]= bellrand(-1.0, 1.0);    /* he's looking to the right or left */
    axis[2]= 0;
    height= bellrand(18.0, 22.0);
    radius= bellrand(3.5, 5.5);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

    height= bellrand(20.0, 25.0);    /* a short tailed giraffe */
    location[0]= -torsoH + height;
    location[1]= 0;
    location[2]= 0;
    axis[0]= -1.0;
    axis[1]= bellrand(-1.0,1.0);   /* pointing any which way */
    axis[2]= bellrand(-1.0,0.0);
    radius= bellrand(0.5, 1.0);
    texture= bellrand(170.0, 180.0);
    printpart(height, radius, texture, axis, location);

} /* end of makegee */

void printpart(float h, float r, int t, float axis[], float loc[])
{
    printf("%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%d",
            loc[0], loc[1], loc[2], axis[0], axis[1], axis[2], h, r, t);
} /* end of printpart */

float bellrand(float st, float fin)
{
    float interval;

    interval= (fin-st)/5;
    switch (rand3()) {
        case 1: return(Random(st, fin));
        case 2: return(Random(st+interval, fin-interval));
        case 3: return(Random(st+2*interval, fin-2*interval));
        default: printf("what the hell???/n"); exit(0);
    }
}

#define    MOD 65537
#define    MULT 25173
#define    INC 13849

#define    ABS(x) ((x>0) ? x : -x)

float Random(float st, float fin)
{
    float  range;
    float  tmp;
    range = fin - st;

    seed = (MULT * seed + INC) % MOD; 
    tmp = ABS( seed / (float)MOD ) ;
    return (tmp * range + st);

} /* end of Random */

int rand3()
{
    seed = (MULT *seed + INC) %MOD;
    return ( ABS(seed / (float)MOD ) * 3.0 + 1.0);
}

int rand4()
{
    seed = (MULT *seed + INC) %MOD;
    return ( ABS(seed / (float)MOD ) * 4.0 + 1.0);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值