File:Coloured Voronoi 3D slice.png

Coloured_Voronoi_3D_slice.png(333 × 333 像素,檔案大細:26 KB ,MIME類型:image/png

Transferred from en.wikipedia to Commons by Maksim.

The original description page was here. All following user names refer to en.wikipedia.

Coloured slice of a 3D Voronoi diagram, made by me.

GNU head 根據自由軟體基金會發佈嘅無固定段落、封面文字同封底文字GNU自由文件授權條款第1.2或打後嘅版本,你獲授權可以重製、散佈同埋修改爾份文件。授權條款嘅副本喺章節GNU自由文件授權條款
w:en:Creative Commons
署名 相同方式分享
呢個檔案用共享創意 姓名標示-非商業性-相同方式分享3.0 未本地化版本條款授權。
你可以:
  • 去分享 – 複製、發佈同傳播呢個作品
  • 再改 – 創作演繹作品
要遵照下面嘅條件:
  • 署名 – 你一定要畀合適嘅表彰、畀返指向呢個授權條款嘅連結,同埋寫明有無改過嚟。你可以用任何合理方式去做,但唔可以用任何方式暗示授權人認可咗你或者你嘅使用方式。
  • 相同方式分享 – 如果你用任何方式改過呢個作品,你必須要用返原本或者相似嘅條款發佈。
This licensing tag was added to this file as part of the GFDL licensing update.

//

GNU head

This work is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This work is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See version 2 and version 3 of the GNU General Public License for more details.

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

#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825
#define PI2 (PI*2)
#define SQ2 1.414213562373095048801688724209698078569671875376948073176679737990732478462
#define FI 1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204

/*
#define SX 666
#define SY 666
#define NPT 100
#define RSD 666
#define V3D 0
*/
#define SX 666
#define SY 666
#define NPT 1000
#define RSD 1923879
#define V3D 1


#define BPL ((SX*3+3)&~3)

void seedr(unsigned int);
unsigned int rnd();
unsigned int rndm(unsigned int);

unsigned char bhdr[54]={
0x42, 0x4D, 0x36, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

unsigned char po[BPL];

double gr[SY][SX][3];

void drawit();

int main(int a, char **b) {
  FILE *o;
  int x, y, c;
  double t;
  char *p;

  srand(time(0));
  drawit();
  
  p=bhdr+2; *p++=x=54+BPL*SY; *p++=x>>=8; *p++=x>>=8; *p=x>>=8;
  p=bhdr+18; *p++=x=SX; *p++=x>>=8; *p++=x>>=8; *p++=x>>=8;
  *p++=x=SY; *p++=x>>=8; *p++=x>>=8; *p=x>>=8;

  if(!(o=fopen("voronoi.bmp", "wb"))) {
    fclose(o);
    printf("Couldn't open output file.\n");
    return(0);
  }
  
  fwrite(bhdr, 54, 1, o);

  for(x=SX*3;x<BPL;++x) po[x]=0;
  
  for(y=SY-1;~y;--y) {
    for(x=0,p=po;x<SX;++x) for(c=2;~c;--c) *p++=(t=gr[y][x][c])<=0?0:(t>=1?255:t*255);
    fwrite(po, BPL, 1, o);
  }

  fclose(o);
  return(0);
}


int ptx[NPT], pty[NPT], ptz[NPT];
double ptc[NPT][3];

void drawit() {
  int x, y, c, n, bn, dx, dy, dz;
  unsigned int m, p;
  seedr(RSD);
  for(n=0;n<NPT;++n) {
    ptx[n]=rndm(SX); pty[n]=rndm(SX); ptz[n]=(!!V3D)*(rndm(SX)-SX/2);
    for(c=0;c<3;++c) ptc[n][c]=rnd()/(double)~0u;
  }
  for(y=0;y<SY;++y) for(x=0;x<SY;++x) {
    for(n=0,m=~0;n<NPT;++n) {
      dx=x-ptx[n]; dy=y-pty[n]; dz=-ptz[n]; p=dx*dx+dy*dy+dz*dz;
      if(p<m) { m=p; bn=n; }
    }
    for(c=0;c<3;++c) gr[y][x][c]=ptc[bn][c];
  }
  if(!V3D)
    for(n=0;n<NPT;++n)
      for(y=-1+!pty[n];y<=1-(pty[n]==SY-1);++y)
        for(x=-1+!ptx[n];x<=1-(ptx[n]==SX-1);++x)
          for(c=0;c<3;++c)
            gr[pty[n]+y][ptx[n]+x][c]=0;
}

unsigned int rseeda[624];
int rseedu;

void seedr(unsigned int s) {
  int n;
  rseedu=624; rseeda[0]=s; for(n=1;n<624;++n) rseeda[n]=s*=69069u;
}

#define TEMPBLAH(x,y,z) { v=(rseeda[x]&0x80000000)|(rseeda[y]&0x7fffffff);\
                          rseeda[x]=rseeda[z]^(v>>1)^(0x9908b0df&(0-(v&1)));}
void gennewr() {
  int n;
  unsigned int v;
  for(n=0;n<227;++n) TEMPBLAH(n, n+1, n+397);
  for(;n<623;++n) TEMPBLAH(n, n+1, n-227);
  TEMPBLAH(623, 0, 396);
  rseedu=0;
}
#undef TEMPBLAH

unsigned int rnd() {
  if(rseedu>=624) gennewr();
  unsigned int v=rseeda[rseedu++];
  v^=v>>11;
  v^=(v<<7)&0x9d2c5680;
  v^=(v<<15)&0xefc60000;
  v^=v>>18;
  return(v);
}

unsigned int rndm(unsigned int m) {
  unsigned int v, c=(0u-m)/m;
  while((v=rnd())/m>c);
  return(v%m);
}

//
date/time username edit summary
20:18, 14 October 2004 en:User:Cyp (+Image generator source code, made by me)
20:16, 14 October 2004 en:User:Cyp (Coloured slice of a 3D Voronoi diagram, made by me. {{GFDL}})

Original upload log

Legend: (cur) = this is the current file, (del) = delete this old version, (rev) = revert to this old version.

Click on date to download the file or see the image uploaded on that date.

  • (del) (cur) 20:16, 14 October 2004 . . en:User:Cyp Cyp ( en:User_talk:Cyp Talk) . . 333x333 (27132 bytes) (Coloured slice of a 3D Voronoi diagram, made by me. { { GFDL } })

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

圖中顯示嘅係

image/png

5a88b138ac30ea0ea67c10ca77189464e6fe7c26

27,132 字節

333 像素

333 像素

檔案歷史

撳個日期/時間去睇響嗰個時間出現過嘅檔案。

日期/時間縮圖尺寸用戶註解
現時2006年3月20號 (一) 19:50響2006年3月20號 (一) 19:50嘅縮圖版本333 × 333(26 KB)MaksimLa bildo estas kopiita de wikipedia:en. La originala priskribo estas: Coloured slice of a 3D Voronoi diagram, made by me. {{GFDL}} //{{GPL}}<pre> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> #define PI 3.14159265358979323

無嘢連來呢份檔案。

全域檔案使用情況