-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement everything left for mandelbrot.
* RTime for Time; only #-, #to_s, .new() work for now * Return logic plus statement tweaks for non-expression nodes * While logic * Body-aware improvements to If logic * Slightly modified bench_fractal.rb to use Time.new instead of .now * to_java method added to RKernel
- Loading branch information
Showing
11 changed files
with
168 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import java.util.Calendar; | ||
import java.util.GregorianCalendar; | ||
|
||
public class RTime extends RObject { | ||
public final Calendar cal; | ||
|
||
public RTime() { | ||
this(new GregorianCalendar()); | ||
} | ||
|
||
public RTime(Calendar cal) { | ||
this.cal = cal; | ||
} | ||
|
||
public RObject to_s() { | ||
return new RString(cal.toString()); | ||
} | ||
|
||
public RObject to_int() { | ||
return new RFixnum(cal.getTimeInMillis()); | ||
} | ||
|
||
public RObject to_f() { | ||
return new RFloat(cal.getTimeInMillis() / 1000.0); | ||
} | ||
|
||
public Object to_java() { | ||
return cal; | ||
} | ||
|
||
public RObject $minus(RObject other) { | ||
if (other instanceof RTime) { | ||
return new RFloat(cal.getTimeInMillis() / 1000.0 - ((RTime)other).cal.getTimeInMillis() / 1000.0); | ||
} | ||
|
||
throw new RuntimeException(other.getClass().getName() + " is not a Time object"); | ||
} | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,51 @@ | ||
#!/usr/local/bin/ruby | ||
|
||
class Mandelbrot | ||
BAILOUT = 16 | ||
MAX_ITERATIONS = 1000 | ||
BAILOUT = 16 | ||
MAX_ITERATIONS = 1000 | ||
|
||
def initialize | ||
def fractal | ||
puts "Rendering" | ||
y = -39 | ||
while y <= 39 | ||
puts | ||
x = -39 | ||
while x <= 39 | ||
i = iterate(x/40.0,y/40.0) | ||
if (i == 0) | ||
print "*" | ||
else | ||
print " " | ||
end | ||
x+=1 | ||
y = -39 | ||
while y <= 39 | ||
puts | ||
x = -39 | ||
while x <= 39 | ||
i = iterate(x/40.0,y/40.0) | ||
if (i == 0) | ||
print "*" | ||
else | ||
print " " | ||
end | ||
y+=1 | ||
end | ||
end | ||
x+=1 | ||
end | ||
y+=1 | ||
end | ||
end | ||
|
||
def iterate(x,y) | ||
cr = y-0.5 | ||
ci = x | ||
zi = 0.0 | ||
zr = 0.0 | ||
i = 0 | ||
def iterate(x,y) | ||
cr = y-0.5 | ||
ci = x | ||
zi = 0.0 | ||
zr = 0.0 | ||
i = 0 | ||
|
||
while(1) | ||
i += 1 | ||
temp = zr * zi | ||
zr2 = zr * zr | ||
zi2 = zi * zi | ||
zr = zr2 - zi2 + cr | ||
zi = temp + temp + ci | ||
return i if (zi2 + zr2 > BAILOUT) | ||
return 0 if (i > MAX_ITERATIONS) | ||
end | ||
|
||
end | ||
|
||
while(1) | ||
i += 1 | ||
temp = zr * zi | ||
zr2 = zr * zr | ||
zi2 = zi * zi | ||
zr = zr2 - zi2 + cr | ||
zi = temp + temp + ci | ||
return i if (zi2 + zr2 > BAILOUT) | ||
return 0 if (i > MAX_ITERATIONS) | ||
end | ||
end | ||
|
||
i = 0 | ||
while i < 10 | ||
time = Time.now | ||
Mandelbrot.new | ||
time = Time.new | ||
fractal | ||
puts | ||
puts "Ruby Elapsed %f" % (Time.now - time) | ||
puts "Ruby Elapsed %f" % (Time.new - time) | ||
i+=1 | ||
end |