Changes

Jump to: navigation, search

TriForce

152 bytes added, 10:42, 8 March 2019
Assignment 1: Julia Set
|-
|
/** * Julia.cpp * Vincent Terpstra * Feb 18 / 2019 * Functions to display a Mandlebrot set */
#include <iostream> #include <math.h> #include "Bitmap.h"
#define MAXCYCLES 1000 #define ITER 1 #define PI 3.14159
void calcJulia(int* array, int width, int height, float jR, float jI); void createBMP(int* array, int width, int height);
int main(int size, const char ** args) { int height = (size > 1) ? atoi(args[1]) : 1000; int width = height / 2 * 3;
int * array = new int[height * width]; float jI = -0.4f; float jR = 0.6f; float angle = 2.0f / ITER * PI; float cosA = cos(angle); float sinA = sin(angle); for(int i = 0; i < ITER; i++){ calcJulia(array, width, height, jI, jR); createBMP(array, width, height); //rotate the Julia point float tmp = jI; jI = cosA * jI - sinA * jR; jR = cosA * jR + sinA * tmp; } delete[] array; return 0; } /** * calcDepth * finds the escape value of the Julia set * inputs sR, sI: starting position on the map * jR, jI: values of the julia set * exits when |s| > 2 or reached MAXCYCLES * return the */ int calcDepth(float sR, float sI, const float jR, const float jI){ int cycle = 0; while(sR * sR + sI * sI <= 4 && ++cycle < MAXCYCLES){ // s(next) = s * s + j float tmp = sR; sR = sR * sR - sI * sI + jR; sI = 2 * tmp * sI + jI; } return cycle; }
//rotate the Julia point float tmp = jI; jI = cosA * jI - sinA * jR; jR = cosA * jR + sinA * tmp; }  delete[] array; return 0;}/** * calcDepth * finds the escape value of the Julia set * inputs sR, sI: starting position on the map * jR, jI: values of the julia set * exits when |s| > 2 or reached MAXCYCLES * return the */int calcDepth(float sR, float sI, const float jR, const float jI){ int cycle = 0; while(sR * sR + sI * sI <= 4 && ++cycle < MAXCYCLES){ // s(next) = s * s + j float tmp = sR; sR = sR * sR - sI * sI + jR; sI = 2 * tmp * sI + jI; } return cycle;} /** * calcJulia * Function to calculate the values from (-1.5, 1.5),(-1, 1) in the Julia set * saves the values onto the array */ void calcJulia(int * array, int width, int height, const float jR, const float jI){
float delta = 2 / (float)height;
float x, y = -1;
y += delta;
}
}
struct Pix {
float val;
int r, g, b;
Pix(float val, int r, int g, int b) :
val(val), r(r), g(g), b(b) {}
};
bool lerp(float clr, Pix& first, Pix& second, Bitmap & map);
/** * createBMP * maps the values in the array to a .bmp file * linear interpolates between color values */ void createBMP(int * array, int width, int height){
static int idx = 0;
char name[] = "julia000.bmp";
lerp(clr, clr2, clr3, map);
}
}
/** * Function to linearly interpolate color values and draw to the Bitmap */ bool lerp(float clr, Pix& first, Pix& second, Bitmap & map){
if(clr <= second.val){
float diff = (clr - first.val) / (second.val - first.val);
}
return false;
}
|}
To view the full c++ code [https://github.com/vincent-terpstra/julia-sets github link]

Navigation menu