tcb wrote:
Updated my script.
MathWizz: How do you make a PHP file return as a MIMETYPE jpg/image? I wish I could do that... Imagine the possibilities! Unfortunately, PHP is server side, couldn't look at your code![]()
Just something I whipped up...
Link for png: http://location/of/file?file=<insert … ge/png>
<?php
$data = "data:" . $_GET["type"] . ",";
foreach (str_split(file_get_contents($_GET["file"])) as $byte)
{
$hex = dechex(ord($byte));
if (strlen($hex) == 1)
{
$hex = "0" . $hex;
}
$data .= "%" . $hex;
}
echo $data;
//header("Location: " . $data); //redirecting doesn't work for Chome. :/
?>Last edited by MathWizz (2010-11-24 08:25:30)
Offline
tcb wrote:
Thanks MathWizz. But I was talking about "the puzzle" in your sig, aka, creating the file on the spot and displaying it
Oh... Here:
<?php
$project = $_GET["project"];
$user = $_GET["user"];
$width = $_GET["width"];
if ($width == "")
{
$width = 340;
}
$scratchpage = file_get_contents("http://scratch.mit.edu/projects/" . $user . "/" . $project . "/");
$start = stripos($scratchpage,'<title>');
$end = stripos($scratchpage,'</title>',$start);
$title = strip_tags(substr($scratchpage,$start + 28,$end - $start - 20));
//$scratchpage = strip_tags($scratchpage,"<div>");
$start = stripos($scratchpage,'<div id="pactivity">');
$end = stripos($scratchpage,'</div>',$start);
$pactivity = strip_tags(substr($scratchpage,$start,$end - $start));
$src = imagecreatefromgif("http://scratch.mit.edu/static/projects/" . $user . "/" . $project . "_sm.png");
$dest = imagecreate($width,150);
imagefill($dest,0,0,$forum);
imagecopy($dest,$src,0,0,0,0,133,100);
$black = imagecolorallocate($dest,0,0,0);
$forum = imagecolorallocate($dest,222,223,223);
imagefilledrectangle ($dest,133,0,$width,100,$forum);
imagefilledrectangle ($dest,0,100,$width,150,$forum);
$item = strtok(" ," . $pactivity,",");
imagestring($dest,5,5,105,$title,$black);
imagestring($dest,1,5,140,"I update! Click to view the project then come back to see!",$black);
for ($i = 0;$item != false;$i++)
{
imagestring($dest,4,143,18 * $i,trim($item = strtok(",")),$black);
}
header("Content-Type: image/png");
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>Offline
If people are looking for jobs and know JScript, work on the blocks. If you don't know JScript then think of new ideas that could be incoperated. You could also make a design for the viewer, or some sample project that could be used to test the viewer.
Offline
johnnydean1 wrote:
If people are looking for jobs and know JScript, work on the blocks. If you don't know JScript then think of new ideas that could be incoperated. You could also make a design for the viewer, or some sample project that could be used to test the viewer.
Can I see and example Jscript for a reporter block?
I'll do them.
Last edited by Daffy22 (2010-11-24 16:17:03)
Offline
Daffy22 wrote:
johnnydean1 wrote:
If people are looking for jobs and know JScript, work on the blocks. If you don't know JScript then think of new ideas that could be incoperated. You could also make a design for the viewer, or some sample project that could be used to test the viewer.
Can I see and example Jscript for a reporter block?
I'll do them.![]()
Here:
function join(s1, s2)
{
return s1 + s2;
}Offline
Daffy22 wrote:
Nice, thanks bbbed!
![]()
I'll do as many reporter blocks as I can.![]()
I persume s1 and s2 are the input variables?
Yeah, but you can call them anything
Offline
okay here's my code for the sqrt cos and sin block, length of block and the round block. Can I see the code for a stack block now please
function length(s1)
{
return s1.length;
}
function math(s1, s2)
{
if (s1 == 'sqrt')
{
return Math.sqrt(s2)
}
if (s1 == 'abs')
{
return Math.abs(s2)
}
if (s1 == 'sin')
{
return Math.sin(s2)
}
if (s1 == 'cos')
{
return Math.cos(s2)
}
if (s1 == 'asin')
{
return Math.asin(s2)
}
if (s1 == 'acos')
{
return Math.acos(s2)
}
if (s1 == 'atan')
{
return Math.atan(s2)
}
if (s1 == 'log')
{
return Math.log(s2)
}
if (s1 == 'e^')
{
return Math.e^(s2)
}
}
function round(s1)
{
return Math.round(s1);
}Last edited by Daffy22 (2010-11-25 11:31:42)
Offline
Hmm... we are going to have a problem here... our syntax is going to be all over the place, with lots of people coding. One of us is going to think the function should be called this while another thinks it should be called that. can we have a few rules?
Offline
tcb wrote:
Hmm... we are going to have a problem here... our syntax is going to be all over the place, with lots of people coding. One of us is going to think the function should be called this while another thinks it should be called that. can we have a few rules?
I was just thinking the same thing.
Offline
All the operators I know of:
//Simple Operators.
function AddNumbers(number1, number2) {
return number1 + number2
}
function SubtractNumbers(number1, number2) {
return number1 - number2
}
function MultiplyNumbers(number1, number2) {
return number1 * number2
}
function DivideNumbers(number1, number2) {
return number1 / number2
}
function and(obj1, obj2) {
if obj1 == true {
if obj2 == true {
return true }
else {
return false } }
else {
return false }
}
function or(obj1, obj2) {
if obj1 == true {
return true }
if obj2 == true {
return true }
else {
return false }
}
function not(obj1) {
if obj1 == true
return false
else
return true
}
function equals(obj1, obj2) {
if obj1 == obj2 {
return true}
else {
return false }
}
function lessThan(obj1, obj2) {
If obj1 < obj2 {
return true }
else {
return false }
}
function greaterThan (obj1, obj2) {
if obj1 > obj2 {
return true }
else {
return false }
}
function join(obj1 , obj2) {
return String(obj1) + String(Obj2)
}
function letter_ofString(num1, obj1) {
return obj1.charAt(num1)+1
}
function lengthOf(obj1) {
return length(obj1)
}
function _mod_(num1, num2) {
return num1 % num2
}
function round(num1) {
return Math.round(num1)
}
function _of_(op1, num1) {
If op1 == sqrt {
return Math.sqrt(num1) }
If op1 == abs {
return Math.abs(num1) }
If op1 == sin {
return Math.sin(num1) }
If op1 == cos {
return Math.cos(num1) }
If op1 == tan {
return Math.tan(num1) }
If op1 == asin {
return Math.asin(num1) }
If op1 == acos {
return Math.acos(num1) }
If op1 == atan {
return Math.atan(num1) }
If op1 == ln {
return Math.LN2(num1) }
If op1 == ^e {
return Math.E(num1) }
If op1 == ^10 {
for i = 1, i < 11 {
if i == 11 {
break;
}
num1 = num1*num1
i++ }
return num1
}It's a lot.
Last edited by bbbeb (2010-11-26 01:44:58)
Offline
Here is my idea: (Yes i will change mine as needed)
You place the name that isnt a operator like this:
round()
but for the slots, you use an underscore, like this:
round_()
And i personally use obj1, obj2 for all slots, num1, num2 for number slots, and it should be bol1 for boolean sockets.
Now to do as much sensing as i can....
Last edited by bbbeb (2010-11-25 14:04:44)
Offline
MathWizz can help with the names. I am not making the execution engine so I dont know how hes planning to do it
Offline
I'm making the execution engine, and I can modify it to fit what you want.
Offline
TheSuccessor wrote:
I'm making the execution engine, and I can modify it to fit what you want.
Ok Nice, I didn't know. You handle the question.
Offline
What I've done in my code (willing to change...) is put the script name as it appears in Sratch, only with _ for the places where there is a value.
so [blocks]<go to x
32 )y
35[/blocks]
would be
function gotox_y(element, value1, value2){
//code
}Where element is the object to apply the code to, value1 is x, value2 is y.
Oh, and personally, I prefer code to be documented, especially for group projects like this.
bbbeb: Your code is glitchy. Remember, in javascript, to test the value of a variable, you need to use ==. To set you use a single equals =.
//Used VERY often, so had to declare it at top.
function direction(element){
//Code here will probably work :P
direction = element.style.transform;
rotstarts = direction.split("(");
rotends = rotstarts[1].split("deg)");
direction = rotends[0];
return direction
}
//Move %value1 steps
function move_steps(element,value1){
//Find rotation of object:
direction = direction(element);
//Direction should now equal rotation.
//Lets move the object by value1.
//I'm not very good at trig btw.
element.style.left += (value1 * Math.sin(direction));
element.style.top += (value1 * Math.cos(direction));
//That should work: Tell me if it don't!
}
//Turn %value1 degrees clockwise: Insert negative number for anti-clockwise
function turn_degrees(element, value1){
//CODE WILL NOT WORK IE.
//IE only allows you to use 90, 180, 270, 360: Not Good!
//Find rotation:
direction = direction(element);
//Now, plus value1 onto that:
direction += value1;
//If its bigger than 360, minus 360 from it
//(prob not needed, but ohwell):
if(direction > 360){
direction -= 360;
}else if(direction < -360){ //Don't forget Negatives!
direction += 360;
}
//And concat that into a nice css property:
css_style = "rotate(" + direction + "deg)";
//And now assign it to the element
//This is the bit where IE gets left out: I might add a little extra for IE users
//which will just rotate by 90degrees.
element.style.transform = css_style;
element.style.-moz-transform = css_style;
element.style.-o-transform = css_style;
element.style.-webkit-transform = css_style;
}
//Point in direction %value1
function pointindirection(element, value1){
//IE hates this code. Could someone else please write code for IE?
//This code is basic, though. first lets get the css from value1:
css_style = "rotate(" + value1 + "deg)";
//Now lets simply just set the style to that:
element.style.transform = css_style;
element.style.-moz-transform = css_style;
element.style.-o-transform = css_style;
element.style.-webkit-transform = css_style;
}
//Hmm, a tricky one, point towards %value1: I'm bad at trig :(
function pointtowards(element, value1){
//value1 should be the ID of the element to point towards.
//so lets get the element itself:
value1 = document.getElementById(value1);
//Now, lets get the pos of that element
xpos = value1.style.left;
ypos = value1.style.top;
//Put it in a rotation() wrapper:
css_style = (Math.atan2(ypos-element.style.top, xpos-
element.style.top))*180/Math.PI
css_style = "rotation(" + css_style
css_style += "deg)"
//And assign it to the element:
element.style.transform = css_style;
element.style.-moz-transform = css_style;
element.style.-o-transform = css_style;
element.style.-webkit-transform = css_style;
}
//Few, Go To x:%value1 y:%value2: our first two-value block!
function gotox_y(element,value1,value2){
//Scratch x and y are different to CSS top and left
//So, convert them! Assuming the project size ISNT scaling,
xpos = value1 - 241;
ypos = value2 - round(387/2); //Couldn't bother working that one out!
//And now, right it to CSS top and left properties
element.style.top = ypos + "px";
element.style.left = xpos + "px";
}
//Go To %value1: Very easy, we can just call the function above!
function goto(element, value1){
//But first,we've got to get the pos of the element value1
//value1 is an id, not the object itself, so:
value1 = document.getElementById(value1);
//and the (scratch) x and y of those are:
xpos = value1.style.top + 241;
ypos = value1.style.left + round(387/2);
//Call gotox_y to move the element
gotox_y(element, xpos, ypos);
}
//glide %value1 secs to x %value2 y %value3: I hate coding smooth moving!
function glide_secstox_y(element,value1,value2,value3){
//decided to skip this one for productivity issues
}
//Nice and simple compared to the one above
//Change X by %value1
function changexby(element, value1){
element.style.left += value1;
//And thats it!
}
//All of the following are basic!
//Set X to %value1
function setxto(element, value1){
element.style.left = value1;
}
//Change Y By %value1
function changeyby(element, value1){
//Copy Paste :)
element.style.top += value1;
}
//Set Y to %value1
function setyto(element, value1){
element.style.left = value1;
}
//If on edge, bounce: Where is the edge? Will it be defined by a div?
function ifonedgebounce(element){
//Leaving because I don't know what the edge is!
}
//Some nice reporter blocks!
//direction already declared at top of script
function xposition(element){
return element.style.left;
}
function yposition(element){
return element.style.top;
}
//Motion Blocks are done (to an extent...)My current code above ^
(remember, you can also get it from scratch.fridgecow.com/blocks.js
Last edited by tcb (2010-11-26 05:42:18)
Offline
tcb wrote:
bbbeb: your code is glitchy. Remember, in javascript, to test the value of a variable, you need to use ==. To set you use a single equals =.
Gimme a sec. Ill fix it.
Offline