Skip to content

Instantly share code, notes, and snippets.

@palmenros
Last active March 20, 2017 18:28
Show Gist options
  • Save palmenros/30c5a730b2ddee678701d9f541b50321 to your computer and use it in GitHub Desktop.
Save palmenros/30c5a730b2ddee678701d9f541b50321 to your computer and use it in GitHub Desktop.
Leva
void drawPoint(float centerX, float centerY, float angle, float radius){
float x = radius * cos(angle);
float y = radius * sin(angle);
point(x + centerX, 700 - y - centerY);
}
float offset = 200;
float max = 100;
float getRadius(float angle){
if(angle <= HALF_PI){
return offset + max;
} else if( angle <= PI){
angle -= HALF_PI;
float rad = angle * max / HALF_PI;
return (max - rad) + offset;
} else if (angle <= (3*HALF_PI)){
return offset;
} else {
angle -= 3* HALF_PI;
float rad = angle * max / HALF_PI;
return rad + offset;
}
}
void patternLine(int xStart, int yStart, int xEnd, int yEnd, int linePattern, int lineScale) {
int temp, yStep, x, y;
int pattern = linePattern;
int carry;
int count = lineScale;
boolean steep = (abs(yEnd - yStart) > abs(xEnd - xStart));
if (steep == true) {
temp = xStart;
xStart = yStart;
yStart = temp;
temp = xEnd;
xEnd = yEnd;
yEnd = temp;
}
if (xStart > xEnd) {
temp = xStart;
xStart = xEnd;
xEnd = temp;
temp = yStart;
yStart = yEnd;
yEnd = temp;
}
int deltaX = xEnd - xStart;
int deltaY = abs(yEnd - yStart);
int error = - (deltaX + 1) / 2;
y = yStart;
if (yStart < yEnd) {
yStep = 1;
} else {
yStep = -1;
}
for (x = xStart; x <= xEnd; x++) {
if ((pattern & 1) == 1) {
if (steep == true) {
point(y, x);
} else {
point(x, y);
}
carry = 0x8000;
} else {
carry = 0;
}
count--;
if (count <= 0) {
pattern = (pattern >> 1) + carry;
count = lineScale;
}
error += deltaY;
if (error >= 0) {
y += yStep;
error -= deltaX;
}
}
}
void drawDivisions(float divNum){
for(float a = 0; a <= TWO_PI; a += (TWO_PI / divNum)){
float x = 495 * cos(a);
float y = 495 * sin(a);
patternLine(350, 350, int(x + 350), int(700 - y - 350), 0x5555, 10);
}
}
void setup(){
size(700, 700);
background(255);
stroke(0);
strokeWeight(2);
print(sin(HALF_PI));
for(float a = 0; a <= 2 * PI; a += 0.001){
drawPoint(350, 350, a, getRadius(a));
}
strokeWeight(0.5);
drawDivisions(32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment