Mandelbrot
This commit is contained in:
12
mandelbrot.iml
Normal file
12
mandelbrot.iml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaScript" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
185
mandelbrot.ipr
Normal file
185
mandelbrot.ipr
Normal file
@@ -0,0 +1,185 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="GradleLocalSettings">
|
||||
<option name="modificationStamps">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$/../../DestinationSol" value="5718836739744" />
|
||||
<entry key="$PROJECT_DIR$/../../simple/Simple-persistence" value="2890201693583" />
|
||||
<entry key="$PROJECT_DIR$/../../simple/Simple-web" value="2890212261770" />
|
||||
<entry key="$PROJECT_DIR$/../../simple/SimpleDatabase" value="2890191706466" />
|
||||
<entry key="$PROJECT_DIR$/../../simple/Very-simple-templates" value="2890190703434" />
|
||||
<entry key="$PROJECT_DIR$/../../simple/stats/simple-stats-server" value="2909544379158" />
|
||||
<entry key="$PROJECT_DIR$/../../work/Kos/KosConvertBranchcode" value="2904315467504" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="externalProjectsViewState">
|
||||
<projects_view />
|
||||
</option>
|
||||
</component>
|
||||
<component name="MavenImportPreferences">
|
||||
<option name="generalSettings">
|
||||
<MavenGeneralSettings>
|
||||
<option name="mavenHome" value="Bundled (Maven 3)" />
|
||||
</MavenGeneralSettings>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/mandelbrot.iml" filepath="$PROJECT_DIR$/mandelbrot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="index.html" type="JavascriptDebugType" factoryName="JavaScript Debug" nameIsGenerated="true" uri="http://localhost:63342/mandelbrot/web/index.html">
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="false" name="Mandelbrot" type="K2JSConfigurationType" factoryName="Kotlin (JavaScript - experimental)">
|
||||
<K2JSConfigurationSettings>
|
||||
<option name="browserFamily" value="Chrome" />
|
||||
<option name="generatedFilePath" value="$PROJECT_DIR$/web/js/generated" />
|
||||
<option name="pageToOpenFilePath" value="" />
|
||||
<option name="shouldOpenInBrowserAfterTranslation" value="false" />
|
||||
</K2JSConfigurationSettings>
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="GoToClass.includeLibraries" value="false" />
|
||||
<property name="GoToClass.toSaveIncludeLibraries" value="false" />
|
||||
<property name="GoToFile.includeJavaFiles" value="false" />
|
||||
<property name="MemberChooser.sorted" value="false" />
|
||||
<property name="MemberChooser.showClasses" value="true" />
|
||||
<property name="MemberChooser.copyJavadoc" value="false" />
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin">
|
||||
<module name="" />
|
||||
<option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" />
|
||||
<option name="PROGRAM_PARAMETERS" />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="true" type="Applet" factoryName="Applet">
|
||||
<option name="WIDTH" value="400" />
|
||||
<option name="HEIGHT" value="300" />
|
||||
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
|
||||
<module />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="true" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="VM_PARAMETERS" />
|
||||
<option name="PROGRAM_PARAMETERS" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<option name="ENABLE_SWING_INSPECTOR" value="false" />
|
||||
<option name="ENV_VARIABLES" />
|
||||
<option name="PASS_PARENT_ENVS" value="true" />
|
||||
<module name="" />
|
||||
<envs />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="true" type="JUnit" factoryName="JUnit">
|
||||
<module name="" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<option name="PACKAGE_NAME" />
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="METHOD_NAME" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="VM_PARAMETERS" value="-ea" />
|
||||
<option name="PARAMETERS" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
|
||||
<option name="ENV_VARIABLES" />
|
||||
<option name="PASS_PARENT_ENVS" value="true" />
|
||||
<option name="TEST_SEARCH_SCOPE">
|
||||
<value defaultName="singleModule" />
|
||||
</option>
|
||||
<envs />
|
||||
<patterns />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="true" type="Remote" factoryName="Remote">
|
||||
<option name="USE_SOCKET_TRANSPORT" value="true" />
|
||||
<option name="SERVER_MODE" value="false" />
|
||||
<option name="SHMEM_ADDRESS" value="javadebug" />
|
||||
<option name="HOST" value="localhost" />
|
||||
<option name="PORT" value="5005" />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration name="<template>" type="TestNG" default="true" selected="false">
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="VM_PARAMETERS" value="-ea" />
|
||||
<option name="PARAMETERS" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaScript">
|
||||
<CLASSES>
|
||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-jslib.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-jslib-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ProjectJDKs.UI">
|
||||
<settings>
|
||||
<last-edited>1.7</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
||||
110
src/MandelBrot.kt
Normal file
110
src/MandelBrot.kt
Normal file
@@ -0,0 +1,110 @@
|
||||
import org.w3c.dom.CanvasRenderingContext2D
|
||||
import org.w3c.dom.HTMLCanvasElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
import kotlin.browser.document
|
||||
import kotlin.browser.window
|
||||
|
||||
/**
|
||||
* User: rnentjes
|
||||
* Date: 21-5-16
|
||||
* Time: 17:06
|
||||
*/
|
||||
|
||||
class HTMLElements {
|
||||
val container: HTMLElement
|
||||
val canvas: HTMLCanvasElement
|
||||
val canvas2d: CanvasRenderingContext2D
|
||||
|
||||
var windowWidth = window.innerWidth.toInt()
|
||||
var windowHeight = window.innerHeight.toInt()
|
||||
|
||||
init {
|
||||
container = document.createElement("div") as HTMLElement
|
||||
|
||||
canvas = document.createElement("canvas") as HTMLCanvasElement
|
||||
|
||||
container.setAttribute("style", "position: relative;")
|
||||
canvas.setAttribute("style", "position: absolute; left: 0px; top: 0px; z-index: 10; width: 2000px; height: 1000px;" )
|
||||
|
||||
document.body!!.appendChild(container)
|
||||
container.appendChild(canvas)
|
||||
|
||||
canvas2d = canvas.getContext("2d") as CanvasRenderingContext2D
|
||||
}
|
||||
|
||||
fun resize() {
|
||||
windowWidth = window.innerWidth.toInt()
|
||||
windowHeight = window.innerHeight.toInt()
|
||||
|
||||
canvas.setAttribute("width", "${windowWidth}px")
|
||||
canvas.setAttribute("height", "${windowHeight}px")
|
||||
canvas.setAttribute("style", "position: absolute; left: 0px; top: 0px; z-index: 5; width: ${windowWidth}px; height: ${windowHeight}px;" )
|
||||
}
|
||||
|
||||
fun drawMandel() {
|
||||
/*
|
||||
For each pixel (Px, Py) on the screen, do:
|
||||
{
|
||||
x0 = scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
|
||||
y0 = scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
|
||||
x = 0.0
|
||||
y = 0.0
|
||||
iteration = 0
|
||||
max_iteration = 1000
|
||||
while (x*x + y*y < 2*2 AND iteration < max_iteration) {
|
||||
xtemp = x*x - y*y + x0
|
||||
y = 2*x*y + y0
|
||||
x = xtemp
|
||||
iteration = iteration + 1
|
||||
}
|
||||
color = palette[iteration]
|
||||
plot(Px, Py, color)
|
||||
}*/
|
||||
|
||||
var xs: Float
|
||||
var ys: Float
|
||||
var xx: Float
|
||||
var yy: Float
|
||||
var xt: Float
|
||||
var iteration: Int
|
||||
var max_iteration: Int = 511
|
||||
var halfWindowHeight = windowHeight / 2
|
||||
var red: Int
|
||||
var fillStyle: String
|
||||
|
||||
println("Window width: $windowWidth, height: $windowHeight, half: $halfWindowHeight")
|
||||
for (x in 0..windowWidth) {
|
||||
for (y in 0..halfWindowHeight) {
|
||||
xs = (3.5f / windowWidth.toFloat()) * x - 2.5f
|
||||
ys = 1f - ((1f / halfWindowHeight) * y)
|
||||
|
||||
xx = 0f
|
||||
yy = 0f
|
||||
iteration = 0
|
||||
while(xx*xx + yy*yy < 4 && iteration < max_iteration) {
|
||||
xt = xx*xx - yy*yy + xs
|
||||
yy = 2*xx*yy + ys
|
||||
xx = xt
|
||||
iteration++
|
||||
}
|
||||
fillStyle = "rgb(${(iteration * 2) % 256}, ${(iteration * 3) % 256}, ${(iteration) % 256})"
|
||||
if (iteration == max_iteration) {
|
||||
fillStyle = "rgb(0, 0, 0)"
|
||||
}
|
||||
//red =
|
||||
canvas2d.fillStyle = fillStyle
|
||||
canvas2d.fillRect(x.toDouble(), y.toDouble(), 1.0, 1.0)
|
||||
canvas2d.fillRect(x.toDouble(), windowHeight - y.toDouble(), 1.0, 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val html = HTMLElements()
|
||||
|
||||
html.resize()
|
||||
|
||||
html.drawMandel()
|
||||
}
|
||||
24
web/index.html
Normal file
24
web/index.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Mandelbrot</title>
|
||||
<style type="text/css">
|
||||
body, html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
canvas {
|
||||
position:absolute;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript" src="js/kotlin/kotlin.js"></script>
|
||||
<script type="application/javascript" src="js/generated/mandelbrot.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
70
web/js/generated/mandelbrot.js
Normal file
70
web/js/generated/mandelbrot.js
Normal file
@@ -0,0 +1,70 @@
|
||||
(function (Kotlin) {
|
||||
'use strict';
|
||||
var _ = Kotlin.defineRootPackage(null, /** @lends _ */ {
|
||||
HTMLElements: Kotlin.createClass(null, function () {
|
||||
var tmp$0, tmp$1, tmp$2, tmp$3;
|
||||
this.windowWidth = window.innerWidth | 0;
|
||||
this.windowHeight = window.innerHeight | 0;
|
||||
this.container = Kotlin.isType(tmp$0 = document.createElement('div'), HTMLElement) ? tmp$0 : Kotlin.throwCCE();
|
||||
this.canvas = Kotlin.isType(tmp$1 = document.createElement('canvas'), HTMLCanvasElement) ? tmp$1 : Kotlin.throwCCE();
|
||||
this.container.setAttribute('style', 'position: relative;');
|
||||
this.canvas.setAttribute('style', 'position: absolute; left: 0px; top: 0px; z-index: 10; width: 2000px; height: 1000px;');
|
||||
((tmp$2 = document.body) != null ? tmp$2 : Kotlin.throwNPE()).appendChild(this.container);
|
||||
this.container.appendChild(this.canvas);
|
||||
this.canvas2d = Kotlin.isType(tmp$3 = this.canvas.getContext('2d'), CanvasRenderingContext2D) ? tmp$3 : Kotlin.throwCCE();
|
||||
}, /** @lends _.HTMLElements.prototype */ {
|
||||
resize: function () {
|
||||
this.windowWidth = window.innerWidth | 0;
|
||||
this.windowHeight = window.innerHeight | 0;
|
||||
this.canvas.setAttribute('width', this.windowWidth.toString() + 'px');
|
||||
this.canvas.setAttribute('height', this.windowHeight.toString() + 'px');
|
||||
this.canvas.setAttribute('style', 'position: absolute; left: 0px; top: 0px; z-index: 5; width: ' + this.windowWidth + 'px; height: ' + this.windowHeight + 'px;');
|
||||
},
|
||||
drawMandel: function () {
|
||||
var tmp$0, tmp$1;
|
||||
var xs;
|
||||
var ys;
|
||||
var xx;
|
||||
var yy;
|
||||
var xt;
|
||||
var iteration;
|
||||
var max_iteration = 511;
|
||||
var halfWindowHeight = this.windowHeight / 2 | 0;
|
||||
var red;
|
||||
var fillStyle;
|
||||
Kotlin.println('Window width: ' + this.windowWidth + ', height: ' + this.windowHeight + ', half: ' + halfWindowHeight);
|
||||
tmp$0 = this.windowWidth;
|
||||
for (var x = 0; x <= tmp$0; x++) {
|
||||
tmp$1 = halfWindowHeight;
|
||||
for (var y = 0; y <= tmp$1; y++) {
|
||||
xs = 3.5 / this.windowWidth * x - 2.5;
|
||||
ys = 1.0 - 1.0 / halfWindowHeight * y;
|
||||
xx = 0.0;
|
||||
yy = 0.0;
|
||||
iteration = 0;
|
||||
while (xx * xx + yy * yy < 4 && iteration < max_iteration) {
|
||||
xt = xx * xx - yy * yy + xs;
|
||||
yy = 2 * xx * yy + ys;
|
||||
xx = xt;
|
||||
iteration++;
|
||||
}
|
||||
fillStyle = 'rgb(' + iteration * 2 % 256 + ', ' + iteration * 3 % 256 + ', ' + iteration % 256 + ')';
|
||||
if (iteration === max_iteration) {
|
||||
fillStyle = 'rgb(0, 0, 0)';
|
||||
}
|
||||
this.canvas2d.fillStyle = fillStyle;
|
||||
this.canvas2d.fillRect(x, y, 1.0, 1.0);
|
||||
this.canvas2d.fillRect(x, this.windowHeight - y, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
main_kand9s$: function (args) {
|
||||
var html = new _.HTMLElements();
|
||||
html.resize();
|
||||
html.drawMandel();
|
||||
}
|
||||
});
|
||||
Kotlin.defineModule('mandelbrot', _);
|
||||
_.main_kand9s$([]);
|
||||
}(Kotlin));
|
||||
1
web/js/generated/mandelbrot.meta.js
Normal file
1
web/js/generated/mandelbrot.meta.js
Normal file
@@ -0,0 +1 @@
|
||||
// Kotlin.kotlin_module_metadata(3, "mandelbrot", "H4sIAAAAAAAAAOPS4xKJd0lNSyzNKQlITM5OTE/Vy84qzhUSkxIRYJBiMmA04hFgluIQYhFiMmA2YOLK41JOgSjXLYCpzy/JycyLLy4pysxLjy9JTMpJFXLX5GLJTczM42KDyHKxhOZllnCxJBalF3OxOhYVJVZysQWDdchwMQkwcrFxMAgwSTCAaRYozSrBAAB2qhMjoAAAAA==");
|
||||
23870
web/js/kotlin/kotlin.js
Normal file
23870
web/js/kotlin/kotlin.js
Normal file
File diff suppressed because it is too large
Load Diff
1
web/js/kotlin/stdlib.meta.js
Normal file
1
web/js/kotlin/stdlib.meta.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user