All Projects → rafgraph → Fractal

rafgraph / Fractal

Licence: gpl-3.0
Mandelbrot fractal generator - js web app, uses zero libraries

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fractal

Fractal.parts
❄️ build and view fractals
Stars: ✭ 21 (-75.86%)
Mutual labels:  fractal
Git Anger Management
Ever wanted to know just how angry your commits are? Look no further
Stars: ✭ 49 (-43.68%)
Mutual labels:  fun
Simplepyscripts
Collection of various python script's.
Stars: ✭ 67 (-22.99%)
Mutual labels:  fun
Langterm
🕹️ WebGL-based VT220 emulator, made as a learning example and frontend for a text adventure
Stars: ✭ 35 (-59.77%)
Mutual labels:  fun
Remixbot
A multifunctional Discord bot in development that allows you to easily control your discord server.
Stars: ✭ 39 (-55.17%)
Mutual labels:  fun
Nitro
A discord bot
Stars: ✭ 56 (-35.63%)
Mutual labels:  fun
Catimg
🦦 Insanely fast image printing in your terminal
Stars: ✭ 880 (+911.49%)
Mutual labels:  fun
Spicy Proton
Generate a random English adjective-noun word pair in Ruby
Stars: ✭ 76 (-12.64%)
Mutual labels:  fun
Art
🎨 ASCII art library for Python
Stars: ✭ 1,026 (+1079.31%)
Mutual labels:  fun
Awesome Hilarious Repos
Awesome hilarious github repositories
Stars: ✭ 62 (-28.74%)
Mutual labels:  fun
Games
Your own games website, filled with open source goodness! Automated installation of a plethora of open source web games. Fully customizable.
Stars: ✭ 35 (-59.77%)
Mutual labels:  fun
Make Me Lol
😄 A command-line tool to make you laugh
Stars: ✭ 38 (-56.32%)
Mutual labels:  fun
Pizza Cli
🍕 Order a pizza in a CLI app (just for fun!)
Stars: ✭ 58 (-33.33%)
Mutual labels:  fun
Hacktoberchallenges2018
Welcome! I need some help making my list... Learn how in the README
Stars: ✭ 35 (-59.77%)
Mutual labels:  fun
Gobrot
Mandelbrot image renderer in Go
Stars: ✭ 70 (-19.54%)
Mutual labels:  fractal
Hyperbeast
Supreme Terminal prompt
Stars: ✭ 20 (-77.01%)
Mutual labels:  fun
Generative Designs
A collection of generative design React components
Stars: ✭ 51 (-41.38%)
Mutual labels:  fun
Animated Stars Android
Draw animated stars on Android view canvas - written in Kotlin
Stars: ✭ 85 (-2.3%)
Mutual labels:  fun
Cl Aristid
Draw Lindenmayer Systems with Common LISP!
Stars: ✭ 74 (-14.94%)
Mutual labels:  fractal
Fractalart
Generate colorful wallpapers!
Stars: ✭ 61 (-29.89%)
Mutual labels:  fractal

Mandelbrot Fractal Generator

https://fractal.rafgraph.dev

JavaScript app that draws the Mandelbrot fractal and allows you to zoom in and explore the fractal (uses zero libraries). Launches in fullscreen mode for maximum impact on desktop, and has a responsive mobile compatible design with a multi-touch interface on mobile devices.

fractal-screenshot-from-iphone6-1

The coloring algorithm adjusts to the number of colors needed (i.e. the maximum escape time for the Mandelbrot set generation). See below for more info on the coloring algorithm.

By default the maximum escape time is 224, but you can select 448, 896, or 1792 via the higher escape time links on the launch page. Note that if you zoom in on the fractal and exit back to the launch page, and then select a different escape time, it will launch and redraw the fractal in the same place that you had zoomed in on, just with a different maximum escape time (and different coloring).

The code is split into two independent parts: app.js and fractal.js. The app handles all the setup and user interaction, and communicates these to the fractal using the fractal's api. The fractal just calculates and draws itself based on the settings it receives from the app.

Screenshots

Captured on iPhone 6

fractal-screenshot-from-iphone6-1

fractal-screenshot-from-iphone6-2

fractal-screenshot-from-iphone6-3

fractal-screenshot-from-iphone6-4

fractal-screenshot-from-iphone6-5

fractal-screenshot-from-iphone6-6

fractal-screenshot-from-iphone6-7

fractal-screenshot-from-iphone6-8

fractal-screenshot-from-iphone6-9

Fractal API

fractal.js is designed to work independently from app.js and can easily be integrated into any project. It provides an api through its update function, which takes an options object that instructs the fractal how to adjust itself before it re-renders.

// create fractal object, send it an HTML canvas element
// on which it will draw itself
var fractal = new Fractal(fractalCanvasElement);

// tell the fractal to update itself based on the options sent
// it will only redraw itself if necessary
fractal.update(options);
// fractal api as an options object
// all keys are optional
var options = {

  // set size of canvas
  // set pixel width of canvas
  pxWidth: number, // e.g. 2880

  // set pixel height of canvas
  pxHeight: number, // e.g. 1800


  // reset to default settings (coordinates, max escape time, and
  // starting options - does not reset canvas size)
  defaults: true,

  // reset to default cartesian coordinates (shows the whole fractal)
  resetToDefaultCords: true,

  // draw the fractal at these specific cartesian coordinates
  cords: {  
    xCartMin: number, // e.g. -2.1
    xCartMax: number, // e.g. 0.8,
    yCartMin: number, // e.g. -1.2,
    yCartMax: number // e.g. 1.2
  },

  // set the maximum escape time
  // numbers < 14 will be converted to 14
  // numbers > 1792 will be converted to 1792
  maxEscapeTime: number, // e.g. 224

  // pixel coordinates on canvas of point to zoom in on
  zoomInPxPoint: {
    xPx: number, // e.g. 100
    yPx: number // e.g. 100
  },

  // pixel coordinates on canvas of point to zoom out from
  zoomOutPxPoint: {
    xPx: number, // e.g. 100
    yPx: number // e.g. 100
  },

  // pixel coordinates of rectangle on canvas to zoom in on
  zoomInPxBox: {
    xPxMin: number, // e.g. 50
    xPxMax: number, // e.g. 100
    yPxMin: number, // e.g. 50
    yPxMax: number // e.g. 100
  },

  // set the current options as the starting options
  // the fractal resets to its starting options when told to reset
  setAsStartingOptions: bool, // e.g. true

  // reset cartesian coordinates to starting cartesian coordinates
  resetCords: bool, // e.g. true

  // reset the max escape time to the starting max escape time
  resetMaxEscapeTime: bool, // e.g. true

  // draw with distortion if the ratio of canvas width/height doesn't
  // match the ratio of cartesian coordinates width/height
  // by default (if this is omitted or false) the cartesian coordinates are
  // adjusted to match the ratio of the canvas width/height to avoid distortion
  distortion: bool // e.g. true

}

Coloring Algorithm

Start with 2 of the 3 red, green and blue values fixed at either 0 or 255, then increase the other R, G or B value in a given number of increments based on the number of colors needed, repeat this for seven cases and you get a maximum of 1792 colors (7*256). Note that white repeats 3 times, at the end of cases 2, 4 and 6.

The seven case are:
case 0: R=0, B=0, increase green from 0 to 255
case 1: R=0 G=255, increase blue from 0 to 255
case 2: G=255, B=255, increase red form 0 to 255
case 3: G=0, B=255, increase red from 0 to 255
case 4: R=255, B=255, increase green from 0 to 255
case 5: R=255, B=0, increase green from 0 to 255
case 6: R=255, G=255, increase blue from 0 to 255

Fractal.prototype.rgbNum = function(escapeTime){
  if (escapeTime <= 2) {
    //pin all escape times less than 3 to black
    return [0, 0, 0];
  } else if (escapeTime === this.maxEscapeTime) {
    //normally this would be white, but that's too much white, so override
    return [0, 25, 0];
  }

  var redNum;
  var greenNum;
  var blueNum;
  var rgbIncrements = Math.floor(((this.maxEscapeTime) / 7));
  var caseNum = Math.floor(escapeTime / rgbIncrements);
  var remainNum = escapeTime % rgbIncrements;

  switch (caseNum) {
    case 0:
      redNum = 0;
      greenNum = Math.floor(256 / rgbIncrements) * remainNum;
      blueNum = 0;
      break;
    case 1:
      redNum = 0;
      greenNum = 255;
      blueNum = Math.floor(256 / rgbIncrements) * remainNum;
      break;
    case 2:
      redNum = Math.floor(256 / rgbIncrements) * remainNum;
      greenNum = 255;
      blueNum = 255;
      break;
    case 3:
      redNum = Math.floor(256 / rgbIncrements) * remainNum;
      greenNum = 0;
      blueNum = 255;
      break;
    case 4:
      redNum = 255;
      greenNum = Math.floor(256 / rgbIncrements) * remainNum;
      blueNum = 255;
      break;
    case 5:
      redNum = 255;
      greenNum = Math.floor(256 / rgbIncrements) * remainNum;
      blueNum = 0;
      break;
    case 6:
      redNum = 255;
      greenNum = 255;
      blueNum = Math.floor(256 / rgbIncrements) * remainNum;
      break;
  }

  return [redNum, greenNum, blueNum];
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].