Giter VIP home page Giter VIP logo

Comments (4)

Wiladams avatar Wiladams commented on May 27, 2024

Also of note, at the top of the image there's a live framerate and mouse positioning tracker. I have the framerate set at 15, and it's reporting a rate of 12.29. That's due to inaccuracy of the framerate tracking, not an indication of how slow things are. The raw framerate can be much higher (blit to host at 120fps), and the drawing will consume some time per frame, but it's nowhere near saturation at this point.

Also, that spirograph thing isn't a static image, it's constantly updating animation, just like the framerate tracker.

The checkerbox pattern is the default background of my 'desktop'.
The 'windows' are the big translucent gray that has the getting started examples, and the smaller one to the right that houses the spirograph. Just testing the compositor. Windows can have any background they like, and can have any shape they like, just like with Win32, but all with Blend2d.

The setup for that screen looks like this in code:

local winman = require("WinMan")

local stopviews = require("STOP_views")
local spiroapp = require("STOP_spiroapp")
local framestatapp = require("STOP_framestat")

local function startup()
    spawn(framestatapp, {x=0, y=0, width=1920, height=20})
    spawn(stopviews,{x=100, y=100, width=1024, height=768})
    spawn(spiroapp,{x=800, y=300, width=640, height=480})
end

winman {width = 1920, height=1080, startup = startup}

And the spiroapp looks like

local SpiroGraphic = require("SpiroGraphic")

local function app(params)
    local win1 = WMCreateWindow(params.x,params.y, params.width, params.height)

    local spg = SpiroGraphic:new({width = params.width, height=params.height})

    win1:add(spg)
    win1:show()

    while true do
        win1:draw()
        yield();
    end
end

return app

And the spirographic itself looks like

local Graphic = require("Graphic")

local floor = math.floor
local random = math.random
local sin = math.sin;
local cos = math.cos

local SpiroGraphic = Graphic:new()

function SpiroGraphic.new(self, obj)
    obj = obj or {}
    
    obj.N = 36;
    obj.theta = 3.14159 * 2 / obj.N;
    obj.centerX = obj.centerX or obj.width/2;
    obj.centerY = obj.centerY or obj.height/2;

    setmetatable(obj, self)
    self.__index = self;
    
    return obj;
end


function SpiroGraphic:draw(ctxt)
    ctxt:stroke(255, 0,0)
    ctxt:setStrokeWidth(1)
    local x = 0;
    local y = 0;


	local Radius = (self.height / 2) - 5;

    for p = 0, self.N-1 do
		local num = floor((p / self.N) * 254.0);
        local r = random(0, num);
		local g = random(0, num);
		local b = random(0, num);
        ctxt:stroke(r, g, b)

		for q = 0, p-1 do
		    ctxt:line(floor(self.centerX + Radius * sin(p * self.theta)), floor(self.centerY + Radius * cos(p * self.theta)),
		     floor(self.centerX + Radius * sin(q * self.theta)), floor(self.centerY + Radius * cos(q * self.theta)));
        end
    end
end

return SpiroGraphic

The environment these things live in already contains a little user mode scheduler "scheduler.lua" if you look at the source code. That gives things like 'spawn', 'periodic', 'on', 'whenever', etc. That makes it real easy to stitch together task like things. Interweave with graphics, and there you have it.

from blend2d.

Wiladams avatar Wiladams commented on May 27, 2024

And, I guess it would be nice if the rest of the examples on the home page were available in code. I can roughly figure out how to replicate them, but it would be nice to have access to the officials used.

from blend2d.

kobalicek avatar kobalicek commented on May 27, 2024

Nice thank you for sharing :)

from blend2d.

Wiladams avatar Wiladams commented on May 27, 2024

Closed as commentary

from blend2d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.