Last active
February 9, 2019 05:32
-
-
Save nasser/41f76109b3f0842218b4c11a7b3a103a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; based on https://rosettacode.org/wiki/Julia_set#C.23 | |
;; no idea why System.Drawing.dll is not normally findable, this should be | |
;; (import "System.Drawing") | |
(import-from "/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll") | |
(use "System.Drawing") | |
(use "System.Drawing.Imaging") | |
(defn >> [^Int32 x ^Int32 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (ldc-i4-s (const 31b)) (and) (shr))) | |
(defn & [^Int32 x ^Int32 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (and))) | |
(defn & [^Int32 x ^Int64 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (conv-i4) (and))) | |
(defn >> [^Int32 x ^Int64 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (conv-i4) (ldc-i4-s (const 31b)) (and) (shr))) | |
(defn jn.core/multiply [^Int32 x ^Int64 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (conv-i4) (mul))) | |
(defn jn.core/multiply [^Int32 x ^Int32 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (mul))) | |
(defn jn.core/multiply [^Double x ^Int32 y] | |
(cil* Int32 (ldarg-0) (ldarg-1) (conv-r8) (mul))) | |
(defn / [^Int32 x ^Int64 y] | |
(cil* Double (ldarg-0) (conv-r8) (ldarg-1) (conv-r8) (div))) | |
(defn / [^Double x ^Int32 y] | |
(cil* Double (ldarg-0) (ldarg-1) (conv-r8) (div))) | |
(defn jn.core/- [^Int32 x ^Double y] | |
(cil* Double (ldarg-0) (conv-r8) (ldarg-1) (sub))) | |
(defn jn.core/- [^Double x ^Double y] | |
(cil* Double (ldarg-0) (ldarg-1) (sub))) | |
(defn jn.core/add [^Double x ^Int32 y] | |
(cil* Double (ldarg-0) (ldarg-1) (conv-r8) (add))) | |
(defn jn.core/< [^Double x ^Int64 y] | |
(cil* Boolean (ldarg-0) (ldarg-1) (conv-r8) (clt))) | |
(defn color [^Int32 c] | |
(Color/FromArgb | |
(* (>> c 5) 36) | |
(* (& (>> c 3) 7) 36) | |
(* (& c 3) 85))) | |
(defn julia [] | |
(let [w 500i | |
h 400i | |
zoom 1i | |
maxiter 255i | |
move-y 0i | |
move-x 0i | |
cx -.7 | |
cy .27015 | |
bmp (Bitmap w h)] | |
(do | |
(loop [x 0i] | |
(when (< x w) | |
(loop [y 0i] | |
(when (< y h) | |
(loop [zx (+ (/ (* 1.5 (- x (/ w 2))) | |
(* .5 zoom w)) | |
move-x) | |
zy (+ (/ (* 1.0 (- y (/ h 2))) | |
(* .5 zoom h)) | |
move-y) | |
i maxiter] | |
(if (and (< (+ (* zx zx) (* zy zy)) 4) | |
(< 1i i)) | |
(recur | |
(+ cx (- (* zx zx) | |
(* zy zy))) | |
(+ cy (* 2. zx zy)) | |
(dec i)) | |
(.SetPixel bmp x y (color i)))) | |
(recur (inc y)))) | |
(recur (inc x)))) | |
(.Save bmp "julia.png")))) | |
(julia) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using jn; | |
using Jn; | |
using System; | |
using System.Drawing; | |
using System.Reflection; | |
[assembly: System.Reflection.AssemblyVersion("0.0.0.0")] | |
public static class user | |
{ | |
static user() | |
{ | |
// Note: this type is marked as 'beforefieldinit'. | |
Journal.importAssembly(System.Reflection.Assembly.LoadFile("/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll")); | |
core.use("System.Drawing"); | |
core.use("System.Drawing.Imaging"); | |
user.julia(); | |
} | |
public static int >>(int x, int y) | |
{ | |
return x >> y; | |
} | |
public static int &(int x, int y) | |
{ | |
return x & y; | |
} | |
public static int &(int x, long y) | |
{ | |
return x & (int)y; | |
} | |
public static int >>(int x, long y) | |
{ | |
return x >> (int)y; | |
} | |
public static double /(int x, long y) | |
{ | |
return (double)x / (double)y; | |
} | |
public static double /(double x, int y) | |
{ | |
return x / (double)y; | |
} | |
public static Color color(int c) | |
{ | |
return Color.FromArgb((c >> (int)5L) * (int)36L, (c >> (int)3L & (int)7L) * (int)36L, (c & (int)3L) * (int)85L); | |
} | |
public static void julia() | |
{ | |
int num = 500; | |
int num2 = 400; | |
int num3 = 1; | |
int num4 = 255; | |
int num5 = 0; | |
int num6 = 0; | |
double num7 = -0.7; | |
double num8 = 0.27015; | |
Bitmap bitmap = new Bitmap(num, num2); | |
for (int i = 0; i < num; i++) | |
{ | |
for (int j = 0; j < num2; j++) | |
{ | |
double num9 = 1.5 * jn.core.-(i, user./(num, 2L)) / (0.5 * (double)(num3 * num)) + (double)num6; | |
double num10 = 1.0 * jn.core.-(j, user./(num2, 2L)) / (0.5 * (double)(num3 * num2)) + (double)num5; | |
int num11 = num4; | |
while (core.and(num9 * num9 + num10 * num10 < (double)4L, 1 < num11)) | |
{ | |
double arg_F8_0 = num7 + (num9 * num9 - num10 * num10); | |
double arg_F6_0 = num8 + 2.0 * (num9 * num10); | |
num11--; | |
num10 = arg_F6_0; | |
num9 = arg_F8_0; | |
} | |
bitmap.SetPixel(i, j, user.color(num11)); | |
} | |
} | |
bitmap.Save("julia.png"); | |
} | |
} | |
public static class jn | |
{ | |
public static class core | |
{ | |
public static int multiply(int x, long y) | |
{ | |
return x * (int)y; | |
} | |
public static int multiply(int x, int y) | |
{ | |
return x * y; | |
} | |
public static int multiply(double x, int y) | |
{ | |
return (int)(x * (double)y); | |
} | |
public static double -(int x, double y) | |
{ | |
return (double)x - y; | |
} | |
public static double -(double x, double y) | |
{ | |
return x - y; | |
} | |
public static double add(double x, int y) | |
{ | |
return x + (double)y; | |
} | |
public static bool <(double x, long y) | |
{ | |
return x < (double)y; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment