/* cube Scriptographer 2.0 script 2006-11-23 2008-03-26 modified to work with Sg 2.0.025 2008-03-27 minor modification for dialog 2008-04-01 minor fix on myDialog_getValues Scriptographer is a plugin for Adobe Illustrator(TM) created by Juerg Lehni http://www.scriptographer.com/ This script was written by SATO Hiroyuki http://park12.wakwak.com/~shp/lc/et/en_sg.html */ // --------------------------------------------- var hlen = 4*(Math.sqrt(2)-1)/3; var mpi = Math.PI; var hpi = Math.PI / 2; var wpi = Math.PI * 2; var cubeSize, interval, lastPnt, jitter; var g_myDialog; // ---------------------------------------------- function mm2pt(n){ return n * 2.83464567; } // ---------------------------------------------- function onOptions(){ if(g_myDialog){ g_myDialog.dialog.destroy(); g_myDialog = null; } g_myDialog = myDialog("cube:",[ {description:"size", value:cubeSize}, {description:"interval (%)", value:interval/cubeSize*100}, {description:"jitter (%)", value:jitter/cubeSize*100}]); } // --------------------- function getValuesFromDialog(){ var opt = myDialog_getValues(); if(opt != null){ if(opt[0]<=0 || opt[1]<=0 || opt[2]<=0){ Dialog.alert("please input a positive number"); return false; } cubeSize = opt[0]; interval = opt[1]*cubeSize/100; jitter = opt[2]*cubeSize/100; return true; } return false; } // ---------------------------------------------- function onInit() { cubeSize = 10; interval = cubeSize * Math.sqrt(2)*1.1; jitter = cubeSize; // show dialog at start onOptions(); } // ---------------------------------------------- function onMouseDown(event){ with(activeDocument.activeLayer){ if(locked || hidden){ Dialog.alert("please unlock and show the active layer"); return; } } // get values from dialog var chk = getValuesFromDialog(); if(!chk){ return; } lastPnt = event.point; drawCube(cubeSize, lastPnt); } // ---------------------------------------------- function onMouseDrag(event){ if(!lastPnt || event.point.isClose(lastPnt, interval) ) return; var jv = event.point.subtract(lastPnt).normalize().rotate(hpi); lastPnt = event.point; drawCube(cubeSize, lastPnt.add(jv.multiply((Math.random()-0.5)*jitter))); } // ---------------------------------------------- function onMouseUp(){ lastPnt = null; } // ---------------------------------------------- function drawCube(s, pnt){ // s = Math.random()*s + s; var tv = (Math.random()*0.7+0.15)*hpi; var th = (Math.random()-0.5)*(hpi*0.85); var r = s/Math.sqrt(2); var v = new Point(1,0); var v2 = v.rotate(th).multiply(r); var sn = Math.sin(tv); var face_top = [v2.multiply(1,sn), v2.rotate(hpi).multiply(1,sn), v2.rotate(mpi).multiply(1,sn), v2.rotate(-hpi).multiply(1,sn)]; var s2 = s*Math.cos(tv); var face_side = [v2.rotate(mpi).multiply(1,sn).add(0,-s2), v2.rotate(-hpi).multiply(1,sn).add(0,-s2), v2.multiply(1,sn).add(0,-s2)]; var pi = make_a_path(1, new GrayColor(0)); pi.closed = true; pi.style.stroke.join = 1; var gr = new Group(); gr.appendChild(pi); seg = pi.segments; seg.addAll([face_top[0], face_top[1], face_top[2], face_side[0], face_side[1], face_side[2]]); pi = make_a_path(0.5, null); seg = pi.segments; gr.appendChild(pi); seg.addAll([face_top[0], face_top[3]]); pi = make_a_path(0.5, null); seg = pi.segments; gr.appendChild(pi); seg.addAll([face_top[2], face_top[3]]); pi = make_a_path(0.5, null); seg = pi.segments; gr.appendChild(pi); seg.addAll([face_side[1], face_top[3]]); gr.translate(0,s2/2); gr.rotate( Math.random()*wpi ); gr.translate(pnt); } // ---------------------------------------------- function make_a_path(w,c){ var pi = new Path(); pi.closed = false; with(pi.style){ stroke.color = new GrayColor(1); stroke.width = w; fill.color = c; } return pi; } // ================================================================== // function for floating dialog function myDialog(title, elems){ this.dialog = new FloatingDialog(FloatingDialog.OPTION_TABBED); this.dialog.title = title this.textedits = []; this.max_caption_width = 0; // parts -------------------------------------- this.addStatic = function(elem, left, top){ var st = new Static(this.dialog); st.setText(elem["description"]); st.setSize(st.bestSize); st.setPosition(left, top); if(st.size.width > this.max_caption_width){ this.max_caption_width = st.size.width; } } this.addTextEdit = function(elem, size, left, top){ var te = new TextEdit(this.dialog, { units:TextValueItem.UNITS_NO }); te.setText(elem["value"]); te.setSize(size); te.setPosition(left, top); this.textedits.push(te); } // layout -------------------------------------- // constants var vertical_interval = 24; var caption_and_textedit_interval = 4; var margin = 10; var left = margin; var textedit_size = new Size(50, 20); var button_size = new Size(50, 20); // ------------------------ for(var i=0; i