sparks wrote:
joletole wrote:
I have a suggestion for your website.
How about, when you go onto the website, there will be an introduction, the exact same one as the one on here. Then, at the top, you have 5 options, scratch blocks, panther, byob, the statistics, and the glossary.
Then, when you click on either scratch blocks, byob, or panther, it will bring you to a page that has the corosponding page.We had that, but databases weren't working. Thanks for the suggestion though, joletole
@greenatic, yes, I was just thinking about that one, but it is very unfinished...
I posted on the Announcements Block Plugin thread to ask about the source code. Now we wait
Meanwhile, where can I find TheSuccessor's API and source code? I don't know PHP but I *might* be able to figure it out
Offline
it's on the old site11 site: http://theblocklibrary.site11.com/include/img/blocks/specparser.php?spec=text&type=stack&color=sensing
I could move it if I can remember the password, one sec..
Last edited by sparks (2012-04-15 17:00:23)
Offline
sparks wrote:
it's on the old site11 site: http://theblocklibrary.site11.com/include/img/blocks/specparser.php?spec=text&type=stack&color=sensing
I could move it if I can remember the password, one sec..
The block shape is alot more accurate than the Scratch one...but it doesn't seem to support C-blocks...
Offline
Well... I take my hat off to him... Wow.
<?php /* * Purpose: Parses the given blockspec * and generates a block image. Supports * Scratch and Panther blocks so far. * Maybe someone could optimise it and * expand it to BYOB at some point. * Form accepted: spec=spec&type=(stack|boolean|stop|reporter)&color=(category name|hex colour) * or spec=fullblockspec&color=(category name|hex colour) */ if(!isset($_GET['spec'])) die(); //Exit if we have no spec $font = 2; //The most appropriate font IMO that PHP has preinstalled (still not particularly good though - Scratch uses Verdana Bold Narrow Space) $arg_widths = array(/*Text*/ 10, /*Boolean*/ 25, /*Number*/ 15, /*Color*/ 13, /*Dropdown menu*/ 22); //Width in pixels of the arguments $n_arg_w = array('String' => 10, 'Boolean' => 25, 'Number' => 15, 'Color' => 13, 'Other' => 22); //Same here, but with names attached $spec = $_GET['spec']; $spec = str_replace('\\', '', $spec); //Clear out backslashes before ' function full_spec($spec){ //Parse full block spec - currently incomplete $bspec = $spec; //Get a local copy of $spec for the full spec parser $tspec = array(); trim($bspec); //Get rid of surrounding whitespace if(substr($bspec, 0, 1) == "("){ //Take off any surrounding brackets $bspec = substr($bspec, 1); if(substr($bspec, -1) == ")") $bspec = substr($bspec, 0, -1); } trim($bspec); //Get rid of surrounding whitespace again $tspec[0] = extractString($bspec); echo $tspec[0]."<br />"; echo $bspec."<br />"; if($tspec[0] === false) return false; //Only return here if the returned value was actually false, not just equivalent to false trim($bspec); //Get rid of whitespace again if($bspec == "") return false; $spacepos = strpos($bspec, " "); if(!$spacepos){ $tspec[1] = $bspec; return $tspec; } $tspec[1] = substr($bspec, 0, $spacepos); //Get the type identifier from the spec if(substr($tspec[1], 0, 1) == "#") $tspec[1] = substr($tspec[1], 1); //Remove a preceding # symbol from the start of it if necessary $bspec = substr($bspec, $spacepos + 1); //Chop it off echo $bspec."<br />"; echo $tspec[1]."<br />"; $spacepos = strpos($bspec, " "); //Find where the method name ends if(!$spacepos) return $tspec; //If we can't find an ending space, it must take up the rest of the string so we just return $tspec as it is $bspec = substr($bspec, $spacepos + 1); //Chop off the method echo $bspec."<br />"; $args = array(); $i = 0; $loopbuster = 0; while($bspec && $loopbuster < 100){ //Repeat until we've got rid of everything $args[$i] = extractString($bspec); if($args[$i] === false){ $spacepos = strpos($bspec, " "); if($spacepos == 0){ $args[$i] = $bspec; $bspec = null; }else{ $args[$i] = substr($bspec, 0, $spacepos); $bspec = substr($bspec, $spacepos + 1); } } trim($bspec); $loopbuster++; } $tspec[2] = $args; return $tspec; } function extractString(&$source){ //Removes the first smalltalk string from $source and returns it $next = 1; $loopbuster = 0; //Helps prevent an infinite loop if(!substr($source, 0, 1) == "'") return false; //If it doesn't start with a smalltalk string delimiter, return false while($loopbuster < 100){ //Try and find the end of the string $next = strpos($source, "'", $next); if(!$next) return false; $dsq = strpos($source, "''", $next); //Let's find out if they're doubled single quotes if(!$dsq || $dsq > $next){ //One single quote ends string $res = substr($source, 1, $next - 1); //Save the string $source = substr($source, $next + 1); //Chop it off the original return $res; //Return it }else{ $next += 2; //They're DSQs, skip over them } $loopbuster++; } } $type = isset($_GET['type']) ? $_GET['type'] : 'stack'; if($type == 'cap') $type = 'stop'; //Cap is probably more accurate, but stop is what I programmed it with originally, so we change it if necessary $args = array(); /*$fs = full_spec($spec); if($fs != false){ echo $fs[0]."hi<br />"; $spec = $fs[0]; //$type = $fs[1]; if($fs[2]) $args = $fs[2]; } //echo $fs[2];*/ $color = isset($_GET['color']) ? $_GET['color'] : 'control'; //Control's the default color if($color == 'sounds') $color = 'sound'; //Sound is the correct name, but it accepts sounds as that's how I made it originally $colors = array( 'control' => 'E7AD21', 'motion' => '4A6BD6', 'sensing' => '0094DE', 'looks' => '8C52E7', 'sound' => 'CE4ADE', 'operators' => '63C610', 'pen' => '00A57B', 'variables' => 'F77318', 'files' => '2C78C3', 'colors' => '191919', //Not sure about this one - I modified my version of Panther and don't want to re-install ); //The hexadecimal RGB colours of the different categories if(isset($colors[$color])) $color = $colors[$color]; //Insert preset colour if applicable if(substr($color, 0, 1) == '#') $color = substr($color, 1); //Get rid of a preceding # in the colour $color = array(intval(substr($color, 0, 2), 16), intval(substr($color, 2, 2), 16), intval(substr($color, 4, 2), 16)); //Parse colour into decimal rgb values $highlights = computeHighlightColors($color[0], $color[1], $color[2]); //Get the highlight variations $shadow = array($color[0] * 0.7, $color[1] * 0.7, $color[2] * 0.7); //Get the shadow variation $scratch = array('/%s/', '/%b/', '/%n/', '/%[cC]/', '/%[^\ssbncC]/'); //Scratch arg regexs $panther = array('\$String\$', '\$Boolean\$', '\$Number\$', '\$Color\$', '\$Other\$'); //Panther args $panther_regex = array('/\$String\$/', '/\$Boolean\$/', '/\$Number\$/', '/\$Color\$/', '/\$Other\$/'); //Panther arg regexs $spec = preg_replace($scratch, $panther, $spec); //Panther arg identifiers make much more sense - replace them in $text_width = imagefontwidth($font) * strlen(preg_replace($panther_regex, '', $spec)); //Get the total text length for($i = 0; $i < sizeof($panther); $i++){ $text_width += (substr_count($spec, str_replace('\\', '', $panther[$i])) * $arg_widths[$i]); //Add the length of the arg inserters } $text_bits = explode('$Arg$', preg_replace($panther_regex, '$Arg$', $spec)); //Get the different text sections $results = array(); preg_match_all('/\$(String|Boolean|Number|Color|Other)\$/', $spec, $results); //Get the arg inserters $arg_bits = $results[1]; if(sizeof($arg_bits) + 1 !== sizeof($text_bits)) exit('Error parsing argument inserters'); //Exit if we have a strange number of one or the other $w = $text_width + 12; $h = 25; //Set the width and height if($type == 'reporter' || $type == 'boolean' || $type == 'color'){ $h = 20; } //Shrink it for reporters if($type == 'boolean'){ $w += 6; } //Booleans need to be wider than other blocks $w = max($w, 40); //Apply a minimum width or it can end up with nasty looking blocks $img = imagecreate($w, $h); //Create an image for the block $bck = imagecolorallocate($img, 0, 0, 0); //Set the back colour $color = imagecolorallocate($img, $color[0], $color[1], $color[2]); //Convert $color into a colour $highlight1 = imagecolorallocate($img, $highlights[0][0], $highlights[0][1], $highlights[0][2]); //Same with the highlights $highlight2 = imagecolorallocate($img, $highlights[1][0], $highlights[1][1], $highlights[1][2]); $shadow = imagecolorallocate($img, $shadow[0], $shadow[1], $shadow[2]); //And the shadow colour $white = imagecolorallocate($img, 255, 255, 255); //White colour for the text if($type == 'boolean'){ $x = 10; drawBool($img, $w - 1, $h); } else if($type == 'reporter'){ $x = 7; drawRep($img, $w - 1, $h); } else if($type == 'color'){ $x = 6; drawColor($img, $w - 1, $h - 1); } else{ $x = 6; topEdge($img, $w); body($img, $w, $h); if($type == 'stop') smoothBottomEdge($img, $w, $h - 3); else bottomEdge($img, $w, $h); } imagestring($img, $font, $x, 4, $text_bits[0], $white); //Write the first bit of text for($i = 0; $i < sizeof($arg_bits); $i++){ $x += imagefontwidth($font) * strlen($text_bits[$i]); //Move the x locator along $arg = $arg_bits[$i]; switch($arg){ case "Number": drawNumberArg($img, $x, 4, $n_arg_w[$arg], $h); break; } $x += $n_arg_w[$arg]; imagestring($img, $font, $x, 4, $text_bits[$i + 1], $white); //Write bit i of text } imagecolortransparent($img, $bck); //Make the, background transparent header('Content-type: image/png'); //Tell the user's browser it's a png image, not text imagepng($img); //Output the image imagedestroy($img); //Destroy it to save resources function computeHighlightColors($r, $g, $b){ //Based on code from http://www.actionscript.org/forums/archive/index.php3/t-50746.html $result = array(); $r_decimal = $r / 255; $g_decimal = $g / 255; $b_decimal = $b / 255; $min_decimal = min($r_decimal, $g_decimal, $b_decimal); $max_decimal = max($r_decimal, $g_decimal, $b_decimal); $del_Max = $max_decimal - $min_decimal; $V = $max_decimal; if ($del_Max == 0){ $H = 0; $S = 0; }else{ $S = $del_Max / $max_decimal; $del_R = ((($del_Max - $r_decimal ) / 6 ) + ( $del_Max / 2 )) / $del_Max; $del_G = ((($del_Max - $g_decimal ) / 6 ) + ( $del_Max / 2 )) / $del_Max; $del_B = ((($del_Max - $b_decimal ) / 6 ) + ( $del_Max / 2 )) / $del_Max; if ($r_decimal == $max_decimal) $H = $del_B - $del_G; else if ($g_decimal == $max_decimal) $H = ( 1 / 3 ) + $del_R - $del_B; else if ($b_decimal == $max_decimal) $H = ( 2 / 3 ) + $del_G - $del_R; if ($H<0) $H++; if ($H>1) $H--; } /* $minRGB = min(min($r,$g),$bl); $maxRGB = max(max($r,$g),$bl); $delta = $maxRGB-$minRGB; $b = $maxRGB; if ( $maxRGB!=0 ) $s = 255*$delta/$maxRGB; else $s = 0; if ( $s != 0 ) { if ( $r == $maxRGB ) $h = ($g-$bl)/$delta; else if ( $g == $maxRGB ) $h = 2+($bl-$r)/$delta; else $h = 4+($r-$g)/$delta; } else $h = -1; $h *= 60; if ( $h < 0 ) $h += 360; $H = $h / 360; $S = floor($s*100/255); $v = floor($b*100/255);*/ return array(HSV_TO_RGB($H, $S - 0.13, $V + 0.05), HSV_TO_RGB($H, $S, $V + 0.07)); } function HSV_TO_RGB ($H, $S, $V){ if($S == 0){ $R = $G = $B = $V * 255; }else{ $var_H = $H * 6; $var_i = floor($var_H); $var_1 = $V * (1 - $S); $var_2 = $V * (1 - $S * ($var_H - $var_i)); $var_3 = $V * (1 - $S * (1 - ($var_H - $var_i))); if ($var_i == 0) { $r_decimal = $V ; $g_decimal = $var_3 ; $b_decimal = $var_1 ; } else if ($var_i == 1) { $r_decimal = $var_2; $g_decimal = $V; $b_decimal = $var_1; } else if ($var_i == 2) { $r_decimal = $var_1; $g_decimal = $V; $b_decimal = $var_3; } else if ($var_i == 3) { $r_decimal = $var_1; $g_decimal = $var_2; $b_decimal = $V; } else if ($var_i == 4) { $r_decimal = $var_3; $g_decimal = $var_1; $b_decimal = $V; } else { $r_decimal = $V; $g_decimal = $var_1; $b_decimal = $var_2; } $R = $r_decimal * 255; $G = $g_decimal * 255; $B = $b_decimal * 255; } return array($R, $G, $B); } function topEdge($image, $width){ //Code hereon is based off that in Scratch. I didn't write the original Smalltalk, and won't comment my PHP translation global $color, $highlight1, $highlight2, $shadow; imageline($image, 2, 0, 11, 0, $highlight1); imageline($image, 25, 0, $width - 3, 0, $highlight1); imageline($image, 1, 1, 11, 1, $highlight2); imageline($image, 25, 1, $width - 2, 1, $highlight2); imageline($image, 0, 2, 12, 2, $color); imageline($image, 24, 2, $width - 1, 2, $color); imageline($image, 0, 3, 13, 3, $color); imageline($image, 23, 3, $width - 1, 3, $color); imageline($image, 0, 4, $width - 1, 4, $color); imageline($image, 13, 4, 23, 4, $highlight1); } function stopBody($image, $width, $height){ global $color, $highlight1, $highlight2, $shadow; imagefilledrectangle($image, 0, 5, $width - 1, $height - 3, $color); imagefilledrectangle($image, 0, 2, 2, $height - 3, $highlight2); imagefilledrectangle($image, $width - 1, 2, $width, $height - 3, $shadow); } function body($image, $width, $height){ global $color, $highlight1, $highlight2, $shadow; imagefilledrectangle($image, 0, 5, $width - 1, $height - 7, $color); imagefilledrectangle($image, 0, 2, 2, $height - 7, $highlight2); imagefilledrectangle($image, $width - 1, 3, $width, $height - 7, $shadow); } function bottomEdge($image, $width, $height){ global $color, $highlight1, $highlight2, $shadow; imageline($image, 1, $height - 7, $width - 2, $height - 7, $color); imageline($image, 2, $height - 6, $width - 3, $height - 6, $color); imageline($image, 11, $height - 5, 25, $height - 5, $color); imageline($image, 12, $height - 4, 24, $height - 4, $color); imageline($image, 12, $height - 3, 24, $height - 3, $color); imageline($image, 12, $height - 2, 23, $height - 2, $color); imageline($image, 3, $height - 5, 11, $height - 5, $shadow); imageline($image, 25, $height - 5, $width - 3, $height - 5, $shadow); imageline($image, 13, $height - 1, 23, $height - 1, $shadow); imagesetpixel($image, 11, $height - 4, $shadow); imagesetpixel($image, 11, $height - 3, $shadow); imagesetpixel($image, 12, $height - 2, $shadow); imagesetpixel($image, 24, $height - 4, $shadow); imagesetpixel($image, 24, $height - 3, $shadow); imagesetpixel($image, 23, $height - 2, $shadow); imagesetpixel($image, $width - 2, $height - 6, $shadow); } function smoothBottomEdge($image, $width, $height){ global $color, $highlight1, $highlight2, $shadow; imageline($image, 1, $height - 3, $width - 1, $height - 3, $color); imageline($image, 2, $height - 2, $width - 2, $height - 2, $color); imageline($image, 3, $height - 1, $width - 3, $height - 1, $shadow); imagesetpixel($image, $width - 2, $height - 3, $shadow); imagesetpixel($image, $width - 3, $height - 2, $shadow); } function drawRep($image, $width, $height){ global $color, $highlight1, $highlight2, $shadow; $topDraw = $bottomDraw = $hh = floor($height / 2); if($hh * 2 == $height) $topDraw = $bottomDraw - 1; while($topDraw >= 0){ $indent = $hh - round(sqrt((pow($hh, 2) - pow($hh - $topDraw - 1, 2)))); $col = $color; if($topDraw == 0) $col = $highlight1; if($topDraw == 1) $col = $highlight2; imageline($image, $indent, $topDraw, $width - $indent, $topDraw, $col); if($indent > 0 && $topDraw > 1){ imagesetpixel($image, $indent, $topDraw, $highlight1); imagesetpixel($image, $width - $indent, $topDraw, $highlight1); } $col = ($bottomDraw == $height - 1) ? $shadow : $color; imageline($image, $indent, $bottomDraw, $width - $indent, $bottomDraw, $col); if($indent > 0){ imagesetpixel($image, $indent, $bottomDraw, $shadow); imagesetpixel($image, $width - $indent, $bottomDraw, $shadow); } $bottomDraw++; $topDraw--; } } function drawBool($image, $width, $height){ global $color, $highlight1, $highlight2, $shadow; $topDraw = $bottomDraw = floor($height / 2); if($topDraw * 2 == $height) $topDraw = $bottomDraw - 1; $indent = 0; while($topDraw >= 0){ $col = $color; if($topDraw == 0) $col = $highlight1; if($topDraw == 1) $col = $highlight2; imageline($image, $indent, $topDraw, $width - $indent, $topDraw, $col); if($topDraw > 1 && $indent > 0){ imagesetpixel($image, $indent, $topDraw, $highlight1); imagesetpixel($image, $width - $indent, $topDraw, $shadow); } $col = ($bottomDraw == $height - 1) ? $shadow : $color; imageline($image, $indent, $bottomDraw, $width - $indent, $bottomDraw, $col); if($indent > 0){ imagesetpixel($image, $indent, $bottomDraw, $shadow); imagesetpixel($image, $width - $indent, $bottomDraw, $shadow); } $indent++; $bottomDraw++; $topDraw--; } } function drawColor($image, $width, $height){ //I wrote this myself without looking at Panther's code, so it may not be completely correct global $color, $highlight1, $highlight2, $shadow; imagefilledrectangle($image, 0, 0, $width, $height, $color); imageline($image, 0, 0, $width, 0, $highlight1); imageline($image, 1, 1, $width, 1, $highlight2); imageline($image, 0, 0, 0, $height, $highlight1); imageline($image, 1, 1, 1, $height, $highlight2); imageline($image, 0, $height, $width, $height, $shadow); imageline($image, $width, 1, $width, $height, $shadow); } function drawNumberArg($image, $x, $y, $width, $h){ global $white; $w = $width + x; $col = imagecolorallocate($image, 128, 128, 128); $topdraw = $bottomdraw = $hh = floor($h / 2); if($h % 2 == 0) $topdraw = $bottomdraw - 1; while($topdraw >= 0){ $indent = round(sqrt($hh - (($hh * $hh) - ($hh - $topdraw - 1) * ($hh - $topdraw - 1)))); imageline($image, $x + $indent, $topdraw, $indent + 1, $topdraw, $col); $drawcol = ($topdraw < 1) ? $col : $white; imageline($image, $x + $indent + 1, $topdraw, t3 - (t7 + 1), $topdraw, $drawcol); imageline($image, $x + $width - ($indent + 1), $topdraw, $width - $indent, $topdraw, $col); imageline($image, $x + $indent, $bottomdraw, $width - $indent, $bottomdraw, $white); if($indent == 0){ imageline($image, $x + $indent + 1, $topdraw, $indent + 2, $topdraw, $white); imageline($image, $x + $indent, $bottomdraw, $indent + 1, $bottomdraw, $col); imageline($image, $x + $width - ($indent + 1), $bottomdraw, $width - $indent, $bottomdraw, $col); } $bottomdraw++; $topdraw--; } }
Offline
Where is he anyway? I've not seen him in a while... I might email him and see if he feels like continuing on with it...
I see us having two choices, wait with the update till we have a proper renderer working or do an update by moving the images now while we wait for a proper renderer, then do the update again to use rendered blocks...
Offline
*gasp* Gosh, that code is long!!!
sparks wrote:
Where is he anyway? I've not seen him in a while... I might email him and see if he feels like continuing on with it...
I see us having two choices, wait with the update till we have a proper renderer working or do an update by moving the images now while we wait for a proper renderer, then do the update again to use rendered blocks...
I guess the questions we need to ask ourselves are:
1) If we wait, how long will it be?
2) How urgent is an update?
---therefore---
3) Is the wait worth it?
I think you should e-mail him. While we wait for a response from him and a response about the Scratchblocks source code, let's focus on the uploader (which will be necessary either way) and the SQL.
Last edited by Greenatic (2012-04-15 17:08:43)
Offline
Mmm... tricky... sigh, this all sounded so fine a while ago.
How about this: I email Thesucessor asking about it. While we wait for that and the source code for the main blocks to come through, I'll keep working on uploaders for the image-moving plan. Hopefully by the time it is done we will have naturally reached a decision based on what has happened in each thing...
EDIT: I see you have just edited saying exactly that, so lets do that
Last edited by sparks (2012-04-15 17:10:40)
Offline
Offline
sparks wrote:
EDIT: I see you have just edited saying exactly that, so lets do that
Sounds like a good plan.
Offline
sparks wrote:
Ah, thanks, Rookwood! I Emailed TheSuccessor (and nXIII for good measure).
Let the waiting games begin, and may the odds be ever in your favour.
Hunger Games reference? As someone on the forums said: Girl on Fire + Boy with Bread = Toast. And as I say: May the odds be ever in your flavor.
Offline
I saw that too, I thought it was hilarious, TOAST!
Ahem. Yeah, nXIII's actually looks pretty neat, all it needs for our uses is a colour input so that other categories can be achieved!
Offline
joefarebrother wrote:
LiquidMetal wrote:
I only know what other people have told me - I'm not so knowledgeable in servers and databases at the moment, but I'm sure that the php thing is not the direct way to access the database. After all, the php page doesn't call a php page to access the database! I'm not trying to bypass using a url - I want to skip the extra php part and go straight to the database. Get it?
A python or C# server thing exists, I'm sure, that accesses a database directly - why can't squeak do the same?well I'm not sure but i think PHP and ASP are the only programming languages that can directly access a database.
I sincerely doubt that. (What a poorly designed interface!)
Offline
sparks wrote:
I saw that too, I thought it was hilarious, TOAST!
Ahem. Yeah, nXIII's actually looks pretty neat, all it needs for our uses is a colour input so that other categories can be achieved!
How complicated would a font change for his script be? It doesn't look natural now.
Offline
sparks wrote:
I saw that too, I thought it was hilarious, TOAST!
Ahem. Yeah, nXIII's actually looks pretty neat, all it needs for our uses is a colour input so that other categories can be achieved!
I think it needs cap blocks too. Or would we just manually make pictures for those?
EDIT: And a way to make dropdowns, color input, Panther color blocks...
EDIT: Well, fixed color input. http://block.site90.net/[set%20pen%20color%20to%20[#FFFFFF]]
Last edited by Greenatic (2012-04-15 18:01:43)
Offline
sparks wrote:
nXIII has speedily replied saying he'd be happy to update his to fit our needs I'm going to bed now though
Great! I know you won't see this until tomorrow, but are you going to continue to correspond privately with him or is he going to come to this thread?
Offline
You just caught me. I don't think he has any plans to come here, he's not on much but he would if I asked him to. I think he's probably going to make the changes, send them to me and then go quiet again
If any important decision stuff comes up I'll be sure to direct him here though, or at least post what is being said
Offline
sparks wrote:
You just caught me. I don't think he has any plans to come here, he's not on much but he would if I asked him to. I think he's probably going to make the changes, send them to me and then go quiet again
If any important decision stuff comes up I'll be sure to direct him here though, or at least post what is being said
Alright. I wish him luck
Offline
pjtnt11 wrote:
Where do you put the code?
when gf clicked repeat until <(You know where to put the code?) = [true]> say [Where do you put the code?] end
Corrected grammar. Sorry, I couldn't resist.
Last edited by Splodgey (2012-04-17 10:27:59)
Offline
blockspec: ('open gallery number %s ' #- #Gallerylink:)
code:Gallerylink: t1 Cursor wait showWhile: [ScratchPlugin primOpenURL: 'http://scratch.mit.edu/galleries/view/' , t1 asString]
what is does: it makes you go to the gallery number you put in.
Last edited by pjtnt11 (2012-04-18 10:00:38)
Offline