Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed May 29, 2015
1 parent 4e94fda commit b00e722
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 197 deletions.
28 changes: 28 additions & 0 deletions pe/droidjam.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function runServer() {
new java.io.InputStreamReader(
socket.getInputStream()));
writer=new java.io.PrintWriter(socket.getOutputStream(),true);
Level.setTime(0);

while(running) {
var str = reader.readLine();
Expand Down Expand Up @@ -137,6 +138,9 @@ function handleCommand(cmd) {
if (m == "world.setBlock") {
setBlock(args);
}
else if (m == "world.setBlocks") {
setBlocks(args);
}
else if (m == "player.getPos") {
writer.println(""+Player.getX()+","+Player.getY()+","+Player.getZ());
}
Expand All @@ -152,9 +156,33 @@ function handleCommand(cmd) {
}

function setBlock(args) {
// android.util.Log.v("droidjam", "setTile "+args[0]+"|"+args[1]+"|"+args[2]+"|"+args[3]+"|"+args[4]);
Level.setTile(args[0], args[1], args[2], args[3], args[4]);
}

function setBlocks(args) {
var x0 = parseInt(args[0]);
var y0 = parseInt(args[1]);
var z0 = parseInt(args[2]);
var x1 = parseInt(args[3]);
var y1 = parseInt(args[4]);
var z1 = parseInt(args[5]);
var startx = x0 < x1 ? x0 : x1;
var starty = y0 < y1 ? y0 : y1;
var startz = z0 < z1 ? z0 : z1;
var endx = x0 > x1 ? x0 : x1;
var endy = y0 > y1 ? y0 : y1;
var endz = z0 > z1 ? z0 : z1;
android.util.Log.v("droidjam", "setBlocks: "+startx+"|"+starty+"|"+startz+"|"+endx+"|"+endy+"|"+endz+">"+args[6]+"|"+args[7]);
for (x = startx ; x <= endx ; x++) {
for (y = starty ; y <= endy ; y++) {
for (z = startz ; z <= endz ; z++) {
Level.setTile(x, y, z, args[6], args[7]);
}
}
}
}

function err(msg) {
writer.println("ERR "+msg);
print("ERR "+msg);
Expand Down
Binary file modified python2-scripts.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions python2-scripts/mcpipy/donut.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from mc import *

def draw_donut(mcx,mcy,mcz,R,r,mcblock,mcmeta):
def draw_donut(mcx,mcy,mcz,R,r,mcblock):
for x in range(-R-r,R+r):
for y in range(-R-r,R+r):
xy_dist = sqrt(x**2 + y**2)
Expand All @@ -23,13 +23,13 @@ def draw_donut(mcx,mcy,mcz,R,r,mcblock,mcmeta):

for z in range(-R-r,R+r):
if (ring_dist_sq + z**2 <= r**2):
mc.setBlock(mcx+x, mcy+z, mcz+y, mcblock, mcmeta)
mc.setBlock(mcx+x, mcy+z, mcz+y, mcblock)

mc = Minecraft()

playerPos = mc.player.getPos()

draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 9, GLASS, 0)
draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 9, GLASS)
mc.postToChat("Glass donut done")
draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 6, GRASS, 0)
draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 6, WATER)
mc.postToChat("Water donut done")
2 changes: 1 addition & 1 deletion python2-scripts/mcpipy/fancytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def tree(depth,thickness,branchLen):
if random.random() < 0.2:
return
if branchLen < 4:
t.penblock(LEAVES)
t.penblock(LEAVES_OAK_PERMANENT)
else:
t.penblock(WOOD)
t.penwidth(thickness)
Expand Down
2 changes: 1 addition & 1 deletion python2-scripts/mcpipy/lforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def push():
if thickness < 1:
thickness = 1
if length <= 1.6:
t.penblock(LEAVES)
t.penblock(LEAVES_OAK_PERMANENT)
t.penwidth(thickness)

def pop():
Expand Down
240 changes: 120 additions & 120 deletions python2-scripts/mcpipy/lsystem.py
Original file line number Diff line number Diff line change
@@ -1,121 +1,121 @@
#
# Copyright (c) 2015 Alexander Pruss
# L-system with turtle graphics
#

import collections
import random
from mcturtle import *

def playProgram(s, dictionary):
for c in s:
if c in dictionary:
dictionary[c]()


def transform(c, t):
if isinstance(t, basestring):
return t
else:
r = random.random()
for p,out in t:
if r<p:
return out
r -= p
return c

def evolve(axiom, rules, levelCount):
for i in range(levelCount):
out = ""
for c in axiom:
if c in rules:
out += transform(c, rules[c])
else:
out += c
axiom = out
return axiom


def lsystem(axiom, rules, dictionary, levelCount):
out = evolve(axiom, rules, levelCount)
playProgram(out, dictionary)

if __name__ == "__main__":
t = Turtle()
t.pendelay(0)
t.penup()
t.turtle(None)
t.go(10)
t.verticalangle(90)
t.pendown()
t.penblock(WOOD)

# a fairly simple example with rules from http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-94to95/hwchen/
# rules = {'F':'F[-&<F][<++&F]||F[--&>F][+&F]'}
#
# angle = 22.5
#
# dictionary = {
# '[': t.push,
# ']': t.pop,
# 'F': lambda: t.go(5),
# '-': lambda: t.yaw(-angle),
# '+': lambda: t.yaw(angle),
# '&': lambda: t.pitch(angle),
# '^': lambda: t.pitch(-angle),
# '<': lambda: t.roll(-angle),
# '>': lambda: t.roll(angle),
# '|': lambda: t.pitch(180)
# }
#
# lsystem('F', rules, dictionary, 3)


#
# A more complex example with
# rules based on http://www.geekyblogger.com/2008/04/tree-and-l-system.html
#
rules = {'A': '^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'}

#randomized version:
# rules = {'A': [(0.75,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'),
# (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]}

axiom = 'fA'
angle = 15
thickness = 8
length = 15
material = WOOD
t.penwidth(thickness)
t.penblock(material)

stack = []
def push():
global length
global thickness
stack.append((length,thickness))
t.push()
thickness = thickness * 0.6
length = length * 0.75
if thickness < 1:
thickness = 1
if length <= 1:
t.penblock(LEAVES)
t.penwidth(thickness)

def pop():
global length
global thickness
length,thickness = stack.pop()
t.pop()

dictionary = {
'[': push,
']': pop,
'^': lambda: t.pitch(angle),
'>': lambda: t.roll(angle),
'f': lambda: t.go(length)
}

# print evolve(axiom, rules, 11)
#
# Copyright (c) 2015 Alexander Pruss
# L-system with turtle graphics
#

import collections
import random
from mcturtle import *

def playProgram(s, dictionary):
for c in s:
if c in dictionary:
dictionary[c]()


def transform(c, t):
if isinstance(t, basestring):
return t
else:
r = random.random()
for p,out in t:
if r<p:
return out
r -= p
return c

def evolve(axiom, rules, levelCount):
for i in range(levelCount):
out = ""
for c in axiom:
if c in rules:
out += transform(c, rules[c])
else:
out += c
axiom = out
return axiom


def lsystem(axiom, rules, dictionary, levelCount):
out = evolve(axiom, rules, levelCount)
playProgram(out, dictionary)

if __name__ == "__main__":
t = Turtle()
t.pendelay(0)
t.penup()
t.turtle(None)
t.go(10)
t.verticalangle(90)
t.pendown()
t.penblock(WOOD)

# a fairly simple example with rules from http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-94to95/hwchen/
# rules = {'F':'F[-&<F][<++&F]||F[--&>F][+&F]'}
#
# angle = 22.5
#
# dictionary = {
# '[': t.push,
# ']': t.pop,
# 'F': lambda: t.go(5),
# '-': lambda: t.yaw(-angle),
# '+': lambda: t.yaw(angle),
# '&': lambda: t.pitch(angle),
# '^': lambda: t.pitch(-angle),
# '<': lambda: t.roll(-angle),
# '>': lambda: t.roll(angle),
# '|': lambda: t.pitch(180)
# }
#
# lsystem('F', rules, dictionary, 3)


#
# A more complex example with
# rules based on http://www.geekyblogger.com/2008/04/tree-and-l-system.html
#
rules = {'A': '^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'}

#randomized version:
# rules = {'A': [(0.75,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'),
# (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]}

axiom = 'fA'
angle = 15
thickness = 8
length = 15
material = WOOD
t.penwidth(thickness)
t.penblock(material)

stack = []
def push():
global length
global thickness
stack.append((length,thickness))
t.push()
thickness = thickness * 0.6
length = length * 0.75
if thickness < 1:
thickness = 1
if length <= 1:
t.penblock(LEAVES_OAK_PERMANENT)
t.penwidth(thickness)

def pop():
global length
global thickness
length,thickness = stack.pop()
t.pop()

dictionary = {
'[': push,
']': pop,
'^': lambda: t.pitch(angle),
'>': lambda: t.roll(angle),
'f': lambda: t.go(length)
}

# print evolve(axiom, rules, 11)
lsystem(axiom, rules, dictionary, 11)
Loading

0 comments on commit b00e722

Please sign in to comment.