Question about the possibilities of scripts

Need help writing a script or want to share scripts with other users? This is the right place!

Question about the possibilities of scripts

Postby NeatNit on Tue Feb 23, 2010 4:27 pm

How far can they go?

Can you make animations with scripts?
Can you make Connect 4 with scripts?
Can you make Frogger with scripts?


This is all ignoring their slowness. Assume you have a super computer which does any calculation with 1/infinity of a milisecond. Can those things be done?


Obviously they can't be saved with Paint3D's native 3MP format, but maybe in a script's special format :)


Anyway, can those things be done?
User avatar
NeatNit
 
Posts: 69
Joined: Thu Dec 24, 2009 11:26 am

Re: Question about the possibilities of scripts

Postby Atomic on Tue Feb 23, 2010 8:59 pm

Yeah, IronPython is a full programming language so they can do anything any program can.

The limitations only apply to things that require interoperating with Paint3D (they can't, for example, get the coordinates of the voxel currently pointed by the mouse). As far as interop is concerned they can only get/set the current image/selection and front/back colors. I intend to add a plugin system eventually to allow scripts to add functions to the menus and new tools.

I've been playing around with animation scripts, they're far from being smooth but here's one in case you're curious:
Note that it will take some time to preprocess and there's no way to stop it.
I also have a script that will take a sequence of 3mp's (xyz000.3mp, xyz001.3mp and so on) and animate it but it's kinda buggy :P

Code: Select all
import math
clr.AddReference('mscorlib')
from System import Array, EventHandler
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import *

empty = Color( 255.0, 255.0, 255.0, 0.0 )


voxs = []
width = 80
depth = 80
height = 80
voxels = Array.CreateInstance( Color, height, depth, width )
tmax = 10
curt = 0


def getColor(x,y,z,t):
   dx = (2.0 * x/width) - 1.0
   dy = (2.0 * y/depth) - 1.0
   dz = (0.999 * z/height) + 0.001 #avoids divide by zero
   dt = (1.0 * t/tmax)

   h = ((math.atan2(dx, dy) + math.pi) / math.pi) * 180
   h = (h + (360*dt))%360 # rotate
   s = math.sqrt(dx**2 + dy**2) / dz
   v = dz

   if s > 1.0:
      return empty

   hi = math.fmod(math.floor(h/60), 6)

   f = h/60 - math.floor(h/60)

   p = v * (1-s)
   q = v * (1-f*s)
   t = v * (1-(1-f)*s)

   p = 255.0*p
   q = 255.0*q
   t = 255.0*t
   v = 255.0*v

   if hi == 0:
      return Color(v, t, p, 255.0)
   elif hi == 1:
      return Color(q, v, p, 255.0)
   elif hi == 2:
      return Color(p, v, t, 255.0)
   elif hi == 3:
      return Color(p, q, v, 255.0)
   elif hi == 4:
      return Color(t, p, v, 255.0)
   elif hi == 5:
      return Color(v, p, q, 255.0)


def nextFrame( arg1, arg2 ):
   setVoxels( voxs[PeriodTimer.Tag] )

   PeriodTimer.Tag = PeriodTimer.Tag + 1

   if PeriodTimer.Tag == len( voxs ):
      PeriodTimer.Tag = 0

for t in range(tmax):
   voxs.append( Array.CreateInstance( Color, height, depth, width ) )

   for x in range(width):
      for y in range(depth):
         for z in range(height):
            voxs[t][x,y,z] = getColor(x,y,z,t)


PeriodTimer = Timer()
PeriodTimer.Interval = 20
PeriodTimer.Tick += EventHandler( nextFrame )
PeriodTimer.Tag = 0
PeriodTimer.Start()
User avatar
Atomic
Paint3D Developer
 
Posts: 119
Joined: Tue Aug 25, 2009 12:47 pm

Re: Question about the possibilities of scripts

Postby NeatNit on Wed Feb 24, 2010 4:07 pm

Thanks!


Also, what is the difference between full and simple? Why can't just everything be full?
User avatar
NeatNit
 
Posts: 69
Joined: Thu Dec 24, 2009 11:26 am

Re: Question about the possibilities of scripts

Postby Atomic on Thu Feb 25, 2010 1:29 am

Simple means you'll have less work because the loop is already set up for you. If you want to clear an image you can just
Code: Select all
return empty


In full mode you'd have to do it manually:
Code: Select all
empty = Color( 255.0, 255.0, 255.0, 0.0 )

for x in xrange(width):
   for y in xrange(depth):
      for z in xrange(height):
         voxels[x,y,z] = empty


Many things (like loading a file, for example) do not fit this loop so you have to use full mode and do your own thing.
User avatar
Atomic
Paint3D Developer
 
Posts: 119
Joined: Tue Aug 25, 2009 12:47 pm

Re: Question about the possibilities of scripts

Postby NeatNit on Thu Feb 25, 2010 5:52 pm

So simple simply repeats the script for each voxel?


And I noticed this line:
Code: Select all
empty = Color( 255.0, 255.0, 255.0, 0.0 )
Do you really need to put the ".0" for each of them? Why is it there anyway? I doubt it works, as it would require 12 extra bits for each color... (3 for each number) So why is it there? And I assume 'empty' is bound automatically in simple scripts?


Really off-topic, do you have Steam or MSN Messenger (... fine, Windows Live Messenger)? I'd like to be able to chat with you instead of using relatively slow forums :P
User avatar
NeatNit
 
Posts: 69
Joined: Thu Dec 24, 2009 11:26 am

Re: Question about the possibilities of scripts

Postby Atomic on Fri Feb 26, 2010 4:48 pm

NeatNit wrote:So simple simply repeats the script for each voxel?


Since you're curious, simple just surrounds your script with some lines of prewritten IPY code to save you typing the usual stuff:

Code: Select all
clr.AddReference('mscorlib')
import System
import math

random = System.Random()

empty = Color( 255.0, 255.0, 255.0, 0.0 )

def getColor(x, y, z):
   ******YOUR SIMPLE SCRIPT IS PASTED HERE******

for x in xrange(width):
   for y in xrange(depth):
      for z in xrange(height):
         voxels[x,y,z] = getColor(x, y, z)"


NeatNit wrote:And I noticed this line:
Code: Select all
empty = Color( 255.0, 255.0, 255.0, 0.0 )
Do you really need to put the ".0" for each of them? Why is it there anyway? I doubt it works, as it would require 12 extra bits for each color... (3 for each number) So why is it there? And I assume 'empty' is bound automatically in simple scripts?


That's ugly but it's necessary due to the differences between IPY's type system and C#'s.
Try doing something like
Code: Select all
return Color( 128, 0, 0, 255 )
it will give a totally red color instead of a darker tone because it uses the wrong constructor.

The decimal will be truncated if you use anything other than .0.

Edit: I've just hidden some of the Color constructors from scripts and that seems to have fixed this.

NeatNit wrote:Really off-topic, do you have Steam or MSN Messenger (... fine, Windows Live Messenger)? I'd like to be able to chat with you instead of using relatively slow forums :P


Not really, I'm kind of.. antisocial :P your best bet is to mail me, if I'm online at the moment we may be able to chat on GMail.
User avatar
Atomic
Paint3D Developer
 
Posts: 119
Joined: Tue Aug 25, 2009 12:47 pm

Re: Question about the possibilities of scripts

Postby Shadaez on Mon Apr 05, 2010 6:32 pm

I have Steam, http://steamcommunity.com/id/Shadaez if you'd like to add me.

I do a little programming every once in a while, I'm interested in a script that would change the colour of a block depending on its depth. Green on the top layer, brown one down, and then grey 4 or 5 blocks down. I'm going to check out the scripts to see if I can figure out how they work.
Shadaez
 
Posts: 22
Joined: Mon Apr 05, 2010 6:56 am

Re: Question about the possibilities of scripts

Postby NeatNit on Mon Apr 05, 2010 8:00 pm

http://www.minecraftforum.net/viewtopic ... 1&start=30
please ignore the irrelevant parts of the thread :roll:

Just make sure that everything is grass first.
User avatar
NeatNit
 
Posts: 69
Joined: Thu Dec 24, 2009 11:26 am

Re: Question about the possibilities of scripts

Postby Shadaez on Mon Apr 05, 2010 10:27 pm

Very cool, any idea how this works inside caves?
Shadaez
 
Posts: 22
Joined: Mon Apr 05, 2010 6:56 am

Re: Question about the possibilities of scripts

Postby Atomic on Wed Apr 07, 2010 11:43 am

As far as I remember it counted depth from the top to bottom, starting with the first non-air block and ignored any air blocks after that. You'd have to modify it to behave better on caves but it shouldn't be hard.
User avatar
Atomic
Paint3D Developer
 
Posts: 119
Joined: Tue Aug 25, 2009 12:47 pm

Next

Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron