File:Rational coords ordering.gif
Rational_coords_ordering.gif (512 × 512 pixels, file size: 390 KB, MIME type: image/gif, looped, 1,000 frames, 50 s)
Note: Due to technical limitations, thumbnails of high resolution GIF images such as this one will not be animated. The limit on Wikimedia Commons is width × height × number of frames ≤ 100 million.
Captions
Summary
[edit]DescriptionRational coords ordering.gif |
English: This is an animation I made which shows one possible ordering of all infinitely many 2D rational coordinates (first 1000 coordinates are shown). If we take the traditional ordering of rational numbers (i.e. 0, 1, 1/2, 2, 3, 1/3, 1/4, ...) and index them as C0, C1, C2, C3, ... we can order pairs of these indices the same way to get ordered coordinates, i.e. [C1,C1], [C1, C2], [C2,C1], [C3,C1], [C2,C2] etc. The animation was made with C, libcairo and GIMP. I release it to the public domain under CC0 1.0. |
Date | |
Source | Own work |
Author | Drummyfish |
Source code InfoField | /* Generates animation of ordering rational 2D coordinates. By drummyfish,
released under CC0 1.0, public domain. */
#include <cairo.h>
#define W 512
#define H 512
#define S 10.0 // scale
#define LW 0.1 // line width
#define C1 0.5,0.5,0.5 // color 1
#define C2 1.0,0,0
#define C3 0.7,0.7,0.8
#define N 20 // number of coords to plot
cairo_surface_t *s;
cairo_t *c;
int isSimplified(int nom, int den)
{
int divisor = 2;
while (divisor <= nom && divisor <= den)
{
if (nom % divisor == 0 && den % divisor == 0)
return 0;
divisor++;
}
return 1;
}
void nThPair(int n, int *a, int *b, int skipSimplified)
{
*a = 0;
*b = 1;
if (n == 0)
return;
n--;
int state = 0;
*a = 1;
while (n > 0)
{
switch (state)
{
case 0: (*a)++; state = 1; break;
case 1:
(*a)--;
(*b)++;
if (*a == 1)
state = 2;
break;
case 2: (*b)++; state = 3; break;
case 3:
(*a)++;
(*b)--;
if (*b == 1)
state = 0;
break;
default: break;
}
if (!skipSimplified || isSimplified(*a,*b))
n--;
}
}
void nThRational(int n, int *nom, int *den)
{
nThPair(n,nom,den,1);
}
void nThCoord(int n, int *xNom, int *xDen, int *yNom, int *yDen)
{
int a, b;
nThPair(n + 1,&a,&b,0);
nThRational(a - 1,xNom,xDen);
nThRational(b - 1,yNom,yDen);
}
void line(double x1, double y1, double x2, double y2, double w,
double r, double g, double b)
{
cairo_set_operator(c,CAIRO_OPERATOR_DARKEN);
cairo_set_source_rgb(c,r,g,b);
cairo_set_line_width(c,w);
cairo_move_to(c,x1,S - y1);
cairo_line_to(c,x2,S - y2);
cairo_stroke(c);
cairo_set_operator(c,CAIRO_OPERATOR_OVER);
}
void point(double x, double y, double rad, double r, double g, double b)
{
cairo_set_source_rgb(c,r,g,b);
cairo_arc(c,x,S - y,rad,0,2 * 3.1415);
cairo_fill(c);
}
int main(void)
{
s = cairo_image_surface_create(CAIRO_FORMAT_RGB24,W,H);
c = cairo_create(s);
cairo_scale(c,W / S,H / S);
cairo_set_source_rgb(c, 1, 1, 1);
cairo_paint(c);
line(0,0,0,S,LW,C1);
line(0,0,S,0,LW,C1);
for (int i = 0; i < S; ++i)
{
line(i,0,i,0.2,LW,C1);
line(0,i,0.2,i,LW,C1);
}
double xPrev = 0, yPrev = 0;
for (int i = 0; i < 1000; ++i)
{
char fileName[] = "frames/frame0000.png";
fileName[12] += (i / 1000) % 10;
fileName[13] += (i / 100) % 10;
fileName[14] += (i / 10) % 10;
fileName[15] += i % 10;
cairo_surface_write_to_png(s,fileName);
int x1, y1, x2, y2;
nThCoord(i,&x1,&y1,&x2,&y2);
double x = ((double) x1) / ((double) y1),
y = ((double) x2) / ((double) y2);
line(xPrev,yPrev,x,y,LW / 4,C3);
point(xPrev,yPrev,0.05,C2);
point(x,y,0.05,C2);
xPrev = x;
yPrev = y;
}
cairo_destroy(c);
cairo_surface_destroy(s);
return 0;
}
|
Licensing
[edit]This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 12:08, 7 April 2023 | 512 × 512 (390 KB) | Drummyfish (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following page uses this file:
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
GIF file comment | by drummyfish, released under CC0 1.0, public domain |
---|