02-29-2024, 11:07 AM
@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
@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
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