Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 The 20line or less weekly contest!
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2, 3, 4, 5, 6  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
The_Bean




PostPosted: Thu Mar 05, 2009 6:47 pm   Post subject: Re: The 20line or less weekly contest!

Did someone say 3D?
Turing:

View.Set ("graphics:500,500,offscreenonly")
var xm, ym, bm : int
loop
    Mouse.Where (xm, ym, bm)
    cls
    for x : -18 .. 18
        for y : -18 .. 18
            Draw.FillOval(round(200*cosd(x*10)*sind(y*10)*cosd(xm)+200*cosd(y*10)*sind(xm))+maxx div 2,round(200*sind(x*10)*sind(y*10)*cosd(ym)+(200*cosd(y*10)*cosd(xm)-200*cosd(x*10)*sind(y*10)*sind(xm))*sind(ym))+maxy div 2,1,1,7)
        end for
    end for
    View.Update
end loop

A sphere rotating with your mouse in 12 lines.
The formula can be changed to incorporate any 3D formula, although they may not turn out that great being as it is just dots.
Sponsor
Sponsor
Sponsor
sponsor
copthesaint




PostPosted: Thu Mar 05, 2009 8:59 pm   Post subject: Re: The 20line or less weekly contest!

Wow cool effect. I was very interested in you sphere. But I didn't know for sure how you did it at first. This may help others understand too what it does is basicly makes 18 dots 18 times and gives the illusion of 3D Gj Bean and don't give me credit for this. I am just posting this code for those who don't understand it. (Like me)

Turing:

View.Set ("graphics:max,max,offscreenonly")
var xm, ym, bm : int
var X : array 1 .. 4 of int
var Y : array 1 .. 4 of int
loop
    Mouse.Where (xm, ym, bm)
    cls
    for x : -18 .. 18
        for y : -18 .. 18
        /*
            for i : 1 .. 2
                X (i) := round (200 * cosd ((x+i-3) * 10) * sind ((y+i-3) * 10) * cosd (xm) + 200 * cosd ((y+i-3) * 10) * sind (xm)) + maxx div 2
                Y (i) := round (200 * sind ((x+i-3) * 10) * sind ((y+i-3) * 10) * cosd (ym) + (200 * cosd ((y+i-3) * 10) * cosd (xm) - 200 * cosd ((x+i-3) * 10) * sind ((y+i-3) * 10) * sind (xm)) * sind (ym)) + maxy div 2
            end for
            for i : 3 .. 4
                X (i) := round (200 * cosd ((x+i+1) * 10) * sind ((y+i+1) * 10) * cosd (xm) + 200 * cosd ((y+i+1) * 10) * sind (xm)) + maxx div 2
                Y (i) := round (200 * sind ((x+i+1) * 10) * sind ((y+i+1) * 10) * cosd (ym) + (200 * cosd ((y+i+1) * 10) * cosd (xm) - 200 * cosd ((x+i+1) * 10) * sind ((y+i+1) * 10) * sind (xm)) * sind (ym)) + maxy div 2
            end for
            */

            Draw.Polygon (X, Y, 4, grey)
            Draw.FillOval (round (200 * cosd (x * 10) * sind (y * 10) * cosd (xm) + 200 * cosd (y * 10) * sind (xm)) + maxx div 2, round (200 * sind (x * 10) * sind (y * 10) * cosd (ym) + (200 *
                cosd (y * 10) * cosd (xm) - 200 * cosd (x * 10) * sind (y * 10) * sind (xm)) * sind (ym)) + maxy div 2, 1, 1, 7)
            Draw.Line (round (200 * cosd (x * 10) * sind (y * 10) * cosd (xm) + 200 * cosd (y * 10) * sind (xm)) + maxx div 2, round (200 * sind (x * 10) * sind (y * 10) * cosd (ym) + (200 *
                cosd (y * 10) * cosd (xm) - 200 * cosd (x * 10) * sind (y * 10) * sind (xm)) * sind (ym)) + maxy div 2,round (200 * cosd ((x+1) * 10) * sind ((y+1) * 10) * cosd (xm) + 200 * cosd ((y+1) * 10) * sind (xm)) + maxx div 2, round (200 * sind ((x+1) * 10) * sind ((y+1) * 10) * cosd (ym) + (200 *
                cosd ((y+1) * 10) * cosd (xm) - 200 * cosd ((x+1) * 10) * sind ((y+1) * 10) * sind (xm)) * sind (ym)) + maxy div 2, black)             
        end for
    end for
    View.Update
end loop
saltpro15




PostPosted: Thu Mar 05, 2009 9:25 pm   Post subject: RE:The 20line or less weekly contest!

The_Bean, that is so cool! and it's not that difficult to understand
The_Bean




PostPosted: Thu Mar 05, 2009 9:44 pm   Post subject: Re: The 20line or less weekly contest!

Heres what is going in those giant lines of Drawing:
The 2 for loops going -18..18 are the degrees, I multiply them by 10 to get -180..180 by 10 which is a complete 360.
Take the equation of a sphere:
code:

 xCoordinate = cosd (x) * sind (y) * radius
 yCoordinate = sind (x) * sind (y) * radius
 zCoordinate = cosd (y) * radius

Now look at the rotation formula:
code:

    p1 = p1 * cosd (theta) + p2 * sind (theta)
    p2 = p2 * cosd (theta) - p1 * sind (theta)

Where p1 and p2 are either x,y,z depending on how you want it rotated and theta controls the degrees of rotation.
To make it spin horizontally: p1=xCoordinate and p2=zCoordinate and theta=xm
To make it spin vertically: p1=yCoordinate and p2=zCoordinate and theta=ym
Now replace variables where you can, and remember you need to keep the z value change in horizontal spinning in the verticle spinning:
code:

xNewCoordinate= xCoordinate * cosd (xm) + zCoordinate * sind (xm)
zNewCoordinate= zCoordinate * cosd (xm) - xCoordinate * sind (xm)
yNewCoordinate= yCoordinate * cosd (ym) + zNewCoordinate * sind (ym)

%do some more substitution, and radius=200
xNewCoordinate = cosd (x) * sind (y) * 200 * cosd (xm) + cosd (y) * 200 * sind (xm)
zNewCoordinate = cosd (y) * 200 * cosd (xm) - cosd (x) * sind (y) * 200 * sind (xm)
yNewCoordinate = sind (x) * sind (y) * 200 * cosd (ym) + (cosd (y) * 200 * cosd (xm) - cosd (x) * sind (y) * 200 * sind (xm)* sind (ym))

Draw.Dot(round(xNewCoordinate )+maxx div 2,round(yNewCoordinate)+maxy div 2,7)

You can change the formula of a sphere to get different looking shapes.
Tony




PostPosted: Thu Mar 05, 2009 10:59 pm   Post subject: Re: The 20line or less weekly contest!

The_Bean @ Thu Mar 05, 2009 9:44 pm wrote:
The 2 for loops going -18..18 are the degrees, I multiply them by 10 to get -180..180 by 10 which is a complete 360.

Turing actually supports
Turing:

for i: -180 .. 180 by 10

type of syntax. for
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
copthesaint




PostPosted: Fri Mar 06, 2009 2:52 am   Post subject: RE:The 20line or less weekly contest!

tony the 180 by 10 what is it used for/ how would you use it?
zylum




PostPosted: Fri Mar 06, 2009 3:30 am   Post subject: RE:The 20line or less weekly contest!

copthesaint, the code Tony posted iterates from -180 to 180 by increments of 10.. So instead of writing:

code:
for x : -18 .. 18

...

sin(x * 10)


you would simply have

code:
for x : -180 .. 180 by 10

...

sin(x)



All of these 3D submissions remind me of one I made in a previous 20 line contest...

Turing:
setscreen ("offscreenonly,graphics:400;400,nobuttonbar,title:zylum3Dv3")
var x, y : array 1 .. 4 of int
var c : array 1 .. 78 of real := init (-1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, - 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0)
for a : 0 .. maxint
    for i : 0 .. 60 by 12
        for j : 0 .. 9 by 3
            c (74 + j div 3) := ((cosd (a / 9) * sind (a / 8) * cosd (a / 7) + sind (a / 9) * sind (a / 7)) * c (i + j + 1) - c (i + j + 2) * sind (a / 9) * cosd (a / 7) + c (i + j + 3) * cosd (a / 9) * cosd (a / 8) + c (i + j + 2) * cosd (a / 9) * sind (a / 8) * sind (a / 7))
            x (j div 3 + 1) := round ((cosd (a / 8) * cosd (a / 7) * c (i + j + 1) + c (i + j + 2) * sind (a / 7) * cosd (a / 8) - c (i + j + 3) * sind (a / 8)) * 100 / (c (74 + j div 3) + 3) + maxx div 2)
            y (j div 3 + 1) := round (((sind (a / 9) * sind (a / 8) * cosd (a / 7) - cosd (a / 9) * sind (a / 7)) * c (i + j + 1) + c (i + j + 2) * cosd (a / 9) * cosd (a / 7) + c (i + j + 3) * sind (a / 9) * cosd (a / 8) + c (i + j + 2) * sind (a / 9) * sind (a / 8) * sind (a / 7)) * 100 / (c (74 + j div 3) + 3) + maxy div 2)
        end for
        c (78) := ((x (4) - x (3)) * (y (2) - y (3)) - (y (4) - y (3)) * (x (2) - x (3))) / (2 * 10186) + 1e-3
        drawfillpolygon (x, y, (c (78) + abs(c (78))) div c (78) * 2, RGB.AddColor (c (78) + 0.25, c (78) + 0.25, c (78) + 0.25))
    end for
    View.Update
    drawfillbox(0, 0, maxx, maxy, 43)
end for


Perspective, lighting and back face culling XD
Tallguy




PostPosted: Fri Mar 06, 2009 9:23 am   Post subject: RE:The 20line or less weekly contest!

i gotta say, @The_Bean - so sweet!! i love the sphere, how long did it take you to make?
Sponsor
Sponsor
Sponsor
sponsor
MihaiG




PostPosted: Fri Mar 06, 2009 3:02 pm   Post subject: Re: The 20line or less weekly contest!

i hearby disband zylum from posting any more submissions Razz so other people can win Smile <3

very nice zylum, want to add some commenting to your submission?
copthesaint




PostPosted: Mon Mar 23, 2009 10:56 pm   Post subject: Re: The 20line or less weekly contest!

Here is a 18 line program that is easy and cool. I took 5 min to make it.

Turing:
var Num : int := 0
var BinaryTable, BinaryNumbers : array 1 .. 8 of int := init (1, 2, 4, 8, 16, 32, 64, 128)
loop
    for i : 1 .. 8
        BinaryNumbers (i) := 0
    end for
    put skip, "Enter a number less then 256 to get it's 8-bit binary form." ..
    get Num
    for decreasing i : 8 .. 1
        if Num - BinaryTable (i) >= 0 then
            BinaryNumbers (i) += 1
            Num := Num - BinaryTable (i)
        end if
    end for
    for i : 1 .. 8
        put BinaryNumbers (i), " " ..
    end for
end loop
zero-impact




PostPosted: Sat Mar 28, 2009 1:29 pm   Post subject: Re: The 20line or less weekly contest!

Here is a particularly nice looking zoom of the mandelbrot set. In 18 lines! Very Happy

Turing:

setscreen ("graphics:200;200;nobuttonbar;")
var a1, b1, b2 : real
var lp : nat
for x : -100 .. 100
    for y : -100 .. 100
        a1 := (0.143 + x * 0.00001)
        b1 := 0.652 + y * 0.00001
        lp := 0
        loop
            lp += 1
            b2 := 2 * a1 * b1 + 0.652 + y * 0.00001
            a1 := a1 * a1 - b1 * b1 + 0.143 + x * 0.00001
            b1 := b2
            exit when lp > 254 or ((a1 * a1) + (b1 * b1)) > 4
        end loop
        drawdot (x + 100, y + 100, lp)
    end for
end for
copthesaint




PostPosted: Wed Apr 01, 2009 12:15 pm   Post subject: Re: The 20line or less weekly contest!

Here is a 19 line program that will take a string and split up the values inbetween each space.
This is usefull for online programs and loading txt files.

Turing:
var First, Last, NextValue : int
var Words : array 1 .. 10000 of string
procedure GetStrings (S : string)
    First := 1
    NextValue := 0
    for i : 1 .. length (S)
        if S (i) = " " then
            Last := i - 1
            NextValue += 1
            Words (NextValue) := ""
            for s : First .. Last
                Words (NextValue) += S (s)
            end for
            First := i + 1
        end if
    end for
end GetStrings
GetStrings ("Enter any string and the program will split it and give the number of words")
saltpro15




PostPosted: Wed Apr 01, 2009 3:44 pm   Post subject: RE:The 20line or less weekly contest!

here is hello world

Turing:

put "Hello World!"


in 1 line! how amazing!
SNIPERDUDE




PostPosted: Wed Apr 01, 2009 3:57 pm   Post subject: RE:The 20line or less weekly contest!

I vote saltpro15 the weekly winner. Razz
saltpro15




PostPosted: Wed Apr 01, 2009 4:43 pm   Post subject: RE:The 20line or less weekly contest!

yay, thanks SNIPERDUDE :p also, excellent video in your signature, I don't even like hip-hop and I thought it was great
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 6  [ 84 Posts ]
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Jump to:   


Style:  
Search: