YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -101,13 +101,11 @@ my $count;
|
|||
PARTICLE: while (1) {
|
||||
my $a = rand(2 * PI);
|
||||
my $p = [ $r_start * cos($a), $r_start * sin($a) ];
|
||||
while ($_ = move($p)) {
|
||||
given ($_) {
|
||||
when (1) { next }
|
||||
when (2) { $count++; last; }
|
||||
when (3) { last PARTICLE }
|
||||
default { last }
|
||||
}
|
||||
while (my $m = move($p)) {
|
||||
if ($m == 1) { next }
|
||||
elsif ($m == 2) { $count++; last; }
|
||||
elsif ($m == 3) { last PARTICLE }
|
||||
else { last }
|
||||
}
|
||||
print STDERR "$count $max_dist/@{[int($r_start)]}/@{[STOP_RADIUS]}\r" unless $count% 7;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
# Project : Brownian tree
|
||||
# Date : 2018/02/16
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
|
||||
load "stdlib.ring"
|
||||
load "guilib.ring"
|
||||
|
|
|
|||
50
Task/Brownian-tree/Scala/brownian-tree.scala
Normal file
50
Task/Brownian-tree/Scala/brownian-tree.scala
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import java.awt.Graphics
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
import javax.swing.JFrame
|
||||
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
object BrownianTree extends App {
|
||||
val rand = scala.util.Random
|
||||
|
||||
class BrownianTree extends JFrame("Brownian Tree") with Runnable {
|
||||
setBounds(100, 100, 400, 300)
|
||||
val img = new BufferedImage(getWidth, getHeight, BufferedImage.TYPE_INT_RGB)
|
||||
|
||||
override def paint(g: Graphics): Unit = g.drawImage(img, 0, 0, this)
|
||||
|
||||
override def run(): Unit = {
|
||||
class Particle(var x: Int = rand.nextInt(img.getWidth),
|
||||
var y: Int = rand.nextInt(img.getHeight)) {
|
||||
|
||||
/* returns false if either out of bounds or collided with tree */
|
||||
def move: Boolean = {
|
||||
val (dx, dy) = (rand.nextInt(3) - 1, rand.nextInt(3) - 1)
|
||||
if ((x + dx < 0) || (y + dy < 0) ||
|
||||
(y + dy >= img.getHeight) || (x + dx >= img.getWidth)) false
|
||||
else {
|
||||
x += dx
|
||||
y += dy
|
||||
if ((img.getRGB(x, y) & 0xff00) == 0xff00) {
|
||||
img.setRGB(x - dx, y - dy, 0xff00)
|
||||
false
|
||||
} else true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var particles = ListBuffer.fill(20000)(new Particle)
|
||||
while (particles.nonEmpty) {
|
||||
particles = particles.filter(_.move)
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE)
|
||||
img.setRGB(img.getWidth / 2, img.getHeight / 2, 0xff00)
|
||||
setVisible(true)
|
||||
}
|
||||
|
||||
new Thread(new BrownianTree).start()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue