This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#876 2010-11-24 04:28:33

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

Blocks (working on)

Sensing Blocks (excluding last two)
Operator Blocks

Credit Needed : No


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#877 2010-11-24 07:23:42

midnightleopard
Scratcher
Registered: 2007-09-13
Posts: 1000+

Re: Lets make a new Scratch viewer!

nice.


http://pwp.wizards.com/5103673563/Scorecards/Landscape.png

Offline

 

#878 2010-11-24 08:23:39

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Lets make a new Scratch viewer!

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  sad

Just something I whipped up...
Link for png: http://location/of/file?file=<insert … ge/png>

Code:

<?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)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#879 2010-11-24 10:45:50

midnightleopard
Scratcher
Registered: 2007-09-13
Posts: 1000+

Re: Lets make a new Scratch viewer!

hello what should i do?


http://pwp.wizards.com/5103673563/Scorecards/Landscape.png

Offline

 

#880 2010-11-24 11:05:11

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Lets make a new Scratch viewer!

midnightleopard wrote:

hello what should i do?

Me too.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#881 2010-11-24 11:13:32

tcb
Scratcher
Registered: 2008-03-25
Posts: 100+

Re: Lets make a new Scratch viewer!

Thanks MathWizz. But I was talking about "the puzzle" in your sig, aka, creating the file on the spot and displaying it


http://goo.gl/eCQLihttp://goo.gl/sK54shttp://goo.gl/jC0dehttp://goo.gl/yhGLQhttp://goo.gl/wqvsQ

Offline

 

#882 2010-11-24 11:31:04

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Lets make a new Scratch viewer!

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:

Code:

<?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);
?>

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#883 2010-11-24 12:33:29

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lets make a new Scratch viewer!

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.


You can now reach me on Twitter @johnnydean1_

Offline

 

#884 2010-11-24 16:15:16

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: Lets make a new Scratch viewer!

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.  big_smile

Last edited by Daffy22 (2010-11-24 16:17:03)


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#885 2010-11-24 17:49:34

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Lets make a new Scratch viewer!

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.  big_smile

Here:

Code:

function join(s1, s2)
{
return s1 + s2;
}

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#886 2010-11-24 20:36:07

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

And i have all the operators, just now i dont have the time to upload. I'll do it later.


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#887 2010-11-25 02:51:11

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: Lets make a new Scratch viewer!

Nice, thanks bbbed!  big_smile
I'll do as many reporter blocks as I can.  smile
I persume s1 and s2 are the input variables?

Last edited by Daffy22 (2010-11-25 02:51:39)


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#888 2010-11-25 06:55:51

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Lets make a new Scratch viewer!

Daffy22 wrote:

Nice, thanks bbbed!  big_smile
I'll do as many reporter blocks as I can.  smile
I persume s1 and s2 are the input variables?

Yeah, but you can call them anything


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#889 2010-11-25 11:31:12

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: Lets make a new Scratch viewer!

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  smile

Code:

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)


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#890 2010-11-25 11:57:03

tcb
Scratcher
Registered: 2008-03-25
Posts: 100+

Re: Lets make a new Scratch viewer!

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?


http://goo.gl/eCQLihttp://goo.gl/sK54shttp://goo.gl/jC0dehttp://goo.gl/yhGLQhttp://goo.gl/wqvsQ

Offline

 

#891 2010-11-25 13:33:10

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Lets make a new Scratch viewer!

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.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#892 2010-11-25 14:00:28

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

All the operators I know of:

Code:

 
//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)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#893 2010-11-25 14:03:39

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

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)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#894 2010-11-25 15:22:07

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lets make a new Scratch viewer!

MathWizz can help with the names. I am not making the execution engine so I dont know how hes planning to do it  smile


You can now reach me on Twitter @johnnydean1_

Offline

 

#895 2010-11-25 16:05:38

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Lets make a new Scratch viewer!

I'm making the execution engine, and I can modify it to fit what you want.


/* No comment */

Offline

 

#896 2010-11-25 16:08:52

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

Alright. So should we use obj1, num1, etc. or what should we use?


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#897 2010-11-25 16:10:40

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lets make a new Scratch viewer!

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.


You can now reach me on Twitter @johnnydean1_

Offline

 

#898 2010-11-26 00:59:03

tcb
Scratcher
Registered: 2008-03-25
Posts: 100+

Re: Lets make a new Scratch viewer!

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 sad  32 )y sad  35[/blocks]
would be

Code:

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 =.

Code:

//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)


http://goo.gl/eCQLihttp://goo.gl/sK54shttp://goo.gl/jC0dehttp://goo.gl/yhGLQhttp://goo.gl/wqvsQ

Offline

 

#899 2010-11-26 01:43:00

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

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.  big_smile


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#900 2010-11-26 01:44:10

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Lets make a new Scratch viewer!

Alright. I fixed it, I think.  big_smile


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

Board footer