Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Scaling and Rotating
#6
@Marcus ... thank you for sharing your "Raster Scaling" code. I'm trying to use your code to make the earth looks bigger and bigger. It works !

@Kevin ... I am actually taking a look at the balls' movement in your "Pool Game", and it's far more advanced in trigonometry. I should learn a lot from you then.

@Johnno... One piece of coding a day, keeps my brain awake 

@Aliensoldier... I'll give you more maths in the code below  Big Grin


Code:
'====================================================
' THE EARTH AND THE SUN
' The earth is bigger and bigger
'
' Author's Note :
' -The Sun https://giphy.com/gifs/nasa-sun-nasagif-1oLeAsuP5UfPK1KR85
' -The Earth https://news.utk.edu/2023/01/25/the-conversation-how-has-the-inside-of-the-earth-stayed-as-hot-as-the-suns-surface-for-billions-of-years/
' -DrawImageScaled() was created by Marcus
'====================================================

'----------------
' INITIALIZATION
'----------------
set window "The Earth and The Sun",800,600
set redraw off
myfont  = createfont("Arial", 30, 1,1,0,0)

'color definition
black = [0,0,0]
white = [255,255,255]
visible white_alpha = [255,255,255,0]

'Sprite class definition
Sprite =[
    '--- Properties ---
    img:0, x:0, y:0, w:0, h:0, f:0,   
   
    '--- Methods ------   
    Draw:function(x,y,w,h)
            set color white_alpha; du = 1/w; u = 0
            for x = x to x + w - 1
                draw vraster this.img, x, y, y + h - 1, u, 0, u, 1; u = u + du
            next     
         endfunc
]

'Initial Value
earth       = copy(Sprite)
earth.img   = loadimage("img/earth1.png")

sun         = copy(Sprite)
sun.img     = loadimage("img/sun1.png",10,3)
sun.x       = (width(primary)-width(sun.img))/2
sun.y       = (height(primary)-height(sun.img))/2

'--------------
' MAIN PROGRAM
'--------------
for angle = 0 to 15*PI step 0.1
    'Clear screen
    set color black;cls; set color white
   
    'Just random Stars in the background
    for j = 1 to 20
        r = rnd(2) 
        draw ellipse rnd(width(primary)),rnd(height(primary)),r,r,1
    next

    'Animate the sun's sprite sheet
    i = i%30
    draw image sun.img,sun.x,sun.y,i
    i = i + 1

    'Moving earth, bigger and bigger
    earth.w =  width(earth.img)*(0.25+earth.f)
    earth.h =  height(earth.img)*(0.25+earth.f)
    earth.f =  earth.f + 0.008
    radius  =  5 + 2 * angle   
    earth.x =  radius * cos(angle) + (width(primary)-earth.w)/ 2
    earth.y =  radius * sin(angle) + (height(primary)-earth.h)/ 2
    earth.Draw(earth.x, earth.y, earth.w, earth.h)
   
    redraw
    fwait 20
next

'Ending text
set color white; set font myfont;
set caret width(primary)/2, height(primary)/2; center "To be Continued..."
temp=rln()'pause

'Clear memory
free image sun.img
free image earth.img


Attached Files
.zip   TheEarth.zip (Size: 995.8 KB / Downloads: 4)
Reply


Messages In This Thread
Simple Scaling and Rotating - by 1micha.elok - 02-28-2024, 11:57 AM
RE: Simple Scaling and Rotating - by kevin - 02-28-2024, 04:36 PM
RE: Simple Scaling and Rotating - by Marcus - 02-28-2024, 04:51 PM
RE: Simple Scaling and Rotating - by johnno56 - 02-28-2024, 06:08 PM
RE: Simple Scaling and Rotating - by aliensoldier - 02-28-2024, 09:58 PM
RE: Simple Scaling and Rotating - by 1micha.elok - 02-29-2024, 11:07 AM
RE: Simple Scaling and Rotating - by johnno56 - 03-01-2024, 04:33 AM
RE: Simple Scaling and Rotating - by 1micha.elok - 03-04-2024, 01:11 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)