Posts Tagged ‘applet’

Real time tester

Thursday, July 22nd, 2010


I’ve adapted an old applet to function as a real time tester. The idea being that you hear a new graphics algorithm is “real-time” or “interactive” because it runs in only “59ms” per frame, but your internal clock isn’t accurate enough to really know what that feels like. Here you can specify the simulated “solve” time and drag around the bezier curve as if hard-core math is going on between frames.

Bézier Curve editor applet

Thursday, February 4th, 2010

Bézier curve editor
This Bézier curve editor is the first applet I’ve written for my Geometric Modeling class. It implements De Casteljau’s algorithm to render the curve recursively and the Graham scan method for determining the convex hull of the control points. I also implement elevating the degree (by adding another control point) of the Bézier curve without changing the curve.

Compile and run applet with just java file, bash script

Monday, February 1st, 2010

I had the habit of creating little bash scripts for each java applet I worked on. These were such boilerplate, not to mention the boilerplate html for each applet. So here’s a script the takes the main applet file as a parameter and compiles the code, creates some html on the fly and runs the applet:


#!/bin/bash
#
# Usage:
#   ./appletmakeandview.sh Applet.java
#

base=`echo $1 | sed "s/\.java$//g"`;
if javac -source 1.5 -target 1.5 $base.java; then
  if [ ! -e $base.html ]
  then
    echo "<applet code=$base width=600 height=600></applet>" | cat > $base.html
  fi
  appletviewer $base.html
fi

New Clock Design

Wednesday, December 2nd, 2009

I’ve made a new digital design prototype for a physical clock I plan to build.
Here’s a preview of my geometric clock prototype in action:


Here’s a preview of my geometric clock prototype frozen:
geometric clock design prototype

Political globe of earth mapped to cube (applet)

Tuesday, October 13th, 2009

I’m reviving an old applet which models a cube I made. The cube is the image a mapping of a political globe of the earth.


Political globe mapped to cube

I didn’t write the java code for this applet (Intel did), though I can’t imagine it’s all that complicated. Someday (sigh) I will write my own textured cube applet and that textured cube applet applet will not have this annoying mouse click feature.

Three body chaos visualization applet revived

Monday, October 12th, 2009

Googlepages has officially migrated to Googlesites. For me this means that my old website on Googlepages has been “migrated”. Migration apparently included only html files and perhaps PDFs. So I’ve been trying to revive my old java applets. Here’s the first to be brought back from the dead.


three body chaos

In a gravitational system with three or more bodies tracking position over time becomes chaotic. Slight perturbations (i.e. miscalculations) in the start position can greatly affect the calculated positions later as time goes by. This java applet that shows the 10 possible paths of a satellite travelling between two suns. All 10 paths start at the same position (with slight perturbations).

I’ve only changed a few minor things from the original 2006 train-wreck java source, so have a look only if you dare.

Restart Safari restoring windows and tabs

Thursday, August 13th, 2009

Safari only resets its JRE cache at restart. So when I am developing Java applets and testing them in my Safari browser, I have to restart Safari every time I recompile to view my changes. I have tried deleting the JRE cache manually and using Safari > Empty Cache, but the JRE cache is still there. Only restarting has worked.

So the least I could do is write an applescript to restart Safari and restore any windows and tabs I might have had open. Here’s my script:


-- Get all windows and their tabs as nested list
set url_list to {}
tell application "Safari"
	activate
	set tab_list to {}
	repeat while (count of documents) > 0
		set doc_count to count of documents
		set this_doc to front window
		set tab_list to tab_list & URL of front document of this_doc
		tell application "System Events" to keystroke "w" using {command down}
		if doc_count is not equal to (count of documents) then
			set url_list to url_list & {tab_list}
			set tab_list to {}
		end if
	end repeat
end tell

-- Save list to preference files just in case
-- convert url list  to text
set old_delim to AppleScript's text item delimiters
set url_text to ""
set AppleScript's text item delimiters to " "
repeat with this_item in url_list
	set url_text to (url_text & this_item as text) & return
end repeat
set AppleScript's text item delimiters to old_delim

-- get path to prefs file where URLs will be stored
set prefs_folder to path to preferences folder as string
set prefs_file to prefs_folder & "Safari Saved URLs"

try
	set open_file to ¬
		open for access file prefs_file with write permission
	-- erase current contents of file:
	set eof of open_file to 0
	write url_text to open_file starting at eof
	close access open_file
on error
	try
		close access file prefs_file
	end try
end try
display dialog url_text

-- Restart Safari
tell application "Safari" to quit
repeat while appIsRunning("Safari")
	delay 1
end repeat
tell application "Safari" to activate

-- Restore windows and tabs
tell application "Safari"
	repeat with i from 1 to length of url_list
		set this_doc to front document
		if i is not equal to 1 then
			set this_doc to make new document at end of documents
		end if
		repeat with j from 1 to length of (item i of url_list)
			set URL of this_doc to item j of (item i of url_list)
			if j is not equal to length of (item i of url_list) then
				tell application "System Events" to keystroke "t" using {command down}
			end if
		end repeat
	end repeat
end tell

-- http://codesnippets.joyent.com/posts/show/1124
on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning

Note: I save the list of window and tab URLs as text in ~/Library/Preferences/Safari Saved URLs. That way if something goes wrong I have a second chance at retrieving the URLs I had open. Perhaps this is entirely unnecessary.

Make any java applet on the web fullscreen (in browser)

Wednesday, August 12th, 2009

Sometimes on the web I find great java applets that I’d enjoy more if they were bigger. I wrote a little php script to generate a fullscreen java applet wrapper on the fly for any given applet. You just need to find the applet’s code and codebase parameters from the original page’s html source.

Here’s the bulk of the php source:


<?php
  $applet = "";
  $code = "";
  if (isset($_GET['code'])&&strlen($_GET['code'])>0)
    $code = $_GET['code'];
  # remove surrounding quotes if given any
  $code = preg_replace("/[\"\']$/","",$code);
  $code = preg_replace("/^[\"\']/","",$code);
  # remove trailing .class just in case it's included
  $code = preg_replace("/\.class$/","",$code);
  $codebase = "";
  if (isset($_GET['codebase'])&&strlen($_GET['codebase'])>0)
    $codebase = $_GET['codebase'];
  # remove surrounding quotes if given any
  $codebase = preg_replace("/[\"\']$/","",$codebase);
  $codebase = preg_replace("/^[\"\']/","",$codebase);
  $path= "";
  if (isset($_GET['path'])&&strlen($_GET['path'])>0)
    $path = $_GET['path'];
  if(empty($code)&&empty($codebase)&&!empty($path)){
    # stip out basename to get just the code's name
    $code = `basename $path`;
    $code = preg_replace("/\n$/","",$code);
    # remove trailing .class just in case it's included
    $code = preg_replace("/\.class$/","",$code);
    if(empty($codebase)){                                     
      $codebase = `dirname $path`;                            
      # make the codebase look like a directory, not neccessary for all browsers
      $codebase = preg_replace("/\n$/","/",$codebase);        
    }                                                         
    $applet = "<applet width='100%' height='100%' code='$code' codebase='$codebase' ></applet>";
  }else if(!empty($code)&&!empty($codebase)){                 
    # remove trailing .class just in case it's included       
    $applet = "<applet width='100%' height='100%' code='$code' codebase='$codebase' ></applet>";
  }
?>

Then I just echo the $applet variable’s contents. Not a lot is actually being done besides build an <applet> tag with the given parameters. Most of the mumbojumbo is preparing the strings.

I don’t think it would be too hard to use wget and yank out the code and codebase parameters automatically… maybe I will add that soon.

Update: I’ve added some css to make the page load better in Firefox. Also added the above mentioned wget applet extractor feature. I realized that I hadn’t considered applet’s with archive= parameters, so I have fixed that. Just now I am realizing that some applets won’t run correctly if they rely on <param name = appletAttribute1 value = value> type tags in the <applet> tag. I will fix that soon.